Python client for WABridge - WhatsApp HTTP API Bridge
Project description
wabridge
Python client for WABridge - send WhatsApp messages from Python via a simple REST API bridge.
Prerequisites
1. Install and link WhatsApp (one-time setup):
npx wabridge
Scan the QR code with WhatsApp (Settings > Linked Devices > Link a Device). Auth is saved to ~/.wabridge/ — you only need to link once.
2. Start the API server:
npx wabridge start
Or on a custom port:
npx wabridge start 8080
Install
pip install wabridge
Quick Start
from wabridge import WABridge
wa = WABridge()
# Send to yourself
wa.send("Hello!")
# Send to a contact (phone number with country code)
wa.send("919876543210", "Hello!")
# Send to multiple contacts in parallel
wa.send([
("919876543210", "Alert 1"),
("919876543211", "Alert 2"),
("919876543212", "Alert 3"),
])
One function. Three ways to use it.
Configuration
# Default - connects to localhost:3000
wa = WABridge()
# Custom port
wa = WABridge(port=8080)
# Custom host and port (e.g. WABridge running on another machine)
wa = WABridge(host="192.168.1.100", port=4000)
# Custom timeout (default 30 seconds)
wa = WABridge(timeout=60.0)
Async Support
import asyncio
from wabridge import AsyncWABridge
async def main():
async with AsyncWABridge() as wa:
await wa.send("Hello!")
await wa.send("919876543210", "Hello!")
await wa.send([
("919876543210", "Alert 1"),
("919876543211", "Alert 2"),
])
asyncio.run(main())
Context Manager
# Sync
with WABridge() as wa:
wa.send("Hello!")
# Async
async with AsyncWABridge() as wa:
await wa.send("Hello!")
API Reference
WABridge(host="localhost", port=3000, timeout=30.0)
wa.send(...)
| Usage | Description | Returns |
|---|---|---|
wa.send("Hello!") |
Send to yourself | {"success": True, "to": "self"} |
wa.send("919876543210", "Hello!") |
Send to a phone number | {"success": True, "to": "919876543210"} |
wa.send([("91...", "msg"), ...]) |
Send to many in parallel | [{"success": True, "to": "91..."}, ...] |
Phone numbers must include the country code (e.g. 91 for India, 1 for US) followed by the number — digits only, no + or spaces.
Utility Methods
| Method | Description |
|---|---|
wa.status() |
Returns {"status": "open", "user": "91...@s.whatsapp.net"} |
wa.is_connected() |
Returns True if WhatsApp is connected |
wa.close() |
Close the HTTP client |
AsyncWABridge(host="localhost", port=3000, timeout=30.0)
Same methods as WABridge, but all are async. Supports async with context manager.
Exceptions
| Exception | When |
|---|---|
WABridgeError |
Base exception for all errors |
ConnectionError |
WhatsApp is not connected (server returned 500) |
ValidationError |
Invalid phone number or missing fields (server returned 400) |
from wabridge import WABridge, ConnectionError, ValidationError
wa = WABridge()
try:
wa.send("919876543210", "Hello!")
except ConnectionError:
print("WhatsApp is not connected. Run: npx wabridge start")
except ValidationError as e:
print(f"Bad request: {e.message}")
Use Cases
Trading alerts:
wa = WABridge()
wa.send("BUY NIFTY 24000 CE @ 150")
Server monitoring:
wa = WABridge()
if cpu_usage > 90:
wa.send("919876543210", f"CPU at {cpu_usage}%")
Broadcast to multiple numbers:
wa = WABridge()
numbers = ["919876543210", "919876543211", "919876543212"]
wa.send([(n, "Server maintenance at 10 PM") for n in numbers])
Cron job notifications:
wa = WABridge()
wa.send("Backup completed successfully")
How It Works
This package is a thin Python wrapper over the WABridge HTTP API. WABridge runs as a local Node.js server that connects to WhatsApp via the Baileys library. This Python client sends HTTP requests to that server using httpx.
Python App --> wabridge (Python) --> WABridge Server (Node.js) --> WhatsApp
Requirements
- Python >= 3.8
- WABridge server running (
npx wabridge start) - Node.js >= 20.0.0 (for the WABridge server)
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wabridge-0.1.0.tar.gz.
File metadata
- Download URL: wabridge-0.1.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7beb442d09b8fb35868e4d245ccf60bdc511e4db739e88c57ffa4114b23f4965
|
|
| MD5 |
c3c62daaa2124b05d187e0899914562c
|
|
| BLAKE2b-256 |
7ce4c66ab737dc98d6a541afb1bdd53e3ce2e13b4e05b78dba6c9bb84641ac72
|
File details
Details for the file wabridge-0.1.0-py3-none-any.whl.
File metadata
- Download URL: wabridge-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d77f244ea7e3642be22369e9223b0581a0ad787e61ff5dab6b5d2b165455eb4d
|
|
| MD5 |
02cbe57e9e05598851f74889e90c3942
|
|
| BLAKE2b-256 |
f516fc783bfbe6bc5798f2f3c933abe2c49aa8422c3cfbaf80b68b5fe2f3129c
|