Skip to main content

A minimal, spec-first, framework-agnostic, async-only JWT validator with zero network dependencies.

Project description

async-jwt-core

A minimal, spec-first, framework-agnostic, async-only JWT validator with zero network dependencies.

PyPI version License: MIT


🚀 Why async-jwt-core? (The Problem We Solve)

In the modern Python async ecosystem, validating JWTs using JSON Web Key Sets (JWKS) usually forces you into one of two bad situations:

  1. Framework Lock-in: Libraries tied directly to FastAPI, Starlette, or Django.
  2. Opinionated I/O: Libraries that insist on making network calls for you (often using specific HTTP clients) to fetch keys, making it hard to implement custom caching (like Redis) or use your own HTTP session.

async-jwt-core solves this by doing exactly one thing perfectly: Pure Cryptographic Validation without I/O.

We provide the core validation logic. You bring the keys. This gives you absolute control over how keys are fetched, cached, and stored, while ensuring your event loop never blocks.

✨ Key Features

  • 🔒 Zero Network I/O – Keys are fetched externally. The validator only does the heavy lifting (crypto and claim checks).
  • Async-Only API – Designed from the ground up for asyncio.
  • 🧩 Framework Agnostic – Works with FastAPI, Sanic, aiohttp, or even pure Python background workers.
  • 🛠️ Highly Modular & Extensible – Want to add a custom algorithm? Just inherit from Algorithm and register it.
  • 🎯 Custom Claim Validation – Pass your own validation functions to enforce business rules.
  • 📦 Ultra Lightweight – Only depends on cryptography for secure signature verification.

🔐 Supported Algorithms

We support a vast range of modern cryptographic algorithms out of the box (12 total):

Type Algorithms
HMAC (Symmetric) HS256, HS384, HS512
RSA (Asymmetric) RS256, RS384, RS512
RSA-PSS (Asymmetric) PS256, PS384, PS512
ECDSA (Elliptic Curve) ES256, ES384, ES512

🌟 Extra Features to Help You (30+ Features Total)

1. Token Creation (Signing)

We are no longer just a validator! You can now create and sign tokens easily.

from async_jwt_core import Encoder

header = {"alg": "HS256", "kid": "key-1"}
payload = {"sub": "1234567890", "name": "John Doe"}
secret = b"my-secret-key"

token = Encoder.create_token(header, payload, secret)

2. Token Extraction from Requests

Extract the JWT token directly from a request object (like FastAPI, Starlette, Flask, or Django Request).

token = Validator.extract_token(request)

3. In-built Async Rate Limiter

Protect your validation endpoint from brute-force attacks with an in-memory rate limiter.

4. JSON Web Encryption (JWE) Support

We support JWE decryption (RSA-OAEP with AES-GCM) to handle encrypted tokens.

5. Nonce / Replay Detection

Prevent replay attacks by checking the jti (JWT ID) claim via an async callback.

📖 Examples (References for Users)

We provide full working examples in the examples/ directory:

  • 📄 Basic Usage: Shows how to create and validate a token.
  • 🚀 FastAPI Demo: Shows how to integrate with FastAPI.
  • 🌶️ Flask Demo: Shows how to use it in Flask 2.0+ async routes.
  • 🎸 Django Demo: Shows how to use it in Django 3.1+ async views.

🛠️ Installation

uv add async-jwt-core
# or
pip install async-jwt-core

⚖️ Why We Are Better

Feature Standard PyJWT Framework Libs async-jwt-core
Async Native ❌ (Sync only) 🟡 (Sometimes)
Zero I/O ❌ (Often fetches keys)
No Lock-in ❌ (FastAPI/Django only)
Extensible Algs ❌ (Hard to add) ❌ (Hard to add)

📄 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 Distribution

async_jwt_core-0.2.4.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

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

async_jwt_core-0.2.4-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file async_jwt_core-0.2.4.tar.gz.

File metadata

  • Download URL: async_jwt_core-0.2.4.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for async_jwt_core-0.2.4.tar.gz
Algorithm Hash digest
SHA256 85b82fb5c63548a3ad919f37fea66f34ad4a2c630b851e316c8b7ec2ec1b09ec
MD5 051976d5bb44fcde12800988abd46bd5
BLAKE2b-256 eaea5cc70ef3c50a24eedfc2f1c2b3190e760d0cf9666321a2d3794c9f3723a7

See more details on using hashes here.

File details

Details for the file async_jwt_core-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: async_jwt_core-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for async_jwt_core-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4fee3658d66020cffece05f2afd9d11a8a71536145035c2844279a0b5a302986
MD5 61dc0648a5295f6f11eced2421673354
BLAKE2b-256 f6de1f15b92eafd67a480864cf651930732228ce6b0a16c8fd6227e1da795923

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