Send an SMS from Python with the requests library and the eSMS Africa SMS API.
pip install requestspip install requestsPut your API key in an environment variable and POST the message.
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': ...}Any modern Python 3 with the requests library. There is also an official Python SDK.
Send one request per recipient, or use the bulk endpoint / contact lists for large campaigns.