Skip to content

viveksinha/whatsapp-sender

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WhatsApp Sender

Send WhatsApp messages from Python using Playwright + WhatsApp Web. No API keys, no Twilio, no Meta Business account — just your regular WhatsApp.

Getting started

1. Install dependencies

pip install -r requirements.txt
playwright install chromium

2. Configure your phone number

cp .env.example .env

Edit .env and set your phone number (with country code):

WHATSAPP_PHONE=+91-9876543210

3. Authenticate with WhatsApp (one-time)

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.

4. You're done

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.

Usage

CLI

# Send to the number in .env
python whatsapp.py "Hello from the terminal"

# Send to a specific number
python whatsapp.py "+919876543210" "Hello!"

Python

import asyncio
from whatsapp import send_whatsapp

asyncio.run(send_whatsapp("+91-9876543210", "Hello from Python!"))

As a class (for multiple messages)

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")

Session management

  • 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_in and .wa_session/ and run again to re-scan:
rm -rf .wa_session .wa_logged_in
python whatsapp.py "Re-authenticating..."

Message formatting

WhatsApp Web supports lightweight markdown:

Syntax Result
*text* bold
_text_ italic
~text~ strikethrough
```text``` monospace

Files

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

About

Send WhatsApp messages from Python using Playwright + WhatsApp Web automation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages