Send a WhatsApp message with an API in Python
Sending a WhatsApp message from your code doesn't require a toll-free number or a drawn-out Meta Business review: a single HTTP request is enough. This guide shows how to do it in Python, from API key to first delivered message.
What you need
- A SenWaAPI account and an API key (
snw_prefix), available in your dashboard. - A linked WhatsApp session (scan the QR code once).
- Python 3.9+ with the
requestslibrary (pip install requests).
First send in 8 lines
The API exposes a REST endpoint that takes a recipient and a text. Here's the minimal send:
import requests
resp = requests.post(
"https://senwaapi.com/api/send-message",
headers={"Authorization": "Bearer snw_your_api_key"},
json={"to": "+221771234567", "text": "Hello from Python 👋"},
)
resp.raise_for_status()
print(resp.json())
The number is in international format (country code included). On success, the API returns a JSON object confirming the message was queued.
Handle errors properly
In production, never assume a send succeeds. The two most common cases are an
invalid key (401) and an unlinked WhatsApp session. Wrap the call so you can
react without crashing your app:
try:
resp = requests.post(
"https://senwaapi.com/api/send-message",
headers={"Authorization": "Bearer snw_your_api_key"},
json={"to": number, "text": message},
timeout=10,
)
resp.raise_for_status()
except requests.HTTPError as e:
# Log the status and body server-side, never client-side.
print("Send failed:", e.response.status_code)
Real-world use cases
- Order notifications for an e-commerce store.
- One-time verification codes (OTP).
- Automated appointment reminders.
For the details of each endpoint (media, session status, webhooks), see the API documentation. To estimate your volume, check the pricing.
What about rate limits?
Each WhatsApp session enforces a minimum delay between two sends to stay within the platform's rules. Space out your messages or queue them on the application side — don't try to bypass this limit, it's what protects your number from a ban.
You now have everything to integrate WhatsApp into your Python application.