Python Tutorial

Send WhatsApp Messages
with Python

A complete guide to sending WhatsApp messages programmatically using Python and MazeAPI. Works with requests, httpx, or aiohttp. No Meta approval needed.

Up and running
in 3 steps

No external SDKs needed beyond your preferred HTTP library. Works with Python 3.8 and above.

1
Sign up & connect your number

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.

2
Get your API key

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.

3
Send your first message

Make a single POST request with requests, use aiohttp for async, or set up a Flask webhook endpoint — all shown in the examples below.

Ready-to-run Python snippets

Install pip install requests or pip install aiohttp, then copy and run.

Using requests

send_whatsapp.py
# 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)

send_async.py
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

webhook.py
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)

Built for Python developers

Standard REST API — works with requests, httpx, aiohttp, or any HTTP library in the Python ecosystem.

Works with any HTTP library

requests, httpx, aiohttp, urllib — use whichever HTTP client fits your project. No custom SDK to maintain.

Async-first webhook delivery

Inbound messages POST to your Flask, FastAPI, or Django endpoint in real time. Automatic retries on failure — no message dropped silently.

Multi-instance support

Manage several WhatsApp numbers from a single API key. Ideal for Python automation pipelines serving multiple clients or departments.

Flat pricing, no per-message fees

Run cron jobs, bulk notifications, or high-frequency bots — all on a predictable monthly plan with no per-message cost surprises.

Start sending WhatsApp messages today

Get your API key in minutes. No Meta approval, no setup fees.

Get Started →
✓ No setup fees ✓ Cancel anytime ✓ Full API access from day one