whagent
A small Python library for the WhatsApp Agent Platform API (https://api.whatsapp.com/agent/v1).
It covers every endpoint in version 1 of the developer manual — sending, long-poll receiving, read receipts, the typing indicator and media — and adds what you would otherwise write yourself: typed responses, offset tracking, retries with backoff, client-side rate limiting and local validation against the documented caps.
from whagent import Agent
agent = Agent("<ACCESS_TOKEN>")
@agent.on_text
def echo(ctx):
ctx.reply(f"You said: {ctx.text}")
agent.run()
Install
pip install whagent
Python 3.9+. The only runtime dependency is requests.
Documentation
https://elimeshi1.github.io/Whagent/ — built from docs/ with MkDocs Material.
| Getting started | Create an agent, get a token, run your first reply |
| How it works | Polling, offsets, identifiers — the model in six pieces |
| Questions and answers | Who it can message, what happens offline, running two agents |
| Sending messages | POST /messages — every type, captions, quotes |
| Receiving messages | GET /updates and offsets |
| Files and media | Upload, download, delete |
| Receipts and typing | POST /statuses |
| Agent | Handlers, Context, the run loop |
| Client | One method per endpoint |
| Models | Update, Message, Status, Media |
| Errors | Exception hierarchy, codes, retry policy |
| Rate limits | Per-method caps and the built-in limiter |
| Limits and formats | Length caps, sizes, accepted MIME types |
| Recipes | Persistence, slow work, shutdown, deployment |
| Testing | Testing an agent without touching the network |
Build the site locally with:
pip install -r docs/requirements.txt
mkdocs serve
At a glance
Two layers — use whichever fits.
Agent registers handlers and runs the loop for you:
@agent.on_text(r"^/help") # regex filter
def help_command(ctx):
ctx.reply("Send me a photo and I'll tell you how big it is.")
@agent.on_message("image")
def on_image(ctx):
data = ctx.download()
ctx.reply(f"{len(data)} bytes, thanks {ctx.profile_name or 'there'}!")
Client is one method per endpoint:
from whagent import Client
with Client(token) as client:
client.send_text("Hello!") # an agent has exactly one recipient
client.send_image(file="cat.jpg", caption="look at this")
update = client.get_updates(offset=1287, timeout=25)
Examples
examples/echo_bot.py— text, media and reactionsexamples/media_bot.py— download an attachment, send a file backexamples/raw_client.py— the loop without theAgentlayer
Tests
git clone https://github.com/Elimeshi1/Whagent.git
cd Whagent
pip install -U pip # editable installs need pip 21.3 or newer
pip install -e ".[dev]"
pytest
143 tests, no network: the HTTP session is faked, so they assert the exact requests the library builds against the payloads in the manual.
License
MIT
Metadata
Release files for whagent 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| whagent-0.1.0.tar.gz | 34.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| whagent-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 61.6 kB
Release files / whagent-0.1.0.tar.gz
| Download URL | whagent-0.1.0.tar.gz |
|---|---|
| Size | 34.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43bdde14d3eaba0995bde32e2f403ee9c95fc69435dd4f43c8aa988f98938e32
|
|
BLAKE2b-256 checksum How to use checksums |
e2d9c4185d73d50d5c025dee0f92851adfe4456b5cc777e80789f042db8a7776
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.
Transparency logRelease files / whagent-0.1.0-py3-none-any.whl
| Download URL | whagent-0.1.0-py3-none-any.whl |
|---|---|
| Size | 27.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9e309c19b573aa4a95de5752eb9a66f47e0871acfc9aebb0eb42c702406adfb
|
|
BLAKE2b-256 checksum How to use checksums |
136aa22e887c84b253d6be19625d4421bfe2c96b0c3016516a2caa655bf82191
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.
Transparency log