Send WhatsApp messages from Python using Playwright + WhatsApp Web. No API keys, no Twilio, no Meta Business account — just your regular WhatsApp.
pip install -r requirements.txt
playwright install chromiumcp .env.example .envEdit .env and set your phone number (with country code):
WHATSAPP_PHONE=+91-9876543210
Run the test message command:
python whatsapp.py "Hello from whatsapp-sender! 🎉"A visible Chromium browser window will open with WhatsApp Web. Scan the QR
code with your phone (WhatsApp → Linked Devices → Link a Device). Once
logged in, the session is saved locally to .wa_session/ and you won't
need to scan again.
Every subsequent send runs fully headlessly — no browser window, no interaction needed.
If you're using an AI agent (Cursor, Claude, etc.), paste this prompt to get set up automatically:
Set up the whatsapp-sender project and send a test message. Install dependencies from requirements.txt, install the Playwright Chromium browser, create a .env file from .env.example (ask me for my phone number with country code), and run
python whatsapp.py "Hello from whatsapp-sender!"— this will open a browser for WhatsApp Web QR login. Confirm once the test message is delivered.
# Send to the number in .env
python whatsapp.py "Hello from the terminal"
# Send to a specific number
python whatsapp.py "+919876543210" "Hello!"import asyncio
from whatsapp import send_whatsapp
asyncio.run(send_whatsapp("+91-9876543210", "Hello from Python!"))from whatsapp import WhatsAppSender
async def main():
async with WhatsAppSender(phone="+91-9876543210") as wa:
await wa.send("First message")
await wa.send("Second message")- First run: Opens a visible browser → scan QR → session saved to
.wa_session/ - Subsequent runs: Headless, fully automatic
- Session expired? If WhatsApp Web logs you out (phone offline too long, manual unlink, etc.), delete
.wa_logged_inand.wa_session/and run again to re-scan:
rm -rf .wa_session .wa_logged_in
python whatsapp.py "Re-authenticating..."WhatsApp Web supports lightweight markdown:
| Syntax | Result |
|---|---|
*text* |
bold |
_text_ |
italic |
~text~ |
|
```text``` |
monospace |
| File | Description |
|---|---|
whatsapp.py |
Core module — WhatsAppSender class + send_whatsapp() helper |
example.py |
Demo scripts (simple, formatted, alert, batch) |
PROMPT.md |
AI agent prompt + detailed explanation of how it works |
.env.example |
Phone number config template |