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.2) 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.2

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.2
File Size Uploaded Provenance Actions
py_momo_sdk-1.3.2.tar.gz 215.9 kB With provenance Details for py_momo_sdk-1.3.2.tar.gz

Built distribution (wheel)

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

Total release size: 362.9 kB

Release files / py_momo_sdk-1.3.2.tar.gz

Download URL py_momo_sdk-1.3.2.tar.gz
Size 215.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bb8f36ef2505e18de0c3a592333c23dafee4ae0a96d6cc5e2a705e6f44d54c4b
BLAKE2b-256 checksum
How to use checksums
a73f4915e680911c4f0712794a80ffb95eadd76f2c893d29153fc5565ad5338e
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 27, 2026.

Transparency log

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

Download URL py_momo_sdk-1.3.2-py3-none-any.whl
Size 146.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7cf935fffd62c9455c2a3b4e1208949b6d5e4353a8e60b9930cc87e988486214
BLAKE2b-256 checksum
How to use checksums
1c9c3fe761c649c3183086f4f671136de64c12ebd13cc1ddbaeeeac95aedcd37
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 27, 2026.

Transparency log

Security for py-momo-sdk 1.3.2

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.2.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 27, 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