Skip to main content

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

Metadata

Release files for whatsapp-rpc 0.0.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for whatsapp-rpc 0.0.15
File Size Uploaded
whatsapp_rpc-0.0.15.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for whatsapp-rpc 0.0.15
File Interpreter ABI Platform
whatsapp_rpc-0.0.15-py3-none-any.whl Python 3 none any Details

Total release size: 17.2 kB

Release files / whatsapp_rpc-0.0.15.tar.gz

Download URL whatsapp_rpc-0.0.15.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dbae19e021e44c0cbfd47185651acea86ba49d4c82f80c29c326e8fb16259469
BLAKE2b-256 checksum
How to use checksums
850abb99edcd699ea4ec21a4ca3f4f9d3d49cbd3fd09512a3c81895d16755c3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / whatsapp_rpc-0.0.15-py3-none-any.whl

Download URL whatsapp_rpc-0.0.15-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9cd1420bb104a3e5e008a55d3edee7db700e05700d4e04bd88c80669708c9d56
BLAKE2b-256 checksum
How to use checksums
309bba7cc1b5fdd33dfbe22287ea0fad968c5dcb773252c04010c1927f172a02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.0.15 This release

2 release files

0.0.14

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.7

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page