How to send a WhatsApp message with Python
Send text and media messages from Python with a single HTTP request, then receive replies on your own webhook. Plain REST and JSON — no SDK, no template approval.
Last updated:
- Python
- REST + JSON
- no SDK needed
- webhook replies
import requests
PID = "your-pid"
PHONE_ID = "your-phone-id"
TOKEN = "your-token"
res = requests.post(
f"https://api.maytapi.com/api/{PID}/{PHONE_ID}/sendMessage",
headers={"x-maytapi-key": TOKEN},
json={
"to_number": "1415xxxxx67",
"type": "text",
"message": "Hello from Python!",
},
timeout=10,
)
print(res.json())What you need
Four things, all available in the console within a few minutes.
-
account
A Maytapi account
Sign up and start the free trial — no card required.
-
phone
A paired number
Scan the QR code with WhatsApp on your phone. Your number keeps working as usual.
-
token
pid and token
Copy them from the token page of the console; phone_id is shown next to your number.
-
Python
A Python environment
Any recent Python version with its standard HTTP client is enough.
Send a text message with Python
POST a JSON body to /sendMessage with your token in the x-maytapi-key header. The message is queued on your phone and the response returns immediately.
- ✓to_number in international format, e.g. 1415xxxxx67
- ✓type: text and the message body
- ✓The response contains the message id
curl -X POST "https://api.maytapi.com/api/$PID/$PHONE_ID/sendMessage" \
-H "x-maytapi-key: $TOKEN" \
-H "Content-Type: application/json" \
-d '{"to_number": "1415xxxxx67", "type": "text", "message": "Hello from Python!"}'{
"success": true,
"data": {
"chatId": "1415xxxxx67@c.us",
"msgId": "3EB065B353B9493D00C9"
}
}Send an image, video or document
Use the same endpoint with type media and a public file URL or a base64 data URI. Add an optional caption and file name.
- ✓Images, video, audio, PDF and other documents
- ✓Caption in the text field
- ✓Base64 data URIs work as well as URLs
res = requests.post(
f"https://api.maytapi.com/api/{PID}/{PHONE_ID}/sendMessage",
headers={"x-maytapi-key": TOKEN},
json={
"to_number": "1415xxxxx67",
"type": "media",
"message": "https://example.com/invoice-10482.pdf",
"text": "Your invoice for order #10482",
"filename": "invoice-10482.pdf",
},
timeout=10,
)Receive replies with a Python webhook
Register a webhook URL once. Incoming messages, delivery and read receipts arrive as JSON; answer through the reply URL included in each event.
- ✓Return 200 quickly, then process the event
- ✓Skip your own messages with fromMe
- ✓Use event.reply to answer in the same chat
requests.post(
f"https://api.maytapi.com/api/{PID}/setWebhook",
headers={"x-maytapi-key": TOKEN},
json={"webhook": "https://example.com/maytapi/webhook"},
timeout=10,
)from flask import Flask, request
import requests
app = Flask(__name__)
@app.post("/maytapi/webhook")
def webhook():
event = request.get_json()
if event.get("type") == "message" and not event["message"]["fromMe"]:
requests.post(
event["reply"],
headers={"x-maytapi-key": TOKEN},
json={
"to_number": event["conversation"],
"type": "text",
"message": "Thanks! We received your message.",
},
timeout=10,
)
return "", 200Python WhatsApp API FAQ
Ask our support team anything over WhatsApp. Average response time is under 24 hours.
Help center →Is there an official Python SDK?
You do not need one. The API is plain REST with JSON, so the standard Python HTTP client is enough, as the examples on this page show.
Can I send messages to groups from Python?
Yes. Use the group id (ending in @g.us) as to_number; group management endpoints are available on every plan.
Why did my message not arrive?
Check that the phone status is active, then look at the queue and logs in the console. New numbers should be warmed up before sending in volume.
More WhatsApp API features

Get your key, send your first message in ten minutes
No approval, no templates, no card. Every endpoint is open for three days.