Skip to main content

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)

    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

License

MIT

Project details


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.10.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whatsapp_rpc-0.0.10-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file whatsapp_rpc-0.0.10.tar.gz.

File metadata

  • Download URL: whatsapp_rpc-0.0.10.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for whatsapp_rpc-0.0.10.tar.gz
Algorithm Hash digest
SHA256 b74ff5d8f1a2dde93a20ab5b453bbfade6fda47ccb4961690a24ef47c8c91e17
MD5 918421ffa38624d778c3ef96d485e9b7
BLAKE2b-256 1468fa0e0df03e93982ef203eab9bf349d0724142c6146727f5e0b0c9bd51e03

See more details on using hashes here.

File details

Details for the file whatsapp_rpc-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: whatsapp_rpc-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for whatsapp_rpc-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 ecf7c6ad081b760ac15db53c6cb0026a0709b0256cdc8e5674a5b884b73f7c9d
MD5 1f31114ba3bcd465610c3899d32b406b
BLAKE2b-256 a2b147bfbc7070711b6f27314fa8c3aa1de4d411811aca139480807e0b5a1778

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page