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.2-cp38-abi3-win_amd64.whl (691.4 kB view details)

Uploaded CPython 3.8+Windows x86-64

pyreqsign-1.3.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (793.2 kB view details)

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

pyreqsign-1.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (748.1 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

pyreqsign-1.3.2-cp38-abi3-macosx_11_0_arm64.whl (675.5 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for pyreqsign-1.3.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2199df35a4d7327ebed5d579a020abc3d1a0bb80a3275f1d7b1299c5838bf348
MD5 db1b5906b1810efa342465cdebea3346
BLAKE2b-256 71ed8f7c1ab7a9f2f514e9710f841ae11198b7505217e9da195e7a1fa4a829f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyreqsign-1.3.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fbd21b84ffd22abdc0522fec7936380bd8e16c9eb861103805863ecf65228179
MD5 83b1cd3afb95ebb61a601f6a48768a66
BLAKE2b-256 80022295c05c84d691b80de173342a716eba231e5f78a3fda8c8b41c7a3a1d0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyreqsign-1.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cd7eabff701c5d5d5fb86e6078143d4162cea289da0908f5a9bb281b32b485ea
MD5 1532fc6de400a7480370a40ad1a2677c
BLAKE2b-256 96fb612c1080c0b05b3d815a3b648559dd56fa86aac2e43aa08e8867fdea305a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyreqsign-1.3.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 882ab382191a4a2cd76b1638326443951a0aa1c1314a5d466e197521d6229079
MD5 38ab05c0342ab0fc07e5051f077b831b
BLAKE2b-256 d43ab4fdda4f13335b3267d79d157af36fbfe31434126a1f54e51f725b1285f7

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