Webhook Utils
A set of utilities for interacting with webhooks.
Installation | Usage | HTTPX | FastAPI | Contributing | End-to-End Examples
Installation
pip install webhook-utils
Usage
Crypto
Available hash algorithms for all methods are:
md5(not recommended)sha1sha256(recommended)
Learn more about HMAC signatures here.
Generating HMAC signatures
Bare usage:
from webhook_utils.crypto import generate_sha256_signature
print(generate_sha256_signature(b'secret-key', b'some-message'))
Comparing HMAC signatures
Bare usage:
from webhook_utils.crypto import compare_sha256_signature
is_valid_signature = compare_sha256_signature(
b'secret-key',
b'some-message',
'expected-signature',
)
if not is_valid_signature:
raise ValueError('Invalid signature')
Httpx
webhook-utils has a built-in httpx.Auth class that can be used to
automatically sign requests made with an httpx.Client.
An X-Webhook-Signature header will be added to all POST requests.
The signature will be generated using the webhook_key and the
provided signature method (defaults to sha256).
The header, signature, and http methods can be customized by passing
the header_name, gen_signature_method, and methods keyword arguments.
pip install webhook-utils[httpx]
import httpx
from webhook_utils.contrib.httpx_auth import WebhookAuth
from webhook_utils.crypto import generate_sha1_signature
# Basic usage
auth = WebhookAuth("secret-key")
client = httpx.Client(auth=auth)
# Customized usage
auth = WebhookAuth(
"secret-key",
header_name="My-Webhook-Signature",
gen_signature_method=generate_sha1_signature,
methods={"POST", "PUT"},
)
client = httpx.Client(auth=auth)
client.post("https://example.com/webhook", json={"foo": "bar"})
FastAPI
webhook-utils has a built-in WebhookRouter class that can be used to
wrap a fastapi.APIRouter to automatically verify incoming request signatures.
pip install webhook-utils[fastapi]
from fastapi import FastAPI, APIRouter
from webhook_utils.contrib.fastapi import WebhookRouter
app = FastAPI()
webhook_router = WebhookRouter(
APIRouter(prefix="/webhooks"),
webhook_key="secret",
)
@webhook_router.on("/demo-webhook")
def demo_event_handler():
return {"status": "ok"}
app.include_router(webhook_router.api_router)
Publishing to PYPI
poetry build
# Verify that everything looks correct on test.pypi.org
poetry publish -r testpypi
poetry publish
Metadata
Release files for webhook-utils 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| webhook-utils-0.3.2.tar.gz | 6.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| webhook_utils-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.0 kB
Release files / webhook-utils-0.3.2.tar.gz
| Download URL | webhook-utils-0.3.2.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8419d7384efd4b6c0d9e8646fc083a3b334f98290222b83cc006d5f3de72da9b
|
|
BLAKE2b-256 checksum How to use checksums |
8e2d52e947e31175bfaa375608d1f4a2cb0f82076cc0d76d4a348e0b55d8aa0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.1 Darwin/20.6.0
|
Release files / webhook_utils-0.3.2-py3-none-any.whl
| Download URL | webhook_utils-0.3.2-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95852ee2d691b87967409ef1bab70eaba949c39edcddb9c6a8f8be1b0337c3db
|
|
BLAKE2b-256 checksum How to use checksums |
0532c855a4ac4b9cf681b78813c1a6627be489d080ca7add8a932fbea2dfcb21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.1 Darwin/20.6.0
|
Security for webhook-utils 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.