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.
Metadata
Release files for openwa-sdk 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| openwa_sdk-1.1.1.tar.gz | 6.8 kB | Without provenance | Details for openwa_sdk-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| openwa_sdk-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for openwa_sdk-1.1.1-py3-none-any.whl |
Total release size: 13.0 kB
Release files / openwa_sdk-1.1.1.tar.gz
| Download URL | openwa_sdk-1.1.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a38cb4e97e69437b4a10c1c52cb8c5cfe17da6243976a856c578b43ececc79ef
|
|
BLAKE2b-256 checksum How to use checksums |
2fabd2bcc207b8c186addd2c8491a412d953de551c8e1cd0f4005707e34d9278
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / openwa_sdk-1.1.1-py3-none-any.whl
| Download URL | openwa_sdk-1.1.1-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2748d4e6110535ea15947d7c82d6e2ea2987624d57871058ba1ab5e66392f64
|
|
BLAKE2b-256 checksum How to use checksums |
58bc10d7de36867072bb0477232ffd8d45ac7da22973ee31a48cb4969272e5e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for openwa-sdk 1.1.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.