SDK
v0.1.0
Python SDK
The official Python SDK for Sendexa. One package, one client, every API — SMS, OTP, WhatsApp, Email, Voice, and Webhook verification.
Zero Dependencies
Built on the Python standard library — urllib and hmac only. No pip bloat.
Universal
Works in Django, Flask, FastAPI, AWS Lambda, and plain scripts.
Fully Typed
Complete TypedDicts for every request and response. Passes mypy strict.
Python 3.9+
Supports Python 3.9 and above. No external type-stub packages needed.
Installation
Bash
pip install sendexa
Requirements
Python 3.9 or later. The SDK uses only the standard library —
urllib, hmac, and hashlib — no third-party packages required.Initialise the Client
Create one client instance per application and reuse it — it is stateless and safe to share across threads and requests.
Python
import osfrom sendexa import Sendexaclient = Sendexa(api_key=os.environ["SENDEXA_API_KEY"],api_secret=os.environ["SENDEXA_API_SECRET"],)
API Examples
Send single and bulk SMS messages with delivery tracking.
Python
# Send a single SMSresponse = client.sms.send(to="0244123456",from_="MyBrand",message="Your order #1234 has been confirmed!",)print(response["data"]["messageId"], response["data"]["status"])# Send bulk SMSclient.sms.send_bulk(from_="MyBrand",message="Hello from MyBrand!", # shared fallbackmessages=[{"to": "0244123456", "message": "Hi Alice!"},{"to": "0555987654"}, # uses shared message],)# Check delivery statusstatus = client.sms.get_status(response["data"]["messageId"])print(status["data"]["status"]) # "delivered"# Resend a failed messageclient.sms.resend(response["data"]["messageId"])
Error Handling
All API errors raise a SendexaError with structured fields for easy branching.
Python
from sendexa import Sendexa, SendexaErrortry:client.sms.send(to="0244123456", from_="MyBrand", message="Hi!")except SendexaError as err:print(err.status) # HTTP status e.g. 403print(err.code) # API code e.g. "SENDER_ID_NOT_APPROVED"print(str(err)) # Human text e.g. "Sender ID not approved"print(err.request_id) # Trace ID for Sendexa support
| Attribute | Type | Description |
|---|---|---|
| status | int | HTTP status code (400, 401, 403, 429…) |
| code | str | Machine-readable error code from the API |
| str(err) | str | Human-readable description of the error |
| request_id | str | None | Sendexa trace ID — include when contacting support |
| raw | Any | The full raw error payload from the API |
Best Practices
- Create one
Sendexainstance at startup and reuse it — do not instantiate per request - Store credentials in environment variables, never in source code
- Always call
client.webhooks.verify()before processing any webhook event - Catch
SendexaErrorseparately from generic exceptions so you can branch onerr.code - Pass a custom
timeoutif your environment has strict request limits (default: 30 s)