🔐 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]
Metadata
Release files for jwtifypy 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| jwtifypy-0.2.1.tar.gz | 11.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| jwtifypy-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.1 kB
Release files / jwtifypy-0.2.1.tar.gz
| Download URL | jwtifypy-0.2.1.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b8f39787b560f3b6b2b902bce9e4ac16fbb1fe8a05ca5c43b031947b82c2948
|
|
BLAKE2b-256 checksum How to use checksums |
6bdc4f21d3c51a92e6b6d102641f5c4edd8c6ea55fc9efb7543404c87cde2e22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.11.13 Linux/6.11.0-1018-azure
|
Release files / jwtifypy-0.2.1-py3-none-any.whl
| Download URL | jwtifypy-0.2.1-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cba770943735a61520e3618edded54c6529bffd8527120d1ae8f81b797d2422b
|
|
BLAKE2b-256 checksum How to use checksums |
07ea2b4c97b0aa7a95062323e28ca59b5df3bebfd58e32cadbbe248a2c26ce1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.11.13 Linux/6.11.0-1018-azure
|