A complete guide to sending WhatsApp messages programmatically using Python and MazeAPI. Works with requests, httpx, or aiohttp. No Meta approval needed.
No external SDKs needed beyond your preferred HTTP library. Works with Python 3.8 and above.
Create a free MazeAPI account, add a WhatsApp instance from the dashboard, and scan the QR code with your phone to connect your WhatsApp number.
Navigate to API Keys in your dashboard and create a new key. Copy the wa_live_… token — it's shown only once. Store it as an environment variable.
Make a single POST request with requests, use aiohttp for async, or set up a Flask webhook endpoint — all shown in the examples below.
Install pip install requests or pip install aiohttp, then copy and run.
Using requests
# send_whatsapp.py import requests API_KEY = "wa_live_your_key_here" INSTANCE_ID = "your_instance_id" def send_whatsapp(number: str, message: str): url = ( f"https://www.mazeapi.com/api/v1/instances/" f"{INSTANCE_ID}/messages/text" ) headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json", } payload = { "number": number, "text": {"body": message}, } response = requests.post(url, json=payload, headers=headers) response.raise_for_status() data = response.json() print(f"Message sent: {data['messageId']}") return data send_whatsapp("972501234567", "Hello from Python!")
Using aiohttp (async)
import aiohttp import asyncio async def send_whatsapp_async(number: str, message: str): async with aiohttp.ClientSession() as session: async with session.post( f"https://www.mazeapi.com/api/v1/instances/" f"{INSTANCE_ID}/messages/text", headers={ "Authorization": f"Bearer {API_KEY}" }, json={ "number": number, "text": {"body": message}, }, ) as resp: data = await resp.json() return data asyncio.run( send_whatsapp_async("972501234567", "Hello async!") )
Receiving webhooks with Flask
from flask import Flask, request app = Flask(__name__) @app.route("/webhook", methods=["POST"]) def webhook(): payload = request.get_json() if payload.get("event") == "message.received": print(f"New message from: {payload['data']['from']}") print(f"Text: {payload['data']['body']}") return "", 200 if __name__ == "__main__": app.run(port=3000)
Standard REST API — works with requests, httpx, aiohttp, or any HTTP library in the Python ecosystem.
requests, httpx, aiohttp, urllib — use whichever HTTP client fits your project. No custom SDK to maintain.
Inbound messages POST to your Flask, FastAPI, or Django endpoint in real time. Automatic retries on failure — no message dropped silently.
Manage several WhatsApp numbers from a single API key. Ideal for Python automation pipelines serving multiple clients or departments.
Run cron jobs, bulk notifications, or high-frequency bots — all on a predictable monthly plan with no per-message cost surprises.
Get your API key in minutes. No Meta approval, no setup fees.
Get Started →