Skip to content

About

Official Python SDK for integrating applications with Momobase.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Momobase Python SDK

PyPI License

Python client for the Momobase payment and administration APIs.

Install

pip install momobase

Requires Python 3.11+.

Usage

Creating a new client instance

There are two clients. MomobaseClient authenticates an application with the OAuth client_credentials grant and calls the public payment API. MomobaseAdminClient authenticates an operator with the OAuth password grant and covers the administration API.

from momobase import MomobaseClient, MomobaseAdminClient

mb = MomobaseClient(
    base_url,
    client_id=client_id,
    client_secret=client_secret,
    token_skew_seconds=30,
)

admin = MomobaseAdminClient(
    base_url,
    email=email,
    password=password,
    access_token=None,
    refresh_token=None,
    token_skew_seconds=30,
    on_token_change=None,
)

Both clients authenticate lazily on the first request, cache the token, and refresh it once when it expires or the API answers 401. token_skew_seconds is how early a token is treated as expired. on_token_change receives a TokenSnapshot (or None) on every token change so an admin session can be persisted and restored.

Clients are thread-safe. Create one per process and close it with close() or a with block. Requests time out after 30 seconds; pass http_client=httpx.Client(...) to change timeouts, proxies, or TLS settings.

Instance methods

Method Description
mb.authenticate() Authenticates with the configured credentials and stores the token.
mb.refresh() Refreshes the session, falling back to a fresh authentication.
mb.get_token() Returns the current TokenSnapshot, or None.
mb.clear_token() Clears the active session token.
mb.close() Closes the underlying HTTP client.
admin.set_credentials(email, password) Replaces the credentials and clears the current session.
admin.set_access_token(access_token, refresh_token=None, expires_in_seconds=None) Restores tokens obtained outside this client.
admin.logout() Ends the current administrator session and clears the token.

Request options

Payment calls accept idempotency_key=; list calls accept page= and per_page=. All are keyword-only.

Admin lists also filter, search and sort on the server. q= searches case-insensitively, sort= and order= order the list, and created_after= and created_before= bound the creation time (the first inclusive, the second not). Each list's own filters are exact matches, and a list of values matches any of them. The server rejects a filter the list does not support with a 400.

admin.transactions.list(
    status=["failed", "expired"],
    app_id="app_123",
    q="256700",
    sort="amount",
    order="desc",
    created_after=datetime(2026, 1, 1, tzinfo=UTC),
    per_page=50,
)

Services

Each call returns the unwrapped API data as plain dicts, typed with the TypedDicts in momobase.types. πŸ”“ marks the application client, πŸ” the administrator client.

PaymentMethodService

# Lists the payment methods currently available for routing.
πŸ”“ mb.payment_methods.list(service_type=None, country=None)

CollectionService

# Creates a collection (money in).
πŸ”“ mb.collections.create(payload, idempotency_key=None)

DisbursementService

# Creates a disbursement (money out).
πŸ”“ mb.disbursements.create(payload, idempotency_key=None)

TransactionService

# Returns a single transaction by its id.
πŸ”“ mb.transactions.get(transaction_id)

# Returns a single transaction by the reference the application supplied.
πŸ”“ mb.transactions.get_by_reference(reference)

# Returns a paginated, filterable transactions list across all applications.
πŸ” admin.transactions.list(page=None, per_page=None, q=None, sort=None, order=None,
    created_after=None, created_before=None, status=None, service_type=None, payment_method=None,
    country=None, currency=None, app_id=None, selected_provider_account_id=None)

# Returns any application's transaction by its id.
πŸ” admin.transactions.get(transaction_id)

# Returns a paginated, filterable audit logs list.
πŸ” admin.transactions.audit_logs(page=None, per_page=None, q=None, sort=None,
    order=None, created_after=None, created_before=None, action=None, actor_type=None, actor_id=None,
    entity_type=None, entity_id=None)

SystemService

# Returns runtime metadata (version, uptime, build).
πŸ” admin.system.info()

# Returns runtime health.
πŸ” admin.system.health()

# Returns a paginated list of the configured background workers.
πŸ” admin.system.workers(page=None, per_page=None)

# Returns a paginated list of the initialized provider runtimes.
πŸ” admin.system.runtime_providers(page=None, per_page=None)

AuthzService

# Lists assignable permissions, optionally for one audience ("admin" | "app").
πŸ” admin.authz.permissions(audience=None)

# Lists roles.
πŸ” admin.authz.roles()

# Creates a role.
πŸ” admin.authz.create_role(payload)

# Replaces a role.
πŸ” admin.authz.update_role(name, payload)

# Deletes a custom role.
πŸ” admin.authz.delete_role(name)

UserService

# Returns the signed-in administrator.
πŸ” admin.users.me()

