Metadata-Version: 2.4
Name: pyaileys
Version: 0.1.2
Summary: Async WhatsApp Web (Multi-Device) protocol client in pure Python, inspired by Baileys.
Project-URL: Homepage, https://github.com/atiti/pyaileys
Project-URL: Repository, https://github.com/atiti/pyaileys
Project-URL: Issues, https://github.com/atiti/pyaileys/issues
Project-URL: Changelog, https://github.com/atiti/pyaileys/blob/main/CHANGELOG.md
Project-URL: Security, https://github.com/atiti/pyaileys/security
Author: Attila Sukosd
License: MIT License
        
        Copyright (c) 2026 Attila Sukosd
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: asyncio,baileys,protocol,websocket,whatsapp
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: cryptography>=42.0.0
Requires-Dist: protobuf>=4.25.0
Requires-Dist: websockets>=12.0
Provides-Extra: dev
Requires-Dist: build>=1.2.1; extra == 'dev'
Requires-Dist: mypy>=1.10.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: ruff>=0.5.0; extra == 'dev'
Requires-Dist: twine>=5.1.1; extra == 'dev'
Requires-Dist: types-protobuf>=4.25.0.20240417; extra == 'dev'
Provides-Extra: qrcode
Requires-Dist: qrcode>=7.4.2; extra == 'qrcode'
Description-Content-Type: text/markdown

# pyaileys

[![CI](https://github.com/atiti/pyaileys/actions/workflows/ci.yml/badge.svg)](https://github.com/atiti/pyaileys/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/pyaileys.svg)](https://pypi.org/project/pyaileys/)
[![Python Versions](https://img.shields.io/pypi/pyversions/pyaileys.svg)](https://pypi.org/project/pyaileys/)
[![License](https://img.shields.io/pypi/l/pyaileys.svg)](LICENSE)
[![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-261230.svg)](https://github.com/astral-sh/ruff)

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)
- `asyncio` API 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 + `notify` push 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

```bash
pip install pyaileys
```

Optional (pretty QR output in terminal + SVG QR file):

```bash
pip install "pyaileys[qrcode]"
```

## Quickstart (Pair + Connect)

```python
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 (`notify` push name)
- Explicit queries (e.g. profile picture URL, about/status)

This library exposes a small convenience layer:

```python
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, and `None` if unavailable.

## Examples

Kitchen sink (interactive):

```bash
python examples/demo_app.py --auth ./auth --log-nodes
```

Simple CLI (decrypt + store + send text/media):

```bash
python examples/simple_cli.py --auth ./auth
```

QR-only helper (writes `qr.svg` into the auth dir if `qrcode` extra is installed):

```bash
python examples/login_qr.py
```

## Development

```bash
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.toml` and `src/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:

```bash
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`:

```bash
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`.
