Skip to main content

HookSniff API

Project description

HookSniff Python SDK

PyPI version License: MIT

Official Python client for the HookSniff webhook delivery service.

Installation

pip install hooksniff

Or install from source:

cd sdks/python
pip install -e .

Quick Start

from hooksniff import HookSniffClient

# Initialize client
client = HookSniffClient(api_key="hr_live_your_api_key_here")

# Create a webhook endpoint
endpoint = client.endpoints.create(
    url="https://myapp.com/webhook",
    description="Order notifications",
)
print(f"Endpoint created: {endpoint.id}")

# Send a webhook
delivery = client.webhooks.send(
    endpoint_id=endpoint.id,
    event="order.created",
    data={"order_id": "12345", "amount": 99.99},
)
print(f"Delivery queued: {delivery.id}, status: {delivery.status}")

# Check delivery status
status = client.webhooks.get(delivery.id)
print(f"Status: {status.status}, attempts: {status.attempt_count}")

# List deliveries
deliveries = client.webhooks.list(status="failed", page=1)
for d in deliveries.deliveries:
    print(f"  {d.id}: {d.status}")

# Replay a failed delivery
replayed = client.webhooks.replay(delivery.id)
print(f"Replay queued: {replayed.id}")

Batch Webhooks

Send multiple webhooks in a single request (max 100):

results = client.webhooks.batch([
    {
        "endpoint_id": "ep_1",
        "event": "order.created",
        "data": {"order_id": "12345"},
    },
    {
        "endpoint_id": "ep_2",
        "event": "payment.completed",
        "data": {"payment_id": "pay_67890"},
    },
])

print(f"Delivered: {len(results.deliveries)}")
print(f"Errors: {len(results.errors)}")
for err in results.errors:
    print(f"  Item {err['index']}: {err['error']}")

Retry Policy

Configure custom retry behavior when creating endpoints:

from hooksniff import HookSniffClient
from hooksniff.models import RetryPolicy

client = HookSniffClient(api_key="hr_live_...")

endpoint = client.endpoints.create(
    url="https://myapp.com/webhook",
    description="Critical notifications",
    retry_policy=RetryPolicy(
        max_attempts=5,
        backoff="exponential",
        initial_delay_secs=10,
        max_delay_secs=3600,
    ),
)

Delivery Attempts

Inspect individual delivery attempts:

attempts = client.webhooks.attempts(delivery.id)
for attempt in attempts:
    print(f"  Attempt {attempt.attempt_number}: status={attempt.status_code}, "
          f"duration={attempt.duration_ms}ms")
    if attempt.error_message:
        print(f"    Error: {attempt.error_message}")

Export Logs

Export webhook logs as JSON or CSV:

# JSON export
logs = client.webhooks.export(format="json", status="failed")

# CSV export
csv_data = client.webhooks.export(format="csv", date_from="2024-01-01")
with open("webhooks.csv", "w") as f:
    f.write(csv_data)

Signature Verification

Verify incoming webhook signatures in your handler:

from hooksniff import verify_signature

# In your webhook handler
def handle_webhook(request):
    payload = request.body.decode("utf-8")
    signature = request.headers.get("X-HookSniff-Signature", "")
    secret = "whsec_your_endpoint_signing_secret"

    if not verify_signature(payload, signature, secret):
        return {"error": "Invalid signature"}, 401

    # Process the webhook
    data = json.loads(payload)
    print(f"Received event: {data['event']}")
    return {"received": True}, 200

Error Handling

from hooksniff import (
    HookSniffClient,
    AuthenticationError,
    NotFoundError,
    RateLimitError,
    ValidationError,
    PayloadTooLargeError,
)

client = HookSniffClient(api_key="hr_live_...")

try:
    delivery = client.webhooks.send(
        endpoint_id="nonexistent",
        data={"test": True},
    )
except AuthenticationError:
    print("Invalid API key")
except NotFoundError:
    print("Endpoint not found")
except RateLimitError:
    print("Rate limit exceeded - try again later")
except ValidationError as e:
    print(f"Invalid request: {e.message}")
except PayloadTooLargeError:
    print("Payload exceeds maximum size")

API Reference

HookSniffClient(api_key, base_url="https://hooksniff-api-1046140057667.europe-west1.run.app/v1", timeout=30)

Main client class.

client.endpoints

  • .create(url, description=None, retry_policy=None)Endpoint
  • .get(endpoint_id)Endpoint
  • .list()List[Endpoint]
  • .delete(endpoint_id)bool

client.webhooks

  • .send(endpoint_id, event=None, data=None)Delivery
  • .get(delivery_id)Delivery
  • .list(status=None, page=1, per_page=20)DeliveryList
  • .replay(delivery_id)Delivery
  • .batch(webhooks)BatchResult
  • .attempts(delivery_id)List[DeliveryAttempt]
  • .export(format="json", status=None, date_from=None, date_to=None)Any

verify_signature(payload, signature, secret)bool

Verify a webhook signature using HMAC-SHA256.

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

hooksniff-0.3.0.tar.gz (106.5 kB view details)

Uploaded Source

Built Distribution

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

hooksniff-0.3.0-py3-none-any.whl (359.6 kB view details)

Uploaded Python 3

File details

Details for the file hooksniff-0.3.0.tar.gz.

File metadata

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

File hashes

Hashes for hooksniff-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f68e1f57b3bca452c80002ec2552aea99963aadef246193b5af9efefb3a0ea49
MD5 c055a77c63e842742b285b5f32f1282d
BLAKE2b-256 8e8d34c797e74887c6db58e613b06ec2e1fe27c0d261f2b78509bfbae1840dc8

See more details on using hashes here.

File details

Details for the file hooksniff-0.3.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for hooksniff-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d89a3153044d8ecaa91a5d07605843edd4d42c5a20d737f141f36be0b901c8cb
MD5 ceaf0e15200a7b7d6c8e40637d5845d1
BLAKE2b-256 777d6ce82ffd8f2f171f0abf4e0849fd9fd2f83181b806eff76d00973f01b71a

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