Official Python SDK for Wapio — send WhatsApp messages and manage WhatsApp sessions.
Project description
wapio
Official Python SDK for Wapio. Send WhatsApp messages, manage WhatsApp sessions, contacts, groups, channels, and decrypt inbound media.
pip install wapio
Python 3.9+ is required.
Features
- Sync and async clients built on
httpx. - Text, image, video, document, group, and channel message helpers.
- Session lifecycle: create, list, update, delete, connect, disconnect, QR, status, and key rotation.
- Contact management: list, details, profile picture, block, and unblock.
- Group management: list, metadata, participants add/remove, and settings.
- Inbound encrypted media decrypt helper.
- Rate-limit metadata and request IDs on every response.
- Automatic idempotency keys for message sends.
Quickstart
from wapio import Wapio
wapio = Wapio(api_key="bps_sk_...")
result = wapio.send_text(to="+15551234567", text="Hello from Wapio")
print(result.data["msgId"])
Use a context manager when you want the HTTP client closed automatically:
with Wapio(api_key="bps_sk_...") as wapio:
wapio.send_text(to="+15551234567", text="Hi")
Async client
import asyncio
from wapio import AsyncWapio
async def main():
async with AsyncWapio(api_key="bps_sk_...") as wapio:
result = await wapio.send_text(to="+15551234567", text="Hi")
print(result.data["msgId"])
asyncio.run(main())
Authentication
| Token | Format | Use |
|---|---|---|
| Personal Access Token | bps_pat_... |
Create, update, delete, connect, disconnect, and rotate WhatsApp sessions. |
| Session key | bps_sk_... |
Send messages and read resources for one connected WhatsApp session. |
wapio = Wapio(
personal_access_token="bps_pat_...",
api_key="bps_sk_...",
)
Messages
wapio.send_text(to="+15551234567", text="Hi")
wapio.send_image(to="+15551234567", image_url="https://example.com/image.jpg", caption="Image")
wapio.send_video(to="+15551234567", video_url="https://example.com/video.mp4")
wapio.send_document(
to="+15551234567",
document_url="https://example.com/file.pdf",
file_name="file.pdf",
)
Pass your own idempotency key when you need retry deduplication across processes:
wapio.send_text(
to="+15551234567",
text="Order #42 shipped",
idempotency_key="order:42:shipped",
)
Channels
Use the WhatsApp Channel ID ending in @newsletter.
wapio.send_channel_message(
"120363428122592568@newsletter",
"This week's release is live",
)
Message lifecycle
info = wapio.get_message_info("bps_msg_...")
wapio.edit_message("bps_msg_...", "Corrected text")
wapio.delete_message("bps_msg_...")
Sessions
created = wapio.create_session(label="Support line")
session_id = created.data["session"]["session_id"]
raw_session_key = created.data["session_api_key"]["raw"]
sessions = wapio.list_sessions(status="connected", limit=50)
session = wapio.get_session(session_id)
wapio.update_session(session_id, label="Support EU")
wapio.get_session_qrcode(session_id)
wapio.get_session_status()
wapio.connect_session(session_id)
wapio.disconnect_session(session_id)
rotated = wapio.regenerate_api_key(session_id)
print(rotated.data["session_api_key"]["raw"])
wapio.delete_session(session_id)
Store session_api_key.raw when it is returned. It is shown once.
Contacts
wapio.get_contacts()
wapio.get_contact("+15551234567")
wapio.get_contact_profile_picture("+15551234567")
wapio.block_contact("+15551234567")
wapio.unblock_contact("+15551234567")
Groups
group = wapio.create_group(
subject="Customer updates",
participants=["15551234567@s.whatsapp.net"],
)
group_jid = group.data["group_jid"]
wapio.get_groups()
wapio.get_group_metadata(group_jid)
wapio.get_group_participants(group_jid)
wapio.add_group_participants(group_jid, ["15559876543@s.whatsapp.net"])
wapio.remove_group_participants(group_jid, ["15559876543@s.whatsapp.net"])
wapio.update_group_settings(group_jid, {"announce": True})
wapio.send_text(to=group_jid, text="Hello group")
Media
For outbound media, pass a public HTTPS URL to send_image, send_video, or send_document.
Use decrypt_media for inbound encrypted WhatsApp media payloads:
media = wapio.decrypt_media({
"mediaKey": "...",
"directPath": "...",
"url": "https://mmg.whatsapp.net/...",
"type": "image",
})
Utilities
wapio.get_user()
wapio.check_if_on_whatsapp("+15551234567")
Errors
SDK methods raise WapioAPIError for API errors and WapioConfigError for missing credentials before a request is sent.
try:
wapio.send_text(to="+15551234567", text="Hi")
except Exception as exc:
print(exc)
Project details
Release history Release notifications | RSS feed
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 wapio-0.2.0.tar.gz.
File metadata
- Download URL: wapio-0.2.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82630d0e386c8455ef7fd36c097c7735f7dc20cf4f39435bb18862e07dc2d9d9
|
|
| MD5 |
049c1188b481200f2e21bff725a15752
|
|
| BLAKE2b-256 |
af5d0e4bdb3901ded43384ca5d8b27e744e59347cb3f0564e80f6e6e9dadc468
|
File details
Details for the file wapio-0.2.0-py3-none-any.whl.
File metadata
- Download URL: wapio-0.2.0-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ce0cc9c512064bc516674262cfcb3d6bc8172109b7a337d661d7f525f2adc3c
|
|
| MD5 |
b7827c6bab7f82d23ceab4c724a9dc9b
|
|
| BLAKE2b-256 |
d0669e407be4b487c9d551a88bdc2f3ee93bf17c7b416011bd6945bdd5068b76
|