UpSec Webhook signature verification SDK for Python
Project description
upsec-webhook
Official Python SDK for UpSec — webhook signature verification & API client.
Installation
pip install upsec-webhook
Features
- ✅ Signature Verification — HMAC constant-time comparison (SHA-256, SHA-512, etc.)
- ✅ Flask Decorator — Auto-reject invalid signatures with 401
- ✅ API Client — Full typed access to UpSec endpoints, events, destinations & delivery attempts
- ✅ Zero Dependencies — Uses only Python standard library
Quick Start — Signature Verification
from upsec import verify_signature
is_valid = verify_signature(
payload=request.get_data(),
secret=os.environ["WEBHOOK_SECRET"],
signature=request.headers.get("X-Hub-Signature-256", ""),
)
Flask Decorator
from upsec.middleware import flask_webhook
@app.route("/webhook", methods=["POST"])
@flask_webhook(secret=os.environ["WEBHOOK_SECRET"])
def handle_webhook():
# Signature verified automatically
return {"ok": True}
API Client
The SDK includes a full-featured API client to interact with your UpSec dashboard programmatically.
Initialize
from upsec import UpSec
client = UpSec(api_key="sk_live_...")
List Endpoints
endpoints = client.endpoints.list()
for ep in endpoints:
print(f"{ep.name} — {ep.target_url} (active: {ep.active})")
List Events
result = client.events.list(endpoint_id="ep_abc123", limit=20)
print(f"{result['total']} total events")
for event in result["data"]:
print(f"{event.source} — valid: {event.signature_valid}")
List Destinations
destinations = client.destinations.list()
for dest in destinations:
print(f"{dest.name} → {dest.target_url}")
List Delivery Attempts
attempts = client.delivery_attempts.list(event_id="evt_abc123", limit=50)
for a in attempts:
print(f"Attempt #{a.attempt_number}: {a.status_code}")
if a.error_message:
print(f" Error: {a.error_message}")
Get Profile
me = client.me()
print(f"{me.full_name} ({me.subscription_status})")
Error Handling
from upsec import UpSec, UpSecApiError
try:
endpoints = client.endpoints.list()
except UpSecApiError as e:
print(f"API Error {e.status}: {e}")
Full Example: Verify + Log
import os
from flask import Flask, request
from upsec import UpSec, verify_signature
from upsec.middleware import flask_webhook
app = Flask(__name__)
client = UpSec(api_key=os.environ["UPSEC_API_KEY"])
@app.route("/webhook", methods=["POST"])
@flask_webhook(secret=os.environ["WEBHOOK_SECRET"])
def handle_webhook():
# Check recent events via API
result = client.events.list(limit=5)
print(f"Recent events: {len(result['data'])}")
return {"ok": True}
API Reference
Signature Verification
verify_signature(payload, secret, signature, algorithm="sha256")
Returns True if the HMAC signature is valid. Uses constant-time comparison.
sign_payload(payload, secret, algorithm="sha256")
Returns a signed header string like sha256=<hex>. Useful for testing.
flask_webhook(secret, header, algorithm)
Flask decorator that auto-rejects invalid signatures with 401.
API Client
UpSec(api_key, base_url=None)
| Param | Type | Description |
|---|---|---|
api_key |
str |
Your API key (sk_live_...) |
base_url |
str |
Custom API base URL (optional) |
Resources
| Method | Returns |
|---|---|
client.endpoints.list() |
List[UpSecEndpoint] |
client.events.list(endpoint_id?, limit?, offset?) |
{ data, total } |
client.destinations.list() |
List[UpSecDestination] |
client.delivery_attempts.list(event_id?, limit?) |
List[UpSecDeliveryAttempt] |
client.me() |
UpSecProfile |
Data Classes
All API responses return typed dataclass objects:
UpSecEndpoint— id, name, target_url, active, created_at, workspace_idUpSecEvent— id, endpoint_id, source, status_code, signature_valid, created_at, payload_jsonUpSecDestination— id, name, target_url, active, endpoint_id, transform_rules, created_atUpSecDeliveryAttempt— id, event_id, destination_id, status_code, attempt_number, error_message, response_body, next_retry_at, created_atUpSecProfile— id, full_name, company_name, subscription_status, created_at
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file upsec_webhook-2.0.0.tar.gz.
File metadata
- Download URL: upsec_webhook-2.0.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6833bc6d07509dc24091e72206ee700c56e971989814aef8bf4c4097e34667fb
|
|
| MD5 |
18e1a550a79e4026ee24330f7b79dbc7
|
|
| BLAKE2b-256 |
12f80da560196c57ccc7901756b7cee44d2f2f85bf61775319cf990451a26cee
|
Provenance
The following attestation bundles were made for upsec_webhook-2.0.0.tar.gz:
Publisher:
publish-python.yml on selmansenol/upsec-594fe05e
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
upsec_webhook-2.0.0.tar.gz -
Subject digest:
6833bc6d07509dc24091e72206ee700c56e971989814aef8bf4c4097e34667fb - Sigstore transparency entry: 1117419760
- Sigstore integration time:
-
Permalink:
selmansenol/upsec-594fe05e@f39bb256fa6e34ba1fab90549348b1149ffce62b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/selmansenol
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@f39bb256fa6e34ba1fab90549348b1149ffce62b -
Trigger Event:
push
-
Statement type:
File details
Details for the file upsec_webhook-2.0.0-py3-none-any.whl.
File metadata
- Download URL: upsec_webhook-2.0.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eca021984d2eb28e344ed1760461edde57df19f72fd44c364a39b419895893d5
|
|
| MD5 |
127c1b7fc8b2cc4df6c20c3b45640204
|
|
| BLAKE2b-256 |
a0f2cfe7afd8485080dc8b225020107fac3d3f768188857614064058b7e784e9
|
Provenance
The following attestation bundles were made for upsec_webhook-2.0.0-py3-none-any.whl:
Publisher:
publish-python.yml on selmansenol/upsec-594fe05e
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
upsec_webhook-2.0.0-py3-none-any.whl -
Subject digest:
eca021984d2eb28e344ed1760461edde57df19f72fd44c364a39b419895893d5 - Sigstore transparency entry: 1117419870
- Sigstore integration time:
-
Permalink:
selmansenol/upsec-594fe05e@f39bb256fa6e34ba1fab90549348b1149ffce62b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/selmansenol
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@f39bb256fa6e34ba1fab90549348b1149ffce62b -
Trigger Event:
push
-
Statement type: