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.0.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.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hey_pingr-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 a6264f7983254073a30b2ae7a34f39e24ccedef8fa46dd4117cc6af3747a9d8d
MD5 b45e1da52e4143cab6bfcd8fd8b46a6b
BLAKE2b-256 e6f2d6d45f70655e1e26b6de6ffc74cd60065f4f300db81c5cf827fdfe14f966

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hey_pingr-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f418b8e8e952bb0ddac91a2629eb23053db22f830b4c7c386c5337a63af7e75
MD5 d1e90d8c4cd934a56ce03d28dd02f7da
BLAKE2b-256 d95770f4930fdea3a9901cc1bed0017a2b2fea035d63fb6d096089be4b74683a

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