# Returns a paginated administrators list.
πŸ” admin.users.list(page=None, per_page=None, q=None, sort=None, order=None,
    created_after=None, created_before=None, role=None, status=None)

# Creates an administrator.
πŸ” admin.users.create({"name": ..., "email": ..., "password": ..., "role": ...})

# Changes an administrator password.
πŸ” admin.users.change_password(user_id, password)

# Changes an administrator status ("active" | "inactive").
πŸ” admin.users.change_status(user_id, status)

# Reassigns an administrator to another role.
πŸ” admin.users.change_role(user_id, role)

AppService

# Returns a paginated applications list.
πŸ” admin.apps.list(page=None, per_page=None, q=None, sort=None, order=None,
    created_after=None, created_before=None, status=None, environment=None, currency=None)

# Creates an application.
πŸ” admin.apps.create({"name": ..., "description": ..., "environment": ..., "currency": ..., "charges": ...})

# Returns a single application by its id.
πŸ” admin.apps.get(app_id)

# Updates an application.
πŸ” admin.apps.update(app_id, payload)

# Changes an application status ("active" | "disabled" | "suspended").
πŸ” admin.apps.change_status(app_id, status)

# Returns a paginated list of an application's credentials.
πŸ” admin.apps.credentials(app_id, page=None, per_page=None, q=None, sort=None,
    order=None, created_after=None, created_before=None, status=None)

# Creates an application credential. The secret is returned only once.
πŸ” admin.apps.create_credential(app_id, {"name": ..., "scopes": ..., "expires_at": ...})

# Revokes an application credential.
πŸ” admin.apps.revoke_credential(app_id, credential_id)

# Rotates an application credential and returns the new secret.
πŸ” admin.apps.rotate_credential(app_id, credential_id)

ProviderService

# Returns a paginated provider accounts list.
πŸ” admin.providers.list(page=None, per_page=None, q=None, sort=None, order=None,
    created_after=None, created_before=None, provider_code=None, environment=None, currency=None,
    active=None)

# Returns a single provider account by its id.
πŸ” admin.providers.get(account_id)

# Lists the provider codes compiled into the server.
πŸ” admin.providers.registry()

# Creates a provider account.
πŸ” admin.providers.create_account({
    "provider_code": ..., "name": ..., "environment": ..., "country": ...,
    "currency": ..., "charges": ..., "config": ...,
})

# Updates provider location, currency, and charges.
πŸ” admin.providers.update_settings(account_id, {"country": ..., "currency": ..., "charges": ...})

# Replaces provider configuration.
πŸ” admin.providers.update_config(account_id, config)

# Activates a provider account.
πŸ” admin.providers.activate(account_id)

# Deactivates a provider account.
πŸ” admin.providers.deactivate(account_id)

# Tests a provider account connection.
πŸ” admin.providers.test(account_id)

# Returns one provider balance, optionally for a single country.
πŸ” admin.providers.balance(account_id, country=None)

# Returns a paginated list of the active provider balances.
πŸ” admin.providers.active_balances(page=None, per_page=None)

# Returns a paginated list of provider health snapshots.
πŸ” admin.providers.health(page=None, per_page=None, q=None, sort=None, order=None,
    created_after=None, created_before=None, status=None, circuit_state=None, provider_account_id=None)

RouteService

# Returns a paginated payment routes list.
πŸ” admin.routes.list(page=None, per_page=None, q=None, sort=None, order=None,
    created_after=None, created_before=None, service_type=None, payment_method=None,
    provider_account_id=None, active=None)

# Creates a payment route.
πŸ” admin.routes.create(payload)

# Updates route priority and status.
πŸ” admin.routes.update(route_id, {"priority": ..., "active": ...})

AnalyticsService

# Returns bucketed transaction analytics.
πŸ” admin.analytics.transactions(from_=None, to=None, interval=None, app_id=None, provider_account_id=None)

Errors

Every non-successful response raises a MomobaseAPIError carrying the HTTP status, the stable Momobase code, and the parsed body. Payment calls raise ValueError before sending when a required field is missing.

from momobase import MomobaseAPIError

try:
    mb.collections.create(payload, idempotency_key=order_id)
except MomobaseAPIError as err:
    print(err.status, err.code)

Permissions

AdminPermissions and AppScopes are enums of the known permission codes, for autocomplete and UI gates. permitted tests a granted list against a required code, honouring the PERMISSION_WILDCARD.

from momobase import AdminPermissions, permitted

permitted(admin.users.me().get("permissions"), AdminPermissions.APPS_CREATE)

Development

uv sync

uv run ruff format   # format
uv run ruff check    # lint
uv run pytest        # test
uv build             # sdist + wheel -> dist

Documentation

See the Momobase SDK documentation for authentication, payment flows, administration, and the complete API.

License

MIT

About

Official Python SDK for integrating applications with Momobase.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages