Skip to main content

jwt-policy-guard

CI PyPI Python

Policy-first JWT verification and issuing for Python 3.9+. The package builds on PyJWT's maintained cryptographic implementation and adds an immutable application policy so security decisions do not come from attacker-controlled token headers.

Created by Luis Aneuris Tavarez De Jesus.

Why this exists

JWT signature verification is only one part of token security. Applications must also constrain algorithms, bind keys to a trusted issuer, validate audiences, require time claims, distinguish token types, and enforce their own scopes and roles. jwt-policy-guard makes those decisions explicit and reusable.

Installation

pip install jwt-policy-guard

Verify tokens

from datetime import timedelta
from jwt_policy_guard import JwtPolicy, JwtVerifier, JwksKeyProvider

policy = JwtPolicy(
    algorithms=("RS256",),
    issuer="https://identity.example.com/",
    audiences=("payments-api",),
    required_scopes=frozenset({"payments:read"}),
    max_token_age=timedelta(minutes=15),
)

verifier = JwtVerifier(
    policy,
    JwksKeyProvider("https://identity.example.com/.well-known/jwks.json"),
)
verified = verifier.verify(encoded_token)

print(verified.subject)
verified.require_roles({"operator"})

Issue application-owned tokens

from datetime import timedelta
from jwt_policy_guard import JwtIssuer

issuer = JwtIssuer(
    issuer="https://identity.example.com/",
    audiences=("payments-api",),
    key=private_key,
    algorithm="RS256",
    key_id="2026-09-primary",
)

token = issuer.issue(
    "customer-42",
    expires_in=timedelta(minutes=10),
    scopes={"payments:read"},
    roles={"customer"},
    claims={"tenant": "acme"},
)

Security guarantees

  • No unsecured none algorithm.
  • Symmetric and asymmetric algorithms cannot be mixed in one policy.
  • The allow-list never comes from the token header.
  • Trusted issuer, intended audience, registered time claims, and explicit typ.
  • Optional maximum token age, subject pattern, required scopes, and roles.
  • HTTPS-only JWKS by default with PyJWT key caching and rotation support.
  • Read-only verified claims and a typed exception hierarchy.

This library follows the deployment guidance in RFC 8725. It does not replace TLS, secure key storage, key rotation, token revocation, or application authorization. Never log raw tokens.

Development

python -m pip install -e '.[dev]'
ruff check .
mypy src
pytest
python -m build
twine check dist/*

License

MIT

Metadata

Release files for jwt-policy-guard 0.1.0

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

Source distribution (sdist)

Source distribution for jwt-policy-guard 0.1.0
File Size Uploaded
jwt_policy_guard-0.1.0.tar.gz 10.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jwt-policy-guard 0.1.0
File Interpreter ABI Platform
jwt_policy_guard-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.9 kB

Release files / jwt_policy_guard-0.1.0.tar.gz

Download URL jwt_policy_guard-0.1.0.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c6bd3d375b8a903d2405305646afc403aa45d8a3c393d6d54e18a3502c4684c1
BLAKE2b-256 checksum
How to use checksums
cde5e753ddf11687ac5cd5bb82b86e33b630f919c7974e9c3eda8a842568afc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 8, 2026.

Transparency log

Release files / jwt_policy_guard-0.1.0-py3-none-any.whl

Download URL jwt_policy_guard-0.1.0-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ff80a20e0fcd9fdde4fe4ad3f3b14c4d07dccb6ce45b6f5894abd2719dccef8
BLAKE2b-256 checksum
How to use checksums
2915ac580bcdc0d78b843583e9e58cd2105bcef75ebdbb00dfc34f2dba5e2aa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

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