Skip to main content

MainMoney Python SDK

PyPI License: MIT

Python client for the MainMoney aggregator merchant API. Install this package in your Python application (Django, FastAPI, Flask, or scripts).

The JS/TS frontend SDK can be used in the browser only if this SDK (or the PHP or Node SDK) runs on your server. Never put merchant API keys in frontend code.

Requirements

  • Python 3.11 or later (3.13 or 3.14 recommended)
  • A merchant application on MM Aggregator

Install

With uv (recommended):

uv add mm-aggr-sdk

With pip:

pip install mm-aggr-sdk

With Poetry:

poetry add mm-aggr-sdk

Quick start

import os

from mm_aggr import Client

client = Client(
    client_id=os.environ["MM_CLIENT_ID"],
    secret=os.environ["MM_API_SECRET"],
    test=True,  # https://testaggregator.mainmoney.net — omit for production
)

deposit = client.deposits.create(
    {
        "provider_code": "VODACOM_MPESA_COD",
        "reference": "ORDER-123",
        "amount": "100.00",
        "currency": "USD",
        "customer_phone": "243820000000",
    },
    idempotency_key="ORDER-123",
)

Defaults: production https://aggregator.mainmoney.net/api/v1/, test https://testaggregator.mainmoney.net/api/v1/. Pass base_uri only to override. Configure credentials from your environment. Merchant API docs: /api/v1/docs/merchants/ on the aggregator host.

Exchange client_id and secret for a Bearer access token is handled by the SDK. There is no X-API-KEY header. Resend the same reference and Idempotency-Key only when retrying the same create (same body). When the body changes (new phone number, new currency) use a new Idempotency-Key; after a failed deposit also use a new reference, because a failed one stays reserved. Derive the key from your checkout session, not from the cart or order. Amounts are decimal strings; do not mix currencies.

Verify inbound webhooks with client.webhooks.verify(raw_body, signature, secret).

Do not send merchant API keys to the browser.

Guides

Detailed, per-flow guides (authentication, countries and providers, fees, deposits, payouts, remittances, refunds, status polling, webhooks, idempotency, payment links, MainMoney Rails sellers and transfers, wallets and reports, errors, browser checkout proxy) are in docs/.

  • Browser checkout widget: your backend forwards its calls with mm_aggr.checkout_proxy (docs/checkout-proxy.md).
  • Payment links: client.payment_links.create(...) returns the url to give your customer (docs/payment-links.md).
  • Platforms acting for sellers: Client(..., merchant_account="<seller id>") or client.with_merchant_account(id) (docs/mainmoney-rails.md).

License

Copyright (c) 2026 MainMoney SARL. Licensed under the MIT License. See LICENSE.

Examples

Runnable mini-shops live in examples/. Each folder has its own README (Django REST Framework, FastAPI, Flask). Pair them with a JS/TS frontend example.

Want to contribute? See CONTRIBUTING.md.

Metadata

Release files for mm-aggr-sdk 0.2.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 mm-aggr-sdk 0.2.1
File Size Uploaded Provenance Actions
mm_aggr_sdk-0.2.1.tar.gz 247.2 kB With provenance Details for mm_aggr_sdk-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mm-aggr-sdk 0.2.1
File Interpreter ABI Platform Actions
mm_aggr_sdk-0.2.1-py3-none-any.whl Python 3 none any Details for mm_aggr_sdk-0.2.1-py3-none-any.whl

Total release size: 271.1 kB

Release files / mm_aggr_sdk-0.2.1.tar.gz

Download URL mm_aggr_sdk-0.2.1.tar.gz
Size 247.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8a1005a9176597aefa241445c53d4f30df2dc7bbb3ff318f42d1e53b48ebf4af
BLAKE2b-256 checksum
How to use checksums
b95c576df8e3b71a9045d1c9d964c445eb6a5728c9b050c4805299e7a6634af4
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 / mm_aggr_sdk-0.2.1-py3-none-any.whl

Download URL mm_aggr_sdk-0.2.1-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
44229f15866fc07f0e7c73273dbba621d71c746a7d6f512a8c01ab8a3883b39f
BLAKE2b-256 checksum
How to use checksums
49909993542b08eba8294ac4b337167580e05f6a687fb2432bf401b207f91235
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 mm-aggr-sdk 0.2.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 mm_aggr_sdk-0.2.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