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.1.tar.gz (217.3 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.1-py3-none-any.whl (171.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pywhats-0.1.1.tar.gz
  • Upload date:
  • Size: 217.3 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.1.tar.gz
Algorithm Hash digest
SHA256 a14ef24a955b109d99b9a90e67f5eb21eaaa36343fe26f0c34d41e635068988b
MD5 a0d208a8ca40f8ea06763ce61f28ee88
BLAKE2b-256 525b24be83bd0b6cb61a6c6a9192f39f590bce3a4315d4db9499fe7570381f48

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywhats-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: pywhats-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 171.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d286e065dce37ac4305a1cb3984cf418a16c3679bf00b107492a1b458d630ad
MD5 ce4602bd2d383d68bd293925f54c7468
BLAKE2b-256 27bd990ac313c9fecadd57d41d1085dbc8dd4bc8c7ff4e652acb426fa6a18418

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywhats-0.1.1-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