← Back to all products
$9
Webhook Handler
Production-ready webhook receiver with signature verification, retry logic, and dead letter queue.
JSONMarkdownPython
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 9 files
webhook-handler/
├── LICENSE
├── README.md
├── examples/
│ └── config.example.json
├── free-sample.zip
├── guide/
│ ├── 01_webhook-handler.md
│ ├── 02_features.md
│ └── 03_quick-start.md
├── index.html
└── src/
└── main.py
📖 Documentation Preview README excerpt
Webhook Handler
Production-ready webhook receiver with signature verification, retry logic, and dead letter queue. Zero dependencies.
Part of the API Launchpad toolkit by [CodeVault](https://codevault.dev).
Features
- HMAC-SHA256 signature verification with timing-safe comparison
- Provider presets: Stripe, GitHub, SendGrid, or generic HMAC
- Event routing: map event types to Python handler functions
- Retry with exponential backoff and configurable jitter
- Dead letter queue: failed webhooks persisted to JSON files for review
- Idempotency: duplicate events automatically detected and skipped
- Zero dependencies — runs on Python stdlib only
Quick Start
# Start the webhook receiver
python3 src/main.py --port 9000
# Test with a signed payload
SECRET="whsec_YOUR_WEBHOOK_SECRET_HERE"
BODY='{"type":"payment.completed","id":"pay_123","amount":2999}'
SIG=$(echo -n "$BODY" | openssl dgst -sha256 -hmac "$SECRET" | awk '{print $2}')
curl -X POST http://localhost:9000/ \
-H "Content-Type: application/json" \
-H "X-Webhook-Signature: $SIG" \
-d "$BODY"
Registering Event Handlers
from main import webhook
@webhook.router.on("payment.completed")
def handle_payment(event_type: str, payload: dict) -> bool:
print(f"Payment received: ${payload['amount'] / 100:.2f}")
# Your logic: update DB, send email, etc.
return True # Return True on success, False to retry
@webhook.router.on("user.created")
def handle_new_user(event_type: str, payload: dict) -> bool:
print(f"New user: {payload.get('email', 'unknown')}")
return True
@webhook.router.default
def handle_unknown(event_type: str, payload: dict) -> bool:
print(f"Unhandled event: {event_type}")
return True
Provider Presets
| Provider | Signature Header | Prefix |
|---|---|---|
generic | X-Webhook-Signature | (none) |
... continues with setup instructions, usage examples, and more.
📄 Code Sample .py preview
src/main.py
#!/usr/bin/env python3
"""
Webhook Handler — Production-Ready Webhook Receiver
=====================================================
Handles incoming webhooks with HMAC-SHA256 signature verification, event
routing to handler functions, retry logic with exponential backoff, dead
letter queuing, and structured logging.
Zero dependencies. Just run: python3 main.py
Part of the API Launchpad toolkit by DataNest.
License: MIT
"""
from __future__ import annotations
import hashlib
import hmac
import json
import logging
import os
import time
import threading
from dataclasses import dataclass, field
from datetime import datetime, timezone
from http.server import HTTPServer, BaseHTTPRequestHandler
from pathlib import Path
from typing import Any, Callable
# ---------------------------------------------------------------------------
# Configuration
# ---------------------------------------------------------------------------
DEFAULT_HOST = "0.0.0.0"
DEFAULT_PORT = 9000
DEFAULT_SECRET = "whsec_YOUR_WEBHOOK_SECRET_HERE"
# Dead letter queue: failed webhooks are written here for manual inspection
DLQ_DIR = Path("./dead_letter_queue")
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S",
)
logger = logging.getLogger("webhook-handler")
# ---------------------------------------------------------------------------
# ... 384 more lines ...