Python SDK & API Guide
How to Send WhatsApp Messages with Python.
Integrate Wapix WhatsApp OTP and notification services directly into Python backends, Django platforms, and FastAPI microservices.
Step 1: Install Requirements
pip install requests python-dotenv
Step 2: Dispatch WhatsApp OTP with Requests
import os
import requests
from dotenv import load_dotenv
load_dotenv()
WAPIX_API_KEY = os.getenv("WAPIX_API_KEY")
def send_whatsapp_otp(phone_number: str, otp_code: str) -> dict:
url = "https://api.wapix.sbs/api/v1/send/otp"
payload = {
"service": "otp",
"whatsaap_number": phone_number,
"otp": otp_code,
"text": "Your one-time login passcode is:",
"api_key": WAPIX_API_KEY
}
response = requests.post(url, json=payload, timeout=10)
data = response.json()
if data.get("success"):
print("OTP delivered successfully!")
else:
print("Delivery failed:", data.get("message"))
return data
# Example Usage
if __name__ == "__main__":
send_whatsapp_otp("919876543210", "492019")Step 3: Webhook Consumer with FastAPI
from fastapi import FastAPI, Request
app = FastAPI()
@app.post("/api/webhook")
async def receive_webhook(request: Request):
payload = await request.json()
event = payload.get("event")
data = payload.get("data", {})
if event == "message":
sender = data.get("from", "").replace("@c.us", "")
body = data.get("body", "")
print(f"Message from {sender}: {body}")
return {"status": "ok"}Looking for error handling definitions?Explore Error Codes Reference →