Skip to main content

Py MoMo SDK

Strictly typed Python SDK for MTN Mobile Money, Airtel Money, Wave, Safaricom M-Pesa, Paystack, Flutterwave, and Orange Money

PyPI version Python versions Build status License

Py MoMo SDK (py-momo-sdk 1.3.1) is a strictly typed Python client library for MTN Mobile Money (MoMo), Airtel Money, Wave, Safaricom M-Pesa (Daraja), Paystack, Flutterwave, and Orange Money behind a unified PaymentRouter. It provides synchronous and asynchronous clients with matching interfaces, automatic token caching, strict input validation, and verified webhook security.

Features

  • Sync and async parity: PyMomoSDK, AsyncPyMomoSDK, AirtelClient, AsyncAirtelClient, PaymentRouter, AsyncPaymentRouter, and all provider clients backed by httpx.Client and httpx.AsyncClient.
  • Pydantic v2 models: Fully typed request and response validation and serialization.
  • Automated token caching: Thread-safe and async-safe double-checked token management with conditional expected_token invalidation and retry-once logic.
  • Comprehensive African payment coverage: MTN MoMo Collection (including CIBA and OAuth2 token exchange/refresh), Disbursement, Remittance, and Sandbox; Airtel Money (AirtelClient / AsyncAirtelClient with encrypt_airtel_pin()); Wave; Safaricom M-Pesa (Daraja); Paystack; Flutterwave; and Orange Money behind PaymentRouter.
  • Resilience and observability: Configurable idempotent retries with Retry-After and jitter, bounded streaming response caps (max_response_bytes), HTTP 3xx redirect rejection, wait_for_settlement() / async_wait_for_settlement(), TelemetryHook observability events, 18-market MSISDN carrier detection, FastAPI/Starlette and Django webhook verifiers, and a local py-momo-sdk mock simulator.
  • CLI utility: Optional py-momo-sdk Typer CLI for sandbox provisioning, collections, disbursements, remittances, Airtel PIN encryption, webhook verification, carrier lookup, and mock server hosting.

Installation

Install the core library from PyPI:

pip install py-momo-sdk

Install optional extras as needed:

pip install "py-momo-sdk[cli]"      # Typer CLI tool
pip install "py-momo-sdk[airtel]"   # cryptography for encrypt_airtel_pin()
pip install "py-momo-sdk[fastapi]"  # FastAPI / Starlette ASGI webhook verifier
pip install "py-momo-sdk[django]"   # Django webhook verifier
pip install "py-momo-sdk[all]"      # All optional extras

For local development and testing:

pip install -e ".[all,dev]"

Quickstart

Check installed version and provision sandbox credentials

import py_momo_sdk
from py_momo_sdk import PyMomoSDK, PyMomoSDKConfig

print(py_momo_sdk.__version__)

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 and wait for settlement:

from py_momo_sdk import (
    ProductConfig,
    PyMomoSDK,
    PyMomoSDKConfig,
    wait_for_settlement,
)

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:
    balance = client.collection.get_balance()
    print(f"Available balance: {balance.available_balance} {balance.currency}")

    reference_id = client.collection.request_to_pay(
        amount="1000",
        currency="UGX",
        payer_msisdn="256771234567",
        external_id="ext-tx-12345",
        payer_message="Payment for invoice 123",
        payee_note="Thank you for shopping with us",
    )

    tx = wait_for_settlement(
        lambda: client.collection.get_payment_status(reference_id),
        timeout=60.0,
        interval=2.0,
    )
    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:
        is_active = await client.disbursement.is_account_holder_active("256771234567")
        print(f"Account holder active: {is_active}")

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

        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

Install pip install "py-momo-sdk[cli]" and export credentials via PY_MOMO_SDK_* environment variables or --*-file flags so secrets are never 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"

py-momo-sdk --version
py-momo-sdk sandbox provision --callback-host "example.com" --output-file ./creds.json
py-momo-sdk collection balance
py-momo-sdk collection status "550e8400-e29b-41d4-a716-446655440000"

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

Testing

Run style checks, type checking, security analysis, and coverage reports:

ruff check .
black --check .
isort --check-only .
mypy py_momo_sdk/ tests/
bandit -r py_momo_sdk/ -ll
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.3.1

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.3.1
File Size Uploaded Provenance Actions
py_momo_sdk-1.3.1.tar.gz 186.4 kB With provenance Details for py_momo_sdk-1.3.1.tar.gz

Built distribution (wheel)

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

Total release size: 319.3 kB

Release files / py_momo_sdk-1.3.1.tar.gz

Download URL py_momo_sdk-1.3.1.tar.gz
Size 186.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0463a070d74ebc002099a52af14b558f3443cd7270a9570667a0dbf61e0fb4c3
BLAKE2b-256 checksum
How to use checksums
842484f94d6eeeb8a91caa2c0afd79f644853d4a3c2c1ace17e0bc905622255e
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 24, 2026.

Transparency log

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

Download URL py_momo_sdk-1.3.1-py3-none-any.whl
Size 132.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a22298a6f1918a3c7e4e675b1049d4ee9bf27c56a63c6901401d44c053df4eeb
BLAKE2b-256 checksum
How to use checksums
86f806dffb9bf6afa8be05c7472c3e05b4d47753949f07044fbe1d7ba50d1bb3
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 24, 2026.

Transparency log

Security for py-momo-sdk 1.3.1

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.3.1.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 24, 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