Async Support
AsyncSendAfrica mirrors the sync resource API, but every call is awaitable. It requires the async extra:
pip install sendafrica[async]from sendafrica import AsyncSendAfrica
client = AsyncSendAfrica(api_key="SA-...", timeout=10, max_retries=3)
await client.sms.send(to="0712345678", message="Async hello")
await client.aclose() # close the httpx transport when doneThe same resources are available — sms, credits, rates, sender_ids, payments, webhooks — with identical signatures.
FastAPI example
from fastapi import FastAPI
from sendafrica import AsyncSendAfrica
app = FastAPI()
client = AsyncSendAfrica(api_key="SA-...")
@app.on_event("shutdown")
async def shutdown():
await client.aclose()
@app.post("/send")
async def send():
result = await client.sms.send(to="0712345678", message="Async hello")
return {"message_id": result.message_id}Notes
- Without
httpx, constructingAsyncSendAfricaraisesImportErrorimmediately. - Always close the client (
await client.aclose()) when your application shuts down to release the connection pool. - Retries, backoff, and error types are identical to the sync client.
Last updated on