AzamPay Python SDK
Production-grade Python SDK for the AzamPay API — sync & async, mobile checkout, bank checkout, disbursements, payment links, and webhook verification.
Features
- Sync & Async —
AzamPayfor Django/Flask,AsyncAzamPayfor FastAPI/asyncio - Auto auth — token fetched on first call, cached for 23 hours, thread/async-safe refresh
- Checksum injection — HMAC-SHA256 automatically added to mutation requests when
x_api_keyis set - Retry logic — exponential backoff on transient 5xx errors and network failures
- Typed exceptions — every API error maps to a specific exception class
- Context manager —
with/async withfor clean connection lifecycle - PEP 561 — ships
py.typedfor full mypy support
Installation
pip install azampay-python-sdk
Requires Python 3.10+.
Quick Start
Synchronous
from azampay import AzamPay, AzamPayError
with AzamPay(
app_name="MyApp",
client_id="your_client_id",
client_secret="your_client_secret",
x_api_key="your_x_api_key",
sandbox=True,
) as client:
# Mobile checkout (USSD push)
result = client.checkout.mobile_checkout(
amount="5000",
account_number="0741234567",
external_id="order-001",
provider="Airtel",
)
print(result["transactionId"])
Asynchronous
import asyncio
from azampay import AsyncAzamPay
async def main() -> None:
async with AsyncAzamPay(
app_name="MyApp",
client_id="your_client_id",
client_secret="your_client_secret",
x_api_key="your_x_api_key",
sandbox=True,
) as client:
result = await client.checkout.mobile_checkout(
amount="5000",
account_number="0741234567",
external_id="order-001",
provider="Airtel",
)
asyncio.run(main())
Services
client.checkout
# Mobile money (USSD push) — Airtel, Tigo, MPESA, HALOPESA, AZAMPESA, TTCL
client.checkout.mobile_checkout(amount, account_number, external_id, provider, currency="TZS")
# Internet banking
client.checkout.bank_checkout(amount, merchant_account_number, merchant_mobile_number, reference_id, bank_name)
client.disbursement
# Mobile wallet payout
client.disbursement.disburse_mobile(full_name, mobile_number, provider, amount)
# Bank account payout
client.disbursement.disburse_bank(full_name, account_number, bank_name, amount)
# Raw payout with full control
client.disbursement.disburse(source, destination, amount)
client.lookup
# Check transaction status
client.lookup.transaction_status(pg_reference_id="pg-123")
client.lookup.transaction_status(external_id="order-001")
# Resolve bank account holder name
client.lookup.name_lookup(bank_name="CRDB", account_number="1234567890")
client.links
# List all payment links
client.links.list_links()
# Create a reusable payment link
client.links.create_link(amount="10000", link_name="School Fees")
# Get payments for a link
client.links.get_link_payments(link_code="LC1")
Webhook Verification
from azampay import WebhookValidator
# In your Flask/FastAPI/Django view:
is_valid = WebhookValidator.verify(
payload=request.json,
signature=request.headers["X-Checksum"],
checksum_key="your_x_api_key",
)
Error Handling
from azampay import (
AzamPayError,
AuthenticationError,
ValidationError,
NotFoundError,
RateLimitError,
ServerError,
)
try:
result = client.checkout.mobile_checkout(...)
except AuthenticationError:
# Invalid credentials
except ValidationError as e:
print(e.response) # Full API response dict
except RateLimitError:
# Back off and retry
except AzamPayError as e:
print(e.status_code, e.response)
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
app_name |
str |
— | App name from AzamPay portal |
client_id |
str |
— | OAuth client ID |
client_secret |
str |
— | OAuth client secret |
x_api_key |
str | None |
None |
X-API-Key for requests and checksums |
sandbox |
bool |
False |
Use sandbox environment |
timeout |
float |
30.0 |
HTTP timeout in seconds |
max_retries |
int |
3 |
Max retries on transient failures |
Development
make install # Install with dev dependencies
make test # Run tests
make lint # Ruff lint
make typecheck # mypy strict
make build # Build wheel + sdist
License
MIT
Metadata
Release files for azampay-python-sdk 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| azampay_python_sdk-1.0.0.tar.gz | 24.5 kB | Without provenance | Details for azampay_python_sdk-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| azampay_python_sdk-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for azampay_python_sdk-1.0.0-py3-none-any.whl |
Total release size: 47.7 kB
Release files / azampay_python_sdk-1.0.0.tar.gz
| Download URL | azampay_python_sdk-1.0.0.tar.gz |
|---|---|
| Size | 24.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a6cff3c2a97aadb061b0f540d73b0f994ee2164d50ff69b4f7f917c1bd2f625
|
|
BLAKE2b-256 checksum How to use checksums |
d4714775eaeb35d875e2f45c4a6f209c91183cc06c9633d73bf7b568efa64f5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / azampay_python_sdk-1.0.0-py3-none-any.whl
| Download URL | azampay_python_sdk-1.0.0-py3-none-any.whl |
|---|---|
| Size | 23.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b63a72e4bb9416b5568c5728390018659ccbb56ae1a608d5f094d3d040b39321
|
|
BLAKE2b-256 checksum How to use checksums |
caf06c108638f36ef7dc8f50a9434e6a61500994e34ed27f2ca80dfc25fbed0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for azampay-python-sdk 1.0.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.