WACrew

Guide

WhatsApp chatbot in Python: four ways to build it in 2026

How to build a WhatsApp chatbot in Python in 2026. The official Cloud API, neonize, browser automation and a self-hosted HTTP API, with working requests code and the trade-offs of each.

Updated 4 min read
On this page
  1. The four routes
  2. Python against a self-hosted gateway
  3. When you do not need a chatbot at all
  4. Limits worth knowing
  5. FAQ

A WhatsApp chatbot in Python sounds like one library away, but there is no Python equivalent of Baileys that most people trust in production. In practice you pick one of four routes, and the choice decides how much you will maintain later: Meta's official API, a Python binding over a Go library, a browser you drive with Selenium, or a WhatsApp gateway that runs somewhere else and gives you plain HTTP.

The four routes

routewhat it isgood forthe catch
WhatsApp Cloud APIMeta's official API, called with requests plus a webhook in Flask or FastAPIbusinesses that message customers at scalebusiness verification, paid templates outside the 24 h window, a separate number
neonizePython SDK on top of whatsmeow (Go), Apache 2.0a script on your own numberyou run the session, reconnection and storage yourself
Browser automationSelenium or pywhatkit driving WhatsApp Webone-off sendsbreaks when the page changes, needs a browser running
HTTP gatewaya server that holds the session (WACrew, WAHA, Evolution API) and exposes RESTbots that live next to other Python codeone more service to host

The official API is the only route Meta supports. The other three connect as a linked device of a regular number, the same way WhatsApp Web does. That works, but bulk or cold messaging is what gets numbers banned, so keep any of them for people who already talk to you.

Python against a self-hosted gateway

If the bot should answer clients on your own number, the least code in Python is a gateway that already handles the session, the reconnects and the media. WACrew is an open-source one (Apache 2.0) and has a versioned REST API with Bearer tokens, documented in docs/api-v1.md.

Create a token on the server where the collector runs:

docker compose exec wacrew node scripts/api-token.mjs criar my-bot --escopos read,write

Then, from Python:

import os, uuid, requests

BASE = "https://your-panel.example.com/api/v1"
H = {"authorization": f"Bearer {os.environ['WAC_API_TOKEN']}"}

chats = requests.get(f"{BASE}/chats", params={"limit": 50}, headers=H, timeout=30).json()["data"]
slug = chats[0]["slug"]

msgs = requests.get(f"{BASE}/chats/{slug}/messages", params={"limit": 20}, headers=H, timeout=30).json()["data"]
for m in msgs:
    print("me" if m["fromMe"] else m["senderName"], m.get("text") or f"[{m['type']}]")

requests.post(
    f"{BASE}/chats/{slug}/messages",
    headers={**H, "idempotency-key": str(uuid.uuid4())},
    json={"text": "got it, checking now"},
    timeout=30,
)

The idempotency-key header matters: if your code retries after a timeout, the second call returns the first answer instead of sending the message twice.

To react to new messages, read the server-sent events of a chat:

import json

with requests.get(f"{BASE}/chats/{slug}/events", headers=H, stream=True, timeout=None) as r:
    for line in r.iter_lines(decode_unicode=True):
        if line and line.startswith("data: "):
            msg = json.loads(line[6:])
            print("new:", msg.get("text"))

When you do not need a chatbot at all

A lot of "WhatsApp chatbot in Python" projects are really "I want an AI to read my clients and answer like me". For that, writing the bot is the wrong layer: an AI coding agent such as Claude Code or Codex can do it through an MCP server, with no Python in between. WACrew ships one (npx -y wacrew-mcp, 37 tools) where replies pass a review that blocks robotic text and go out at a human pace. See the WhatsApp MCP server if that is closer to what you want.

The REST API above sends as you, immediately, and does not apply that review. It returns the chat's mode (confirm or auto) so your code can respect it, but it will not block you.

Limits worth knowing

  • Every unofficial route depends on WhatsApp Web's protocol. Pin versions and expect an update now and then.
  • Group admin actions, payments and calls are out of scope for most of these libraries.
  • Keep the token server side. A write token in a browser is a token anyone can read.

FAQ

Is there an official WhatsApp library for Python? No. Meta's Cloud API is HTTP, so you call it with requests or any client. The open-source libraries are community projects.

Can a Python bot use my personal WhatsApp number? Through neonize, browser automation or a gateway like WACrew, yes, as a linked device. The Cloud API needs a number registered for the API.

Will my number get banned? Answering people who write to you is low risk. Mass messaging and cold outreach are what trigger bans on unofficial clients.

Do I need Node.js to use WACrew from Python? Only on the server that runs the collector (Docker brings it). Your Python code just calls HTTP.