Official Python SDK for OpenWA WhatsApp API Gateway
Project description
OpenWA Python SDK
The official, high-performance Python client library for the OpenWA-Python REST API Gateway.
Overview
The OpenWA Python SDK provides a seamless, developer-friendly interface to manage WhatsApp sessions, send text/media messages, register webhooks, and interact with WhatsApp groups natively in Python.
Built entirely around the OpenWA OpenAPI specification, this SDK abstracts away HTTP requests and JSON parsing, delivering a fully-typed and intuitive developer experience.
Key Features
- 🚀 Synchronous & Asynchronous: Ships with both blocking (
OpenWAClient) and non-blocking (AsyncOpenWAClient) implementations out of the box via HTTPX. - 🛡️ Fully Typed: Extensively utilizes Python type hints for unmatched IDE autocomplete and static type checking.
- ⚡ Zero Boilerplate: Connect directly to your self-hosted OpenWA API gateway without worrying about underlying request headers, authentication protocols, or JSON serializers.
- 📦 Lightweight: Minimal dependencies. Focuses exclusively on delivering data from the REST API to your application logic.
Installation
Install the library directly from PyPI using pip:
pip install openwa-sdk
Quick Start
Initialize the client with your self-hosted OpenWA Gateway Base URL and API Key.
1. Synchronous Usage
Ideal for standard scripts, background workers, or straightforward integrations.
from openwa import OpenWAClient
# Initialize the client
client = OpenWAClient(
base_url="http://localhost:2785",
api_key="your_secret_key"
)
# Create and start a new WhatsApp session
session = client.sessions.create("support_bot")
client.sessions.start(session["id"])
# Fetch the QR code for authentication
qr_data = client.sessions.qr(session["id"])
print(f"Scan this QR code in WhatsApp: {qr_data['qrCode']}")
# Send a text message to a user
client.messages.send_text(session["id"], {
"chatId": "1234567890@c.us",
"text": "Hello from the OpenWA Python SDK! 🐍"
})
# Mark a specific chat thread as unread
client.sessions.mark_chat_unread(session["id"], "1234567890@c.us")
2. Asynchronous Usage (Recommended for High-Concurrency)
Ideal for integration with FastAPI, aiohttp, or high-throughput bots.
import asyncio
from openwa import OpenWAClient
async def main():
# Obtain the async variant of the client
client = OpenWAClient(
base_url="http://localhost:2785",
api_key="your_secret_key"
).get_async_client()
# Send a message asynchronously
response = await client.messages.send_text("support_bot", {
"chatId": "1234567890@c.us",
"text": "Hello async world! ⚡"
})
print(f"Message sent! ID: {response['messageId']}")
asyncio.run(main())
API Resources Reference
The OpenWAClient grants access to all Gateway API namespaces via grouped resources:
| Resource | Namespace | Description |
|---|---|---|
client.sessions |
/api/sessions |
Create, list, start, stop, delete, and authenticate sessions. Also manage session statuses, QR codes, and chat states (mark_chat_unread). |
client.messages |
/api/sessions/{id}/messages |
Dispatch text, media, documents, and contacts. Retrieve message history. |
client.contacts |
/api/sessions/{id}/contacts |
Fetch and query contacts synced from the WhatsApp device. |
client.groups |
/api/sessions/{id}/groups |
Create new groups, manage participants, fetch group metadata, and alter group subjects/settings. |
client.webhooks |
/api/sessions/{id}/webhooks |
Register, update, and manage webhook subscriptions for real-time WhatsApp events. |
client.api_keys |
/api/auth/api-keys |
Manage API tokens and authorization. |
Note: Every resource method natively supports
awaitwhen accessed via theAsyncOpenWAClient.
Contributing
We welcome contributions! To set up the SDK for local development:
# Clone the repository
git clone https://github.com/bonheurNE07/OpenWA-Python.git
cd OpenWA-Python
# Install the SDK in editable mode with dev dependencies
pip install -e "sdk/python[dev]"
# Run tests
pytest test/unit/sdk-python/
Support
If you encounter any bugs, have feature requests, or need general assistance, please open an issue on the main GitHub repository.
License
This project is licensed under the MIT License - see the LICENSE file for more details.
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 openwa_sdk-1.1.1.tar.gz.
File metadata
- Download URL: openwa_sdk-1.1.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a38cb4e97e69437b4a10c1c52cb8c5cfe17da6243976a856c578b43ececc79ef
|
|
| MD5 |
28c7b12b9c059d5d1e037193e007481a
|
|
| BLAKE2b-256 |
2fabd2bcc207b8c186addd2c8491a412d953de551c8e1cd0f4005707e34d9278
|
File details
Details for the file openwa_sdk-1.1.1-py3-none-any.whl.
File metadata
- Download URL: openwa_sdk-1.1.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2748d4e6110535ea15947d7c82d6e2ea2987624d57871058ba1ab5e66392f64
|
|
| MD5 |
50a5a54755fcbd59141f2086f1a967e4
|
|
| BLAKE2b-256 |
58bc10d7de36867072bb0477232ffd8d45ac7da22973ee31a48cb4969272e5e6
|