Skip to main content

HMAC-based API request signing with environment-bound key derivation for microservices

Project description

pyreqsign

HMAC-based API request signing with environment-bound key derivation for microservices.

Installation

pip install pyreqsign

Quick Start

from pyreqsign import sign, verify, sign_request

# Sign API parameters
signature = sign(secret="my-api-key", params={"user_id": "42"}, method="POST", path="/api/data")
# → "ES-v2:YWJjZGVm..."

# Verify on the server side
is_valid = verify(secret="my-api-key", params={"user_id": "42"}, signature=signature)

# Or sign an entire HTTP request (returns headers dict)
headers = sign_request("my-api-key", "POST", "https://api.example.com/v1/data",
                       json_body={"action": "update"})
# → {"Authorization": "EnvSign ES-v2:...", "X-EnvSign-Timestamp": "1714300000"}

Why EnvSign?

Standard HMAC signing only binds the secret key. EnvSign additionally binds the signing environment — the derived key depends on both the secret AND the machine fingerprint, making it ideal for:

  • Microservice-to-microservice auth where each service instance has a unique identity
  • API gateway request validation with replay protection via timestamp binding
  • Webhook verification where the sender environment is part of the trust chain

API

Core Signing

Function Description
sign(secret, params, ...) Sign request parameters, returns ES-v2:<sig>
verify(secret, params, sig, ...) Verify signature, constant-time comparison
sign_request(secret, method, url, ...) Sign full HTTP request, returns auth headers
env_fingerprint() Generate 256-bit machine identity
derive_key(secret, fp) Derive signing key from secret + fingerprint

Config Helpers

Function Description
get_env(key, default) Read string env var
parse_bool(key, default) Parse boolean (true/1/yes/on)
parse_int(key, default) Parse integer, silent fallback
parse_list(key, sep, default) Parse comma-separated list
load_config(prefix) Collect all vars matching prefix

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyreqsign-1.3.3-cp38-abi3-win_amd64.whl (714.3 kB view details)

Uploaded CPython 3.8+Windows x86-64

pyreqsign-1.3.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (800.4 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

pyreqsign-1.3.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (752.8 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

pyreqsign-1.3.3-cp38-abi3-macosx_11_0_arm64.whl (700.5 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

pyreqsign-1.3.3-cp38-abi3-macosx_10_12_x86_64.whl (766.6 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file pyreqsign-1.3.3-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pyreqsign-1.3.3-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 714.3 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pyreqsign-1.3.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5771d7997ccb9da15110305388903c469916fb60a5903d2fd1702e6c58867cbc
MD5 401358dadb68098a254dc2a1773cdf1c
BLAKE2b-256 5b07c207514b352cd0800e99478e8ee15cacc1f413002374adcf8023c75f2ad9

See more details on using hashes here.

File details

Details for the file pyreqsign-1.3.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyreqsign-1.3.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c6734a52a859eb78b2246d3589a95176b73cbf20ba614972f686553d5da849f4
MD5 558df41639ea149f674aa9aedd2979d2
BLAKE2b-256 a8e6e55ea9ebed8eba86129098e6aeda4cf6fc1773e5a833d3ecc920dccd16a0

See more details on using hashes here.

File details

Details for the file pyreqsign-1.3.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyreqsign-1.3.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3783787d81828d32bbc694b144673e18674c8dd4f5de0b6dc04a4761efd42d9a
MD5 b053d7f9d4ee70a985ab8a3362bf1b9b
BLAKE2b-256 e785eb498a3b7f43daecb9eb9271126d6246bc48c087810af2c28354f73c712e

See more details on using hashes here.

File details

Details for the file pyreqsign-1.3.3-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyreqsign-1.3.3-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c9d3a8bfd0d341a22491f6831c83c19957d84d5d1b4f5e59ab4b74f929fd361
MD5 956f0c0cef71a3566d943c8ed6c77c88
BLAKE2b-256 90c9636a0a178be832a1099da5672f7774163cc313969c8a4e41e2931a9d07b0

See more details on using hashes here.

File details

Details for the file pyreqsign-1.3.3-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyreqsign-1.3.3-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6f2564fcedc8640a278d5a8750c5460a13d5c819f007a52294fdafe66d978b7e
MD5 95933b2b712060e3cfa971afa2697045
BLAKE2b-256 ae875bc97c175b06d981e54eec7ef2e2e3f0cdc08b1e2dd058748f8b1d04703f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page