Skip to main content

Python library for Standard Webhooks

Example

Verifying a webhook payload:

from standardwebhooks.webhooks import Webhook

wh = Webhook(base64_secret)
wh.verify(webhook_payload, webhook_headers)

webhook_payload must be the raw request body exactly as received, before any JSON parsing. Pass it as bytes to verify the bytes as sent, including bodies that aren't valid UTF-8. A str is verified as its UTF-8 encoding.

Asymmetric signatures

Verifying a webhook signed with asymmetric (v2a) signatures requires the asymmetric extra (pip install 'standardwebhooks[asymmetric]'), and uses the producer's public keys and the endpoint ID it shared with you:

from standardwebhooks.webhooks import WebhookAsymmetric

wh = WebhookAsymmetric(endpoint_id, ["whpk_..."])
wh.verify(webhook_payload, webhook_headers)

Webhooks signed with any of the public keys are accepted, so keys can be rotated by adding the new key to the list. Put the newest key first: it's the one used for endpoint verification.

Signing (asymmetric)

It's recommended to generate and hold the private key in a KMS or an HSM. Build the hash to sign, sign it with your HSM (pure ed25519), and format the signature for the webhook-signature header (these two don't require the asymmetric extra):

from standardwebhooks.webhooks import WebhookAsymmetric

digest = WebhookAsymmetric.signed_content_hash(endpoint_id, msg_id, timestamp, payload)
raw_signature = your_hsm.sign_ed25519(digest)  # 64 bytes
signature = WebhookAsymmetric.format_signature(raw_signature)

# The public key to share with consumers ("whpk_..."). Accepts the raw 32 byte key or its DER
# encoded SubjectPublicKeyInfo (e.g. what AWS KMS GetPublicKey returns).
public_key = WebhookAsymmetric.format_public_key(your_hsm.get_public_key())

If you hold the private key yourself (whsk_...), use WebhookAsymmetricSigner. One key pair can serve all endpoints, so the endpoint ID is passed to each call:

from standardwebhooks.webhooks import WebhookAsymmetricSigner

signer = WebhookAsymmetricSigner("whsk_...")
signature = signer.sign(endpoint_id, msg_id, timestamp, payload)
public_key = signer.public_key()  # "whpk_...", share it with consumers

Responding to endpoint verification:

challenge = webhook_headers.get("webhook-challenge")
if challenge:
    response_headers["webhook-challenge-response"] = wh.endpoint_verification_response(challenge)
    # Not a webhook delivery: respond (e.g. with 204 No Content) without processing the body
    return

Verifying the response as a producer (raises WebhookVerificationError if it doesn't match):

wh.verify_endpoint_verification_response(challenge, response_headers["webhook-challenge-response"])

Development

Requirements

  • python 3

Installing dependencies

python -m venv .venv
pip install -r requirements.txt && pip install -r requirements-dev.txt

Contributing

Before opening a PR be sure to format your code!

./scripts/format.sh

Running Tests

Simply run:

pytest

Metadata

Release files for standardwebhooks 1.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for standardwebhooks 1.4.1
File Size Uploaded Provenance Actions
standardwebhooks-1.4.1.tar.gz 7.8 kB With provenance Details for standardwebhooks-1.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for standardwebhooks 1.4.1
File Interpreter ABI Platform Actions
standardwebhooks-1.4.1-py3-none-any.whl Python 3 none any Details for standardwebhooks-1.4.1-py3-none-any.whl

Total release size: 16.5 kB

Release files / standardwebhooks-1.4.1.tar.gz

Download URL standardwebhooks-1.4.1.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
91f4bd92fcf8e93323953936d4dd50a4d97050aec7410bc48f3094e3507e2b1f
BLAKE2b-256 checksum
How to use checksums
a365e485605a796d60ad756d287c3d254ad75ef41027c113e1f9f4ed598d0dd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / standardwebhooks-1.4.1-py3-none-any.whl

Download URL standardwebhooks-1.4.1-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70e0b8e93a2f2cff1a10a4fa81292a9baa1decb91b79cbb45d4c34c1f5dd6e9f
BLAKE2b-256 checksum
How to use checksums
56271f44d66454590ad94d7aadacbbb7bb5956cc9d1d0f72f8f13f2f09a318f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Security for standardwebhooks 1.4.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for standardwebhooks-1.4.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page