Send SMS with Python
To send an SMS from Python, POST the number and text to the curl-sms API with requests. No SDK needed; the whole integration is one function.
Example
import os
import requests
API = "https://curl-sms.com/api/sms/send"
def send_sms(receiver: str, body: str) -> dict:
resp = requests.post(
API,
headers={"Authorization": f"Bearer {os.environ['CURLSMS_KEY']}"},
json={"receiver": receiver, "body": body},
timeout=10,
)
if resp.status_code != 202:
err = resp.json()["error"]
raise RuntimeError(f"{err['code']}: {err['message']}")
return resp.json()
sms = send_sms("+4915123456789", "Hello from Python")
print(sms["id"], sms["status"]) # 01JDQ8M3… queued
Install the dependency with pip install requests and set CURLSMS_KEY to a test key (cs_test_…) first: it runs every check but sends nothing and costs nothing.
What you get back
202 Accepted with the SMS as JSON: id, status (queued, later sent and delivered), segments, encoding and price. On errors the API returns {"error": {"code", "message"}}, for example insufficient_balance or invalid_receiver; see error codes.
To follow the status, call GET /api/sms/<id> or let curl-sms call you: delivery reports via webhook include a Python signature check.
Tips
- Safe retries: pass
headers={"Idempotency-Key": "order-4711"}as well. If a request times out, send it again with the same key and body; it is never sent twice. - Many receivers: use
"receivers": [...]instead of"receiver"for up to 100 numbers with the same text. - Scheduling: add
"send_at": "2026-12-24T09:00:00+01:00"to send later. - Django, Flask, FastAPI: call
send_smsfrom a background task, not inside the request, so a slow network never blocks your users.