Skip to main content

starlette-hmac

HMAC Middleware for the pythonic Starlette API framework

Installation

$ pip install starlette-hmac

Usage

This will verify that the request will be done with an authorization header with value HMAC <hmac hash of body>

import os
from starlette.applications import Starlette
from starlette_hmac.middleware import HMACMiddleware

shared_secret = os.environ.get("SHARED_SECRET")

app = Starlette()
app.add_middleware(HMACMiddleware, shared_secret=shared_secret)

Advanced usage

To customize header name or value of you can pass the needed parameters to the middleware. This example verifies that the request was done with an x-hub-signature header with value sha256=<hash>

import os
import hashlib
from starlette.applications import Starlette
from starlette_hmac.middleware import HMACMiddleware

shared_secret = os.environ.get("SHARED_SECRET")

app = Starlette()
app.add_middleware(HMACMiddleware, 
                   shared_secret=shared_secret, 
                   header_field="x-hub-signature", 
                   digestmod=hashlib.sha256, 
                   header_format="sha256={}"
)

Develop

This project uses poetry to manage its development environment, and pytest as its test runner. To install development dependencies:

$ poetry install

To run the tests:

$ poetry shell
$ pytest

Release files for starlette-hmac 0.0.4

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

Source distribution (sdist)

Source distribution for starlette-hmac 0.0.4
File Size Uploaded
starlette_hmac-0.0.4.tar.gz 2.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for starlette-hmac 0.0.4
File Interpreter ABI Platform
starlette_hmac-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 6.2 kB

Release files / starlette_hmac-0.0.4.tar.gz

Download URL starlette_hmac-0.0.4.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e1b12b14e31a3709a7d2209bb3ab6f1e45c58e324dba57cb5e9e724a3e8e1ed3
BLAKE2b-256 checksum
How to use checksums
43d14468813227bfc6281d922b9f240878782191a99e210d0d2171a1663a41db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.6 Darwin/23.1.0

Release files / starlette_hmac-0.0.4-py3-none-any.whl

Download URL starlette_hmac-0.0.4-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e63b69ef21ac7fca39c92f825c9540e78a74fb436431d71c032cdc16b34251a0
BLAKE2b-256 checksum
How to use checksums
3ac1a976b95197a0c0b108a32c1530490a47b32a92f3e196e221c3fa82a9b647
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.6 Darwin/23.1.0

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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