eSMSAfrica
الأسعار تسجيل الدخول Get started
Python

How to send SMS from Python

Send an SMS from Python with the requests library and the eSMS Africa SMS API.

bash
pip install requests

1. Install requests

bash
pip install requests

2. Send an SMS

Put your API key in an environment variable and POST the message.

python
import os, requests

res = requests.post(
    "https://api.esmsafrica.io/v1/sms/send",
    headers={"Authorization": f"Bearer {os.environ['ESMS_API_KEY']}"},
    json={
        "to": "+254712345678",
        "from": "MyBrand",
        "message": "Hello from Python",
    },
    timeout=15,
)
res.raise_for_status()
print(res.json())  # {'id': ..., 'status': ...}

FAQ

Which Python versions are supported?

Any modern Python 3 with the requests library. There is also an official Python SDK.

How do I send to multiple recipients?

Send one request per recipient, or use the bulk endpoint / contact lists for large campaigns.

Ready to send?
Get an API key free and reach every African network.