Skip to Content
SDKsPython

Python SDK

Installation

pip install sendafrica # or uv add sendafrica

Quick Start

Synchronous Client

from sendafrica import SendAfrica client = SendAfrica(api_key="SA-your-api-key") balance = client.credits.get_balance() print(f"Credits available: {balance.credits}") response = client.sms.send( to="+255712345678", message="Hello from SendAfrica!" ) print(f"Message ID: {response.message_id}")

Async Client

from sendafrica import AsyncSendAfrica async with AsyncSendAfrica(api_key="SA-your-api-key") as client: balance = await client.credits.get_balance() response = await client.sms.send( to="+255712345678", message="Hello from SendAfrica!" )

API Reference

# Send single SMS response = client.sms.send(to="+255712345678", message="Hello!") # Send bulk SMS response = client.sms.send_bulk( recipients=["+255712345678", "+255787654321"], message="Sale announcement!" ) # List contacts contacts = client.contacts.list(list_id="1") # Create campaign campaign = client.campaigns.create( name="Summer Sale", contact_group_id="2", message="Get 30% off!" )

Error Handling

from sendafrica.exceptions import SendAfricaError, AuthenticationError, RateLimitError try: response = client.sms.send(to="+255712345678", message="Hello!") except AuthenticationError: print("Invalid API key") except RateLimitError: print("Rate limit exceeded") except SendAfricaError as e: print(f"API error: {e}")

Configuration

client = SendAfrica( api_key="SA-your-api-key", base_url="https://api.sendafrica.online/v1", timeout=30, max_retries=3, )
Last updated on