Skip to main content

Official Python SDK for PingBus Notification Gateway

Project description

PingBus Python SDK (pingbus-python)

An asynchronous, type-safe Python SDK for the PingBus Notification Gateway. Built on httpx and pydantic for high performance and robust data validation.

📦 Installation

pip install httpx pydantic

🚀 Quick Start

Basic Usage

import asyncio
from pingbus import PingBusClient

async def main():
    # Automatically picks up PINGBUS_API_KEY and PINGBUS_BASE_URL from env
    client = PingBusClient()

    # Send a WhatsApp Message
    await client.whatsapp.send_message(
        instance_id="inst_123",
        chat_id="1234567890@c.us",
        message="Hello from Python!"
    )

    # Send an Email
    await client.email.send(
        to="user@example.com",
        subject="Welcome",
        body="<h1>Welcome!</h1>",
        options={"isHtml": True}
    )

asyncio.run(main())

Advanced Push Notifications

from pingbus.models import PushTarget

# Send to a specific User ID
await client.push.send(
    target=PushTarget(type="user", userId="user_456"),
    notification={"title": "Alert", "body": "Critical Update"}
)

Unified Orchestration

Trigger notifications across multiple channels simultaneously or via a waterfall fallback system using a single, idempotent API call.

await client.dispatch.trigger({
    "idempotencyKey": "unique-uuid-v4",
    "event": "order_shipped",
    "targets": {
        "whatsapp": { "instanceId": "wa_123", "chatId": "1234567890@c.us" },
        "sms": { "to": "+19876543210" }
    },
    "content": {
        "title": "Order Shipped!",
        "body": "Hi {{name}}, your order #{{orderId}} is on the way."
    },
    "variables": { "name": "Alice", "orderId": "ORD-777" },
    "strategy": "waterfall",
    "config": { "waterfallTimeoutMs": 300000 }
})

# Check dispatch status
status = await client.dispatch.get_status("unique-uuid-v4")

🔑 Configuration Reference

The client supports automatic environment detection.

Option Env Variable Default
api_key PINGBUS_API_KEY Required
base_url PINGBUS_BASE_URL https://api.pingbus.com
timeout PINGBUS_TIMEOUT 30.0
client = PingBusClient(api_key="pk_...", timeout=10.0)

⚡ Key Features

  • Async/Await Native: Uses httpx.AsyncClient for non-blocking concurrent requests and connection pooling.
  • Pydantic Models: All request and response data is validated using Pydantic, providing full IDE autocompletion and type safety.
  • Automatic Retries: Implements the normative PingBus retry strategy (Exponential Backoff + Jitter) to handle rate limits (429) and server errors (503).

🛡️ Webhook Security

Verify that incoming HTTP requests genuinely originated from PingBus using HMAC-SHA256:

is_valid = PingBusClient.verify_signature(
    body=request.body, 
    signature=request.headers["X-PingBus-Signature"], 
    api_key="your_api_key"
)

📄 License

MIT © PingBus 2026

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pingbus-0.6.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pingbus-0.6.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file pingbus-0.6.0.tar.gz.

File metadata

  • Download URL: pingbus-0.6.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pingbus-0.6.0.tar.gz
Algorithm Hash digest
SHA256 0879f478e9d385ae353e29bc873fbab7a2ef47561fd63356f59e560bfc6ac894
MD5 816922a506c9c74828df902c7430f746
BLAKE2b-256 f87b7fa8f219476d207cda72f6874d295ccb113df024d1cea938e974f3e7b3f9

See more details on using hashes here.

File details

Details for the file pingbus-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: pingbus-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pingbus-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 268bf5f9e3f1d0d3e5b3e422e104fedf9bdbf9bc5ba70e2bb5c8fa4582d24582
MD5 f8c1976dc926c9a90c3b9c44040ca301
BLAKE2b-256 2955c5ef0d13208f17d9a8500956f0ebb15a920121352017f18435e64aefb472

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page