Skip to main content

Py MoMo SDK

PyPI version Python versions Build status License

Py MoMo SDK (py-momo-sdk 1.2.0) is a strictly typed Python client library for the MTN Mobile Money (MoMo) Open API and Airtel Money API. It provides synchronous and asynchronous clients with matching interfaces, automatic token caching, strict validation, and complete product coverage.

Developed for high reliability and clean developer experience, Py MoMo SDK adheres to the strict security standards of modern payment systems.

Features

  • Sync and async parity: PyMomoSDK and AsyncPyMomoSDK backed by httpx.Client and httpx.AsyncClient with matching interfaces.
  • Pydantic v2 models: Fully typed request and response validation and serialization.
  • Automated token caching: Thread-safe and async-safe in-memory token management with automatic cache invalidation and retry-once logic.
  • Comprehensive API coverage: Full MTN MoMo Collection (including CIBA and OAuth2 token exchange), Disbursement, Remittance, Sandbox, synchronous and asynchronous Airtel Money (AirtelClient and AsyncAirtelClient), Wave, M-Pesa (Daraja), Paystack, Flutterwave, and Orange Money adapters behind PaymentRouter.
  • Resilience and observability: Configurable idempotent retries with Retry-After and jitter, settlement polling helpers, TelemetryHook observability events, MSISDN carrier auto-routing, FastAPI and Django webhook verifiers, and a local py-momo-sdk mock simulator.
  • CLI utility: Ships with the py-momo-sdk Typer-powered CLI to bootstrap sandbox credentials, initiate payments, and query balances or transaction status.

Installation

Install py-momo-sdk (1.2.0) from PyPI using pip:

pip install py-momo-sdk

For development dependencies, install with:

pip install -e ".[dev]"

Quickstart

Sandbox provisioning

Bootstrap a new sandbox API user and API key:

from py_momo_sdk import PyMomoSDK, PyMomoSDKConfig

config = PyMomoSDKConfig(environment="sandbox")

with PyMomoSDK(config) as client:
    provisioner = client.create_sandbox_provisioner("your-sandbox-subscription-key")
    credentials = provisioner.provision(callback_host="https://example.com")

    print(f"API user: {credentials['api_user']}")
    print(f"API key: {credentials['api_key']}")

Collection (synchronous example)

Request a payment from a subscriber using the synchronous client:

from py_momo_sdk import ProductConfig, PyMomoSDK, PyMomoSDKConfig

config = PyMomoSDKConfig(
    environment="sandbox",
    collection=ProductConfig(
        subscription_key="your-collection-subscription-key",
        api_user="550e8400-e29b-41d4-a716-446655440000",
        api_key="your-api-key",
        callback_url="https://example.com/webhook",
    ),
)

with PyMomoSDK(config) as client:
    # Query account balance
    balance = client.collection.get_balance()
    print(f"Available balance: {balance.available_balance} {balance.currency}")

    # Initiate a request to pay
    reference_id = client.collection.request_to_pay(
        amount="1000.00",
        currency="UGX",
        payer_msisdn="256771234567",
        external_id="ext-tx-12345",
        payer_message="Payment for invoice 123",
        payee_note="Thank you for shopping with us",
    )
    print(f"Transaction reference: {reference_id}")

    # Check status
    tx = client.collection.get_payment_status(reference_id)
    print(f"Transaction status: {tx.status}")

Disbursement (asynchronous example)

Send funds using the asynchronous client:

import asyncio
from py_momo_sdk import AsyncPyMomoSDK, ProductConfig, PyMomoSDKConfig

config = PyMomoSDKConfig(
    environment="sandbox",
    disbursement=ProductConfig(
        subscription_key="your-disbursement-subscription-key",
        api_user="550e8400-e29b-41d4-a716-446655440000",
        api_key="your-api-key",
    ),
)

async def main() -> None:
    async with AsyncPyMomoSDK(config) as client:
        # Check active status of a mobile money user
        is_active = await client.disbursement.is_account_holder_active("256771234567")
        print(f"Account holder active: {is_active}")

        # Initiate a transfer
        reference_id = await client.disbursement.transfer(
            amount="5000.00",
            currency="UGX",
            payee_msisdn="256771234567",
            external_id="disb-tx-9999",
            payer_message="Staff salary payment",
            payee_note="Disbursement successful",
        )

        # Query transaction details
        status = await client.disbursement.get_transfer_status(reference_id)
        print(f"Transfer status: {status.status} (ID: {status.financial_transaction_id})")

asyncio.run(main())

CLI usage

Py MoMo SDK bundles the py-momo-sdk CLI tool for sandbox management, balance checks, and payment queries. Export credentials as PY_MOMO_SDK_* environment variables so secrets are not recorded in shell history or process listings:

export PY_MOMO_SDK_ENVIRONMENT="sandbox"
export PY_MOMO_SDK_COLLECTION_SUBSCRIPTION_KEY="your-key"
export PY_MOMO_SDK_COLLECTION_API_USER="550e8400-e29b-41d4-a716-446655440000"
export PY_MOMO_SDK_COLLECTION_API_KEY="your-api-key"

# Show installed version
py-momo-sdk --version

# Provision a sandbox environment
py-momo-sdk sandbox provision --callback-host "https://example.com"

# Query the collection balance
py-momo-sdk collection balance

# Check the status of a request to pay transaction
py-momo-sdk collection status "550e8400-e29b-41d4-a716-446655440000"

Use py-momo-sdk --help to list all available commands and flags.

Testing

Run checks, security analysis, and coverage reports:

# Style and format checks
ruff check .
black --check .
isort --check .

# Static type check
mypy py_momo_sdk/

# Security analysis
bandit -r py_momo_sdk/

# Test execution with coverage
pytest --cov=py_momo_sdk --cov-report=term-missing

License

MIT License. Copyright (c) 2026 Wesley Kambale. See LICENSE for more details.

Metadata

Release files for py-momo-sdk 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-momo-sdk 1.2.0
File Size Uploaded Provenance Actions
py_momo_sdk-1.2.0.tar.gz 112.8 kB With provenance Details for py_momo_sdk-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-momo-sdk 1.2.0
File Interpreter ABI Platform Actions
py_momo_sdk-1.2.0-py3-none-any.whl Python 3 none any Details for py_momo_sdk-1.2.0-py3-none-any.whl

Total release size: 213.1 kB

Release files / py_momo_sdk-1.2.0.tar.gz

Download URL py_momo_sdk-1.2.0.tar.gz
Size 112.8 kB
Tags Source
SHA-256 checksum
How to use checksums
72954950aa4015282439fc1783add6b94b4f8f5c607f26e966cb33c7fa8741c0
BLAKE2b-256 checksum
How to use checksums
c601cf6cd3a569d0d8a4e22c9c6b2bec77f38dd5686c875ce618d7e0f4aec47b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / py_momo_sdk-1.2.0-py3-none-any.whl

Download URL py_momo_sdk-1.2.0-py3-none-any.whl
Size 100.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01ce166ed5ef07ab285afd8a447f61b6d0065831717df08343cf26939e16e0a9
BLAKE2b-256 checksum
How to use checksums
32b6828a8124a8a547d8b9c3658255d8b830bb99b1de6e2226df50b08a093f7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for py-momo-sdk 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for py_momo_sdk-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page