Python async client for WhatsApp RPC WebSocket API
Project description
WhatsApp RPC - Python Client
Async Python client for the WhatsApp RPC WebSocket API.
Installation
pip install whatsapp-rpc
Requires the WhatsApp RPC server running separately:
npm install -g whatsapp-rpc
npx whatsapp-rpc start
Usage
import asyncio
from whatsapp_rpc import WhatsAppRPCClient
async def main():
client = WhatsAppRPCClient("ws://localhost:9400/ws/rpc")
await client.connect()
# Check status
status = await client.status()
print(status)
# Send a text message
await client.send(phone="1234567890", type="text", message="Hello!")
# Send an image
await client.send(
phone="1234567890",
type="image",
media_data={
"data": "<base64>",
"mime_type": "image/jpeg",
"caption": "Check this out!"
}
)
# List groups
groups = await client.groups()
# Get chat history
history = await client.chat_history(phone="1234567890", limit=50)
# List subscribed channels
channels = await client.newsletters()
# Get channel stats
stats = await client.newsletter_stats(jid="123456789@newsletter", count=20)
await client.close()
asyncio.run(main())
Events
async def main():
client = WhatsAppRPCClient("ws://localhost:9400/ws/rpc")
def on_event(event):
if event["method"] == "event.message_received":
print(f"New message: {event['params']['text']}")
client.event_callback = on_event
await client.connect()
# Keep running to receive events
await asyncio.sleep(3600)
await client.close()
API Methods
| Method | Description |
|---|---|
status() |
Get connection status |
start() / stop() / restart() |
Control WhatsApp service |
qr() |
Get QR code for pairing |
send(**kwargs) |
Send message (text, image, video, audio, document, location, contact) |
media(message_id) |
Download media from message |
groups() |
List all groups |
group_info(group_id) |
Get group details |
contacts(query) |
List contacts |
contact_check(phones) |
Check WhatsApp registration |
chat_history(**kwargs) |
Get message history |
typing(jid, state) |
Send typing indicator |
presence(status) |
Set online/offline |
mark_read(message_ids, chat_jid) |
Mark messages as read |
rate_limit_get() / rate_limit_set(**config) |
Rate limiting config |
newsletters(refresh) |
List subscribed channels |
newsletter_info(jid, invite, refresh) |
Get channel details |
newsletter_create(name, description, picture) |
Create a channel |
newsletter_follow(jid) |
Subscribe to a channel |
newsletter_unfollow(jid) |
Unsubscribe from a channel |
newsletter_mute(jid, mute) |
Mute/unmute a channel |
newsletter_messages(jid, count, before) |
Get channel messages |
newsletter_send(group_id, type, message, media_data) |
Send to channel (admin only) |
newsletter_mark_viewed(jid, server_ids) |
Mark messages as viewed |
newsletter_react(jid, server_id, reaction) |
React to a channel message |
newsletter_live_updates(jid) |
Subscribe to live updates |
newsletter_stats(jid, invite, count) |
Get channel statistics |
License
MIT
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
whatsapp_rpc-0.0.11.tar.gz
(9.1 kB
view details)
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 whatsapp_rpc-0.0.11.tar.gz.
File metadata
- Download URL: whatsapp_rpc-0.0.11.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
070b18f7cfa7271954b5d9322f37d35073efd58ef1b89f2a9f047b6cc8c8d68e
|
|
| MD5 |
b6ec3d6b723b527d0ffc0f30d64c45fc
|
|
| BLAKE2b-256 |
1ecf442cf2dd52119e89517f3874ae0ad284eb40879bd23dbb56c64d721477ae
|
File details
Details for the file whatsapp_rpc-0.0.11-py3-none-any.whl.
File metadata
- Download URL: whatsapp_rpc-0.0.11-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4a8d4dacb2f1f8e9e9ad9c3548f261c2337547943417449480610d6cd0dff4f
|
|
| MD5 |
58e11c32ed9e660241d3f51162ac548c
|
|
| BLAKE2b-256 |
86214d381851403ffcc7a886474c2e1facf7f0b3a221872c50e07f952f4a8d58
|