Production-grade Python SDK for the AzamPay API — sync & async, mobile checkout, bank checkout, and payment links
Project description
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
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 azampay_python_sdk-1.0.0.tar.gz.
File metadata
- Download URL: azampay_python_sdk-1.0.0.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a6cff3c2a97aadb061b0f540d73b0f994ee2164d50ff69b4f7f917c1bd2f625
|
|
| MD5 |
c1d57d33bbf9f4ce41c8e0485c430f91
|
|
| BLAKE2b-256 |
d4714775eaeb35d875e2f45c4a6f209c91183cc06c9633d73bf7b568efa64f5a
|
File details
Details for the file azampay_python_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: azampay_python_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 23.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b63a72e4bb9416b5568c5728390018659ccbb56ae1a608d5f094d3d040b39321
|
|
| MD5 |
8d303b9fd6f3a17f0d459f9ae383e578
|
|
| BLAKE2b-256 |
caf06c108638f36ef7dc8f50a9434e6a61500994e34ed27f2ca80dfc25fbed0b
|