Lightweight and extensible Python library for generating and verifying JWT tokens with multiple algorithms (HS256, ES256, RS256, etc.). Built on PyJWT, it provides an intuitive interface, flexible configuration, and secure key storage.
Project description
๐ JWTifyPy
JWTifyPy is a lightweight and extensible Python library for generating and verifying JWT tokens, with support for various algorithms like HS256, ES256, RS256, and more.
Built on top of PyJWT, it offers an intuitive interface, easy configuration, and secure key storage โ everything you need to work with JWTs.
๐ฆ Installation
pip install jwtifypy
โ๏ธ Optional Dependencies
To support environment variables (.env) and advanced cryptographic algorithms (ES256), you may install optional packages like python-dotenv and cryptography.
Use extras to include these:
- With dotenv support:
pip install jwtifypy[env]
- With cryptography support:
pip install jwtifypy[crypto]
- Full feature set:
pip install jwtifypy[full]
๐ Quick Start
๐ง Initialization
from jwtifypy import JWTConfig
JWTConfig.init(config={
"keys": {
"algorithm": "HS256",
"secret": "env:MY_SECRET_ENV"
}
})
๐น Basic Examples
from jwtifypy import JWTManager
# ๐ฅ Default token using the "default" key
token = JWTManager.create_access_token("user123")
print(token)
# ๐ eyJhbGciOiJIUzI1NiIsInR5cCI6...
# ๐ Token using a named key
admin_token = JWTManager.using("admin").create_access_token("admin42")
print(admin_token)
# ๐ eyJhbGciOiJSUzI1NiIsInR5cCI6...
๐ Add an Issuer (iss)
token_with_issuer = (
JWTManager.using("admin")
.with_issuer("my-service")
.create_access_token("issuer-user")
)
print(token_with_issuer)
๐ฏ Add an Audience (aud)
# ๐ฏ Single audience
token_with_aud = (
JWTManager.using("admin")
.with_audience("client-app")
.create_access_token("aud-user")
)
print(token_with_aud)
# ๐ฆ Multiple audiences (for decoding)
token_with_multiple_aud = (
JWTManager.using("admin")
.with_audience(
audience_for_encoding="web",
audience_for_decoding=["web", "mobile"]
)
.create_access_token("multi-aud-user")
)
print(token_with_multiple_aud)
๐ค Reuse Manager Conveniently
# ๐ค Create a separate manager using the "admin" key
JWTAdmin = JWTManager.using("admin")
# ๐ฏ Audience
token_with_aud = (
JWTAdmin
.with_audience("client-app")
.create_access_token("aud-user")
)
print(token_with_aud)
# ๐ Issuer + Audience together
token_full = (
JWTAdmin
.with_issuer("auth-server")
.with_audience("bot")
.create_access_token("full-user")
)
print(token_full)
๐ Token Verification with iss and aud
payload = (
JWTManager.using("admin")
.with_issuer("auth-server")
.with_audience("bot")
.decode_token(token_full)
)
print(payload["sub"]) # ๐ full-user
print(payload["aud"]) # ๐ web
print(payload["iss"]) # ๐ auth-server
โ๏ธ Key Features
- โ
Supports
HS256,ES256,RS256, and more - ๐ Named key store (
default,admin,service-X, etc.) - ๐ค Simple JWT creation/decoding interface
- ๐ Extensible for advanced scenarios
- โฑ Supports standard claims:
sub,exp,iat,aud,iss, etc.
๐งฉ Custom Configuration
from jwtifypy import JWTConfig
JWTConfig.init(config={
"keys": {
# ๐ Symmetric key (HS256) using a shared secret
"default": {
"alg": "HS256",
"secret": "secret"
},
# ๐ Asymmetric key (RS256) using RSA keys from files
"admin": {
"algorithm": "RS256",
"private_key": "file:/path/to/private.pem",
"public_key": "file:/path/to/public.pem"
},
# ๐งฌ Asymmetric key (ES256) using ECDSA, private key from env
# public_key will be auto-generated if `cryptography` is installed
"service": {
"alg": "ES256",
"private_key": "env:PRIVATE_KEY"
}
},
# โฑ Leeway in seconds for time validation (exp, iat)
"leeway": 1.0,
# โ๏ธ Additional validation options (as in PyJWT)
"options": {
"verify_sub": False,
"strict_aud": False
}
})
๐๏ธ Project Structure
jwtifypy/
โโโ __init__.py # Public interface
โโโ manager.py # JWTManager class
โโโ config.py # Config and initialization
โโโ key.py # Key parsing/handling (HS/RS/ES)
โโโ store.py # JWTKeyStore
โโโ exceptions.py # Custom exceptions
โโโ utils.py # Utilities
๐งช Running Tests
pytest tests/
๐ก๏ธ Security Recommendations
- โ Never hardcode secrets. Use environment variables.
- ๐ Prefer
RS256/ES256for service-to-service authentication. - โณ Set short token expiration (
exp). - ๐ Use and validate claims (
iss,aud,sub) when security matters.
๐ License
MIT ยฉ 2025 Created by [LordCode Projects] / [Dybfuo Projects]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jwtifypy-0.2.1.tar.gz.
File metadata
- Download URL: jwtifypy-0.2.1.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.11.13 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b8f39787b560f3b6b2b902bce9e4ac16fbb1fe8a05ca5c43b031947b82c2948
|
|
| MD5 |
fa6a10a4dab00ca4b5c68063f3f29050
|
|
| BLAKE2b-256 |
6bdc4f21d3c51a92e6b6d102641f5c4edd8c6ea55fc9efb7543404c87cde2e22
|
File details
Details for the file jwtifypy-0.2.1-py3-none-any.whl.
File metadata
- Download URL: jwtifypy-0.2.1-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.11.13 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cba770943735a61520e3618edded54c6529bffd8527120d1ae8f81b797d2422b
|
|
| MD5 |
46a6f07cdcf6a6f66f390a00b0f87689
|
|
| BLAKE2b-256 |
07ea2b4c97b0aa7a95062323e28ca59b5df3bebfd58e32cadbbe248a2c26ce1c
|