Skip to main content

Async Python client for the WhatsApp multi-device protocol

Project description

pywhats

CI PyPI version Python versions License

Async Python client for the WhatsApp multi-device protocol.

Status: pre-alpha (0.1.0) — the first public release. Implements QR pairing, connect, send/receive text, disconnect, app-state sync, media (send/receive images), history sync, read receipts, presence, and group messaging.

⚠️ Use at your own risk. This is an independent, unofficial client and may violate WhatsApp's Terms of Service — using it can get an account banned; prefer a dedicated number. The bundled Signal crypto (pywhats.signal.experimental) is clean-room and unaudited — see SECURITY.md.

Install

pip install pywhats

Requires Python 3.11+.

Quick start

import asyncio
from pywhats import Client

async def main():
    client = Client()

    @client.on("qr")
    async def on_qr(qr: str):
        print("Scan this QR in WhatsApp → Linked Devices:")
        print(qr)

    @client.on("message")
    async def on_message(msg):
        print(f"{msg.sender}: {msg.text}")
        if msg.text == "ping":
            # Event handlers run on the receive loop, so don't `await` a
            # client call that waits on a server reply (send, receipts,
            # group info) directly here — it would block the loop that has
            # to read that reply. Dispatch it as a task instead.
            asyncio.create_task(client.send_text(msg.chat, "pong"))

    await client.connect()
    await client.wait_closed()

asyncio.run(main())

Note: event handlers are dispatched on the connection's receive loop. Keep them quick, and never await a Client call that waits on a server response (send_text, send_image, mark_read, get_group_info, send_group_text, …) from inside a handler — schedule it with asyncio.create_task(...) so the receive loop stays free to read the reply.

Roadmap

  • 0.1.0 — QR pair, connect, send/receive text, disconnect, app-state sync, media (send/receive images), history sync, read receipts, presence, group messaging
  • 0.2.0+ — more media types (video/audio/document/sticker), message features (reactions/replies/edits), calls, newsletters, business

License

Apache License 2.0. See LICENSE.

This is an independent clean-room implementation of the WhatsApp multi-device protocol. It is not affiliated with or endorsed by WhatsApp LLC or Meta. Using unofficial clients may violate WhatsApp's Terms of Service and can get an account banned — use at your own risk, preferably with a dedicated number.

Acknowledgments

The protocol behavior implemented here was informed by public reverse-engineering writeups and by studying the documented behavior of the open-source whatsmeow (Go) and Baileys (TypeScript) projects. No code was copied from either; pywhats is an independent implementation.

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

pywhats-0.1.0.tar.gz (213.7 kB view details)

Uploaded Source

Built Distribution

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

pywhats-0.1.0-py3-none-any.whl (170.2 kB view details)

Uploaded Python 3

File details

Details for the file pywhats-0.1.0.tar.gz.

File metadata

  • Download URL: pywhats-0.1.0.tar.gz
  • Upload date:
  • Size: 213.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pywhats-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c65a397db93e6dbe471cfc820fb2bbb7fc504ea58f496615b0bc134193c71abd
MD5 26b6b6a490c1bc8b2ea1d8fc44925044
BLAKE2b-256 c93967ab33810bcb9a321ec78ca90f847fbf3e16260dc1d18f4e5a77ba671bd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywhats-0.1.0.tar.gz:

Publisher: release.yml on sanjay3290/pywhats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pywhats-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pywhats-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 170.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pywhats-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5bd33dbd64cff61121e138489218d9f87a42367f598ce95d70ce2b0268bf9d9e
MD5 f37cc6a557f82ba746887ee6e3aadd27
BLAKE2b-256 8f9bbd351cc5883246918b4aee8d2bc3d2d23476f1ea61acba5fef8e5b3ce714

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywhats-0.1.0-py3-none-any.whl:

Publisher: release.yml on sanjay3290/pywhats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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