Python SDK
Install the Strongmb Python client and handle successful, processing and failed purchases.
Install the package
pip install strongmb
Install in your backend project and commit the dependency lockfile where supported. Consult the official repository for runtime requirements and releases.
Configure the API key
Set STRONGMB_API_KEY in your server environment. The example reads it from that variable. Separate development and production configuration. Never expose the key in a browser bundle.
A complete purchase example
import os
import secrets
from strongmb import Strongmb, ApiError, AuthError, StrongmbError
client = Strongmb(os.environ["STRONGMB_API_KEY"])
try:
response = client.data.purchase(
phone="0123456789",
product_code="smb_mtn_sme_1gb_30days",
reference="MYAPP" + secrets.token_hex(12),
)
if response.successful():
data = response.data()
print(f"1GB sent to {data['recipient']}")
print(f" Balance: ₦{data['balance_after']:,}")
elif response.processing():
print("Processing… reference:", response.data()["reference"])
elif response.failed():
print("Failed. Trace ID:", response.trace_id())
except AuthError:
print("Invalid API key.")
except ApiError as e:
print(f"Error [{e.get_api_code()}]: {e}")
except StrongmbError as e:
print(f"Network error: {e}")How the example works
| Part | Explanation |
|---|---|
| Imports | Load the client and relevant error types. |
| Constructor | Reads the API key from your server environment. |
| Purchase arguments | Set the recipient, product code and unique reference. |
| successful() | Read the payload and show a completed receipt. |
| processing() | Keep the order pending rather than repeating the purchase. |
| failed() | Retain identifiers and reconcile the failed outcome. |
| Error handler | Separate authentication, API and network failures. |
Parameter naming
Use product_code in Python keyword arguments. The REST API uses product_code. Follow the client example for the runtime you use.
Reliable transaction handling
Persist the order before calling the client. A network failure leaves the outcome uncertain. Read transaction lifecycle for duplicate-reference handling and the current transaction lookup behavior.
Versions and troubleshooting
These examples follow the existing Strongmb SDK documentation. Check the SDK source and README for version-specific constructor options and available resources. Use the REST API for services not exposed by your installed SDK.
Customer names, phone numbers, meter and smart-card numbers in these examples are fictional placeholders. Replace them with valid customer details for real requests.
Questions? Let’s work through them.
Having an issue or need help with your integration? Join the Strongmb Slack community to ask questions and get assistance from our team and other developers.
Keep API keys and customer details private when sharing examples.
Experiencing a service issue? Check Strongmb’s service status for incident updates.
Did this page help you?
Up to 100 characters. Please leave out personal details, account information and API keys.