Skip to main content

Official Python SDK for the Pingr WhatsApp messaging API

Project description

pingr

Official Python SDK for the Pingr WhatsApp messaging API.

Installation

pip install hey-pingr

For async support (uses httpx):

pip install hey-pingr[async]

Quick start

import pingr

client = pingr.Pingr("pk_live_your_key_here")

result = client.messages.send(
    to="919876543210",      # digits only, with country code
    message="Your OTP is 482910. Valid for 10 minutes.",
)

print(result["message_id"])           # msg_abc123
print(result["rate_limit_remaining"]) # 499

Async usage

import asyncio
import pingr

async def main():
    async with pingr.AsyncPingr("pk_live_your_key_here") as client:
        result = await client.messages.send(
            to="919876543210",
            message="Your OTP is 482910",
        )
        print(result["message_id"])

asyncio.run(main())

Verifying webhooks

from flask import Flask, request
from pingr import verify_webhook, PingrWebhookError
import os

app = Flask(__name__)

@app.route("/webhook", methods=["POST"])
def webhook():
    try:
        payload = verify_webhook(
            request.get_data(),
            request.headers["x-pingr-signature"],
            os.environ["PINGR_WEBHOOK_SECRET"],
        )
        print(payload["event"], payload["session_id"])
        return "", 200
    except PingrWebhookError as e:
        print("Invalid webhook:", e)
        return "", 400

Error handling

from pingr import Pingr, PingrRateLimitError, PingrAuthError, PingrError

client = Pingr("pk_live_...")

try:
    client.messages.send(to="919...", message="Hello")
except PingrRateLimitError as e:
    print(f"Rate limited. Retry in {e.retry_after}s")
except PingrAuthError:
    print("Invalid API key")
except PingrError as e:
    print(f"Error {e.code}: {e.message}")

Test mode

Use a pk_test_ key to exercise the API without sending real messages. The response is identical to live mode — ideal for unit tests and CI.

API reference

Pingr(api_key, *, base_url=..., timeout=15.0)

client.messages.send(*, to, message, session_id=None)

Param Type Required Description
to str Recipient phone — digits + country code
message str Text to send
session_id str Specific session (auto-picks connected if omitted)

Returns a dict with: success, message_id, to, session_id, rate_limit_remaining.

verify_webhook(raw_body, signature, secret, *, check_timestamp=True)

Verifies x-pingr-signature and returns the parsed payload dict.
Raises PingrWebhookError on failure.

License

MIT

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

hey_pingr-0.1.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

hey_pingr-0.1.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file hey_pingr-0.1.1.tar.gz.

File metadata

  • Download URL: hey_pingr-0.1.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hey_pingr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1e2539d04a165d9c98e40efa71f2a7e0123f7cb1364fef423c3a5561febbcfd0
MD5 29a6e6ab1994ba4510584187c2e46e90
BLAKE2b-256 4951c1a71dcfcc825f098ec205d51c04f589207a843ab86d0ca3467243ab64c4

See more details on using hashes here.

File details

Details for the file hey_pingr-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: hey_pingr-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hey_pingr-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a53cf292680e177edfce3e980c762c642154155afe4489885fd41400e3a7704
MD5 cdef0cc15ea807ae1445c24f8366fd82
BLAKE2b-256 035d38078168cfaa8bf6d34b85864fc83463da6cb384324acf645829ff714022

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