Quickstart: Low-Level WAClient#
Use this guide if you want direct control over socket lifecycle and events.
Prerequisites#
Python 3.11+
WhatsApp account on phone
Internet connection
Install#
pip install waton
For local development from repository root:
pip install -e .[dev]
maturin develop
Minimal client example#
import asyncio
from waton.client.client import WAClient
from waton.infra.storage_sqlite import SQLiteStorage
async def main() -> None:
storage = SQLiteStorage("waton_low_level.db")
client = WAClient(storage)
async def on_connection_update(event):
print(f"[connection] status={event.status}")
if event.qr:
print("[connection] qr received")
async def on_message(node):
print(f"[node] tag={node.tag} attrs={node.attrs}")
async def on_event(event):
print(f"[event] type={event.get('type')}")
client.on_connection_update = on_connection_update
client.on_message = on_message
client.on_event = on_event
await client.connect()
print("Connected. Running ping...")
pong = await client.send_ping()
print(f"Ping OK: {pong.attrs}")
await asyncio.sleep(10)
await client.disconnect()
await storage.close()
if __name__ == "__main__":
asyncio.run(main())
Run#
python my_low_level.py
Expected output#
[connection] status=connectingQR event appears and can be scanned
[connection] status=openPing OK: ...
When to use WAClient directly#
You need normalized event stream handling (
client.on_event).You need custom lifecycle/reconnect behavior.
You are building your own abstraction layer.
Next steps#
Connection state details: Connection Lifecycle
Event catalog and payload shape: Event Model
Full client/reference pages: Client API Reference