Python SDK
Coming Soon
The sendapi Python package is currently under development and has not yet been published to PyPI. The examples below show the planned SDK interface. In the meantime, use any HTTP client (e.g., requests, httpx) with the REST API endpoints directly.
The official SendAPI Python SDK will support both synchronous and async/await usage with full type hints.
Installation
bash
pip install sendapiSetup
python
from sendapi import SendAPI
client = SendAPI("sk_live_YOUR_API_KEY")Sending a WhatsApp Message
python
message = client.whatsapp.send(
session_id="sess_01H8BKF...Z2T",
to="+447700900000",
type="text",
text={"body": "Hello from SendAPI!"}
)
print(message.id) # msg_01H8...QPSending an SMS
python
sms = client.sms.send(
to="+447700900000",
content="Your verification code is 847291"
)Sending an Email
python
email = client.email.send(
to="alice@example.com",
from_address="noreply@myapp.com",
subject="Welcome!",
html="<h1>Welcome to MyApp!</h1>"
)Sending and Verifying an OTP
python
# Send OTP
verification = client.verify.send(
to="+447700900000",
channel="auto",
brand_name="MyApp"
)
# Later, check the code:
result = client.verify.check(
id=verification.id,
code=user_entered_code
)
if result.valid:
print("User verified!")Async Support
python
import asyncio
from sendapi import AsyncSendAPI
async def main():
client = AsyncSendAPI("sk_live_YOUR_API_KEY")
message = await client.whatsapp.send(
session_id="sess_01H8BKF...Z2T",
to="+447700900000",
type="text",
text={"body": "Hello async!"}
)
print(message.id)
asyncio.run(main())Error Handling
python
from sendapi.exceptions import SendAPIError, RateLimitError
try:
client.whatsapp.send(...)
except RateLimitError as e:
print(f"Rate limited. Retry after: {e.retry_after}s")
except SendAPIError as e:
print(f"API error {e.status}: {e.code} — {e.message}")Webhook Verification
python
from sendapi.webhooks import verify_signature
def handle_webhook(request):
signature = request.headers.get("X-SendAPI-Signature")
raw_body = request.data
if not verify_signature(raw_body, signature, WEBHOOK_SECRET):
return {"error": "Invalid signature"}, 401
event = request.json
print(f"Event: {event['event']}")
return {"received": True}, 200