One SDK. Every African payment. Python SDK for M-Pesa, Airtel Money, and more.
Project description
umojasdk
One SDK. Every African payment.
UmojaSDK is the unified Python SDK for African mobile money integrations — M-Pesa (Safaricom Daraja 3.0), Airtel Money, and more.
Built by Synapse Softwares.
Installation
pip install umojasdk
Quickstart — M-Pesa STK Push
from umojasdk import UmojaMpesa, MpesaConfig, STKPushRequest
mpesa = UmojaMpesa(MpesaConfig(
consumer_key="your_key",
consumer_secret="your_secret",
shortcode="174379",
passkey="your_passkey",
callback_url="https://yourapp.com/mpesa/callback",
env="sandbox"
))
result = mpesa.stk_push(STKPushRequest(
phone="0712345678", # accepts 07XX, +2547XX, 2547XX — auto-normalized
amount=1500,
reference="ORDER-001"
))
print(result.checkout_request_id)
# Parse incoming Daraja callback
from umojasdk import parse_stk_callback
payment = parse_stk_callback(request_body)
if payment["success"]:
print(payment["mpesa_receipt_number"])
print(payment["amount"])
# CRITICAL: Always return 200 to stop Daraja retries
return {"ResultCode": 0, "ResultDesc": "Accepted"}
Quickstart — Airtel Money
from umojasdk import UmojaAirtel, AirtelConfig, AirtelCollectionRequest
airtel = UmojaAirtel(AirtelConfig(
client_id="your_client_id",
client_secret="your_client_secret",
env="sandbox"
))
result = airtel.request_to_pay(AirtelCollectionRequest(
phone="0733123456",
amount=500,
reference="ORDER-002"
))
Async Support
from umojasdk import AsyncUmojaMpesa, MpesaConfig, STKPushRequest
mpesa = AsyncUmojaMpesa(MpesaConfig(...))
result = await mpesa.stk_push(STKPushRequest(
phone="0712345678",
amount=1500,
reference="ORDER-001"
))
Features
| Feature | Status |
|---|---|
| STK Push (Lipa Na M-Pesa) | ✓ |
| STK Push status query | ✓ |
| C2B URL registration & callbacks | ✓ |
| B2C disbursements | ✓ |
| Transaction status query | ✓ |
| Transaction reversal | ✓ |
| SIM Swap detection (Daraja 3.0) | ✓ |
| Tax remittance to KRA (Daraja 3.0) | ✓ |
| Airtel Money collections | ✓ |
| Airtel Money disbursements | ✓ |
| Webhook parsing | ✓ |
| Phone number normalization | ✓ |
| Automatic token refresh | ✓ |
| Typed errors | ✓ |
| Async client | ✓ |
Error Handling
from umojasdk.core.errors import UmojaAuthError, UmojaValidationError, UmojaApiError
try:
result = mpesa.stk_push(req)
except UmojaAuthError:
pass # bad credentials
except UmojaValidationError as e:
pass # bad input — str(e) is human-readable
except UmojaApiError as e:
pass # Daraja error — e.raw has full response
Environment Variables
MPESA_CONSUMER_KEY=
MPESA_CONSUMER_SECRET=
MPESA_SHORTCODE=174379
MPESA_PASSKEY=
MPESA_CALLBACK_URL=
MPESA_ENV=sandbox # "sandbox" | "production"
AIRTEL_CLIENT_ID=
AIRTEL_CLIENT_SECRET=
AIRTEL_ENV=sandbox
Related
- TypeScript SDK:
npm install umojasdk - CLI:
npx @umojasdk/cli init - Docs: umojasdk.dev
License
MIT — github.com/Knelso/Umoja_SDK
Built with precision in Nairobi, Kenya. For Africa, by Africa.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file umojasdk-0.1.1.tar.gz.
File metadata
- Download URL: umojasdk-0.1.1.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7de6496cb29ef3ee25ce627017e500c31ddf0148d5c16a8d60cde7822cc60189
|
|
| MD5 |
e925c51eb8b22f3d1740343d30e6b245
|
|
| BLAKE2b-256 |
f5365205308f8ace25e6b55f1978ca9a92c70a12ff4446d7a5809512c8e51893
|
Provenance
The following attestation bundles were made for umojasdk-0.1.1.tar.gz:
Publisher:
publish-pypi.yml on Knelso/Umoja_SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
umojasdk-0.1.1.tar.gz -
Subject digest:
7de6496cb29ef3ee25ce627017e500c31ddf0148d5c16a8d60cde7822cc60189 - Sigstore transparency entry: 1708778586
- Sigstore integration time:
-
Permalink:
Knelso/Umoja_SDK@23c523f850c89ea82fad78a9c88fd160d7a4a556 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Knelso
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@23c523f850c89ea82fad78a9c88fd160d7a4a556 -
Trigger Event:
release
-
Statement type:
File details
Details for the file umojasdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: umojasdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6da5f7d338a2845592314c273e3dbf9e3646210c038cfe46f640a855f0769da2
|
|
| MD5 |
05b1cef366c9bc6f5317a8ba0e3cd231
|
|
| BLAKE2b-256 |
a2118a6332377fc72ec9f0dafcf742ff903be29722be6a26c7738f4c476bdb7e
|
Provenance
The following attestation bundles were made for umojasdk-0.1.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on Knelso/Umoja_SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
umojasdk-0.1.1-py3-none-any.whl -
Subject digest:
6da5f7d338a2845592314c273e3dbf9e3646210c038cfe46f640a855f0769da2 - Sigstore transparency entry: 1708778605
- Sigstore integration time:
-
Permalink:
Knelso/Umoja_SDK@23c523f850c89ea82fad78a9c88fd160d7a4a556 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Knelso
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@23c523f850c89ea82fad78a9c88fd160d7a4a556 -
Trigger Event:
release
-
Statement type: