Async WhatsApp Web (Multi-Device) protocol client in pure Python, inspired by Baileys.
Project description
pyaileys
Async WhatsApp Web (Multi-Device) protocol client in pure Python, inspired by Baileys.
What This Is
- WebSocket protocol client (no browser automation)
- QR pairing + multi-device session persistence (Baileys-like auth folder)
asyncioAPI for receiving stanzas/events and sending messages- Minimal runtime deps:
websockets,protobuf,cryptography
Status
This is an early-stage protocol client.
What works today:
- MD session login + QR pairing
- Basic 1:1 Signal E2E (
pkmsg/msg) decrypt/encrypt - Basic text send (with multi-device fanout)
- Typing/recording indications (
chatstate) - Media send (image, PTT voice note, documents, static location, contacts)
- Media download/decrypt (image, audio/PTT, documents)
- History Sync ingestion into an in-memory store
- Best-effort contact/profile metadata (names from history sync +
notifypush names, profile picture URL, status/about)
Limitations (Important)
- Group E2E (
skmsg) / Sender Keys: not implemented - Media support is partial: no video/stickers yet, and no automatic thumbnails/duration/waveform
- App-state sync + rich chat/contact model: minimal (demo store; contact names/profile are best-effort)
- API stability: no guarantees yet (pre-1.0)
Legal / Safety
This project is not affiliated with WhatsApp/Meta. Using unofficial clients may violate WhatsApp Terms of Service. You are responsible for compliance and for preventing abuse (spam/automation).
Installation
pip install pyaileys
Optional (pretty QR output in terminal + SVG QR file):
pip install "pyaileys[qrcode]"
Quickstart (Pair + Connect)
import asyncio
from pyaileys import WhatsAppClient
async def main() -> None:
client, auth_state = await WhatsAppClient.from_auth_folder("./auth")
async def on_update(update) -> None:
# update is `pyaileys.socket.ConnectionUpdate`
if update.qr:
print("QR string:", update.qr)
if update.connection:
print("connection:", update.connection)
async def on_creds_update(_creds) -> None:
await auth_state.save_creds()
client.on("connection.update", on_update)
client.on("creds.update", on_creds_update)
await client.connect()
await auth_state.save_creds()
# keep the process alive
await asyncio.Event().wait()
asyncio.run(main())
Contacts & Profiles (Best-Effort)
WhatsApp Web does not provide a simple "address book" API. In practice, name/profile info comes from multiple places:
- History sync conversations (
displayName/name/username) - Incoming message stanzas (
notifypush name) - Explicit queries (e.g. profile picture URL, about/status)
This library exposes a small convenience layer:
dn = client.get_display_name("12345@s.whatsapp.net")
contact = client.get_contact("12345@s.whatsapp.net")
pic = await client.profile_picture_url("12345@s.whatsapp.net", picture_type="preview")
statuses = await client.fetch_status("12345@s.whatsapp.net")
Notes:
get_display_name()prefers a "saved name" (history sync) and falls back to push name (notify).fetch_status()may return""if the status is hidden/blocked, andNoneif unavailable.
Examples
Kitchen sink (interactive):
python examples/demo_app.py --auth ./auth --log-nodes
Simple CLI (decrypt + store + send text/media):
python examples/simple_cli.py --auth ./auth
QR-only helper (writes qr.svg into the auth dir if qrcode extra is installed):
python examples/login_qr.py
Development
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
ruff check .
ruff format .
mypy src/pyaileys
pytest -q
Releasing to PyPI (Trusted Publishing)
This repo includes a GitHub Actions workflow (.github/workflows/release.yml) that publishes to PyPI when you push a
tag like v0.1.0.
- Bump versions in
pyproject.tomlandsrc/pyaileys/__init__.py - Tag and push:
git tag vX.Y.Z && git push --tags
Regenerating Generated Files
wabinary token tables are generated from a Baileys checkout:
git clone https://github.com/WhiskeySockets/Baileys.git /path/to/Baileys
python3 tools/gen_wabinary_constants.py --baileys /path/to/Baileys
proto/WAProto.proto is vendored from Baileys and patched to satisfy protoc:
python3 tools/patch_waproto_for_protoc.py
protoc -Iproto --python_out=src/pyaileys/proto proto/WAProto.proto
Credits
- Inspired by the Baileys TypeScript library (MIT): https://github.com/WhiskeySockets/Baileys
Contributing
See CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md.
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
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 pyaileys-0.1.2.tar.gz.
File metadata
- Download URL: pyaileys-0.1.2.tar.gz
- Upload date:
- Size: 199.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff7a6d23604d6275f33bff12163d2f5d010ec2a2280c3c152049b583fbf0a108
|
|
| MD5 |
e236fd628b0491c4e5710c3ccbd79fa8
|
|
| BLAKE2b-256 |
e6fb93b5361664479f9b6113d5b8bbc71fd90f3bcc13d3b0c38d0fb3fa6e0eab
|
Provenance
The following attestation bundles were made for pyaileys-0.1.2.tar.gz:
Publisher:
release.yml on atiti/pyaileys
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyaileys-0.1.2.tar.gz -
Subject digest:
ff7a6d23604d6275f33bff12163d2f5d010ec2a2280c3c152049b583fbf0a108 - Sigstore transparency entry: 956821939
- Sigstore integration time:
-
Permalink:
atiti/pyaileys@836a9c342d15a3170465bac6d010a6bee933c9e7 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/atiti
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@836a9c342d15a3170465bac6d010a6bee933c9e7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyaileys-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pyaileys-0.1.2-py3-none-any.whl
- Upload date:
- Size: 162.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec0549b8bc77a2b7bbbd190e449deaaebf09ca1a3484e904c42ee4a0ac30dc63
|
|
| MD5 |
f1699c8ff93f22a04780247866ac115f
|
|
| BLAKE2b-256 |
f6d82b9f6e4955ff4005a5a6c8678916463a0b64c4ef663ce7a97e7542027ed7
|
Provenance
The following attestation bundles were made for pyaileys-0.1.2-py3-none-any.whl:
Publisher:
release.yml on atiti/pyaileys
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyaileys-0.1.2-py3-none-any.whl -
Subject digest:
ec0549b8bc77a2b7bbbd190e449deaaebf09ca1a3484e904c42ee4a0ac30dc63 - Sigstore transparency entry: 956821955
- Sigstore integration time:
-
Permalink:
atiti/pyaileys@836a9c342d15a3170465bac6d010a6bee933c9e7 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/atiti
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@836a9c342d15a3170465bac6d010a6bee933c9e7 -
Trigger Event:
push
-
Statement type: