pyzt
Life is short, I use Python.
pyzt is a Python library that provides a simple and efficient way to work with various tasks.
It is designed to be easy to use and flexible, allowing you to quickly implement and customize your tasks as needed.
pyzt.auth
A reusable and secure Python authentication toolkit for JWT-based APIs and Applications.
Features
- Create and verify JWT tokens (access and refresh tokens).
- Customizable
issuerandaudienceand expiry and scopes. - Defends against signature stripping, invalid types, and expired tokens.
- Secure password hashing with
argon2orbcrypt. - Zero-framework dependency — plug into any FastAPI, Flask, Django, or any other Python web frameworks, APIs, or even CLIs.
Installation
uv add pyzt
Usage
🔐 JWTAuth
from pyzt.auth.jwt import JWTAuth
jwt_auth = JWTAuth(
secret="your-secret",
issuer="your-api",
audience="your-app"
)
# Create a token with optional custom claims
access_token = jwt_auth.create_access_token("user@example.com", {
"role": "admin",
"scope": "read write"
})
# Validate token
payload = jwt_auth.decode_token(access_token, token_type="access")
🔁 Token Pair
pair = jwt_auth.create_token_pair("user@example.com")
print(pair.access_token, pair.refresh_token)
🔒 Password Hashing
from pyzt.auth.crypto import PasswordHasher
hasher = PasswordHasher("argon2")
hash = hasher.hash("mypassword")
assert hasher.verify("mypassword", hash)
Models
from pyzt.types.tokens import TokenPair, TokenPayload
Security Coverage
- ✅ HS256 token signing
- ✅ Expiry checks
- ✅ Signature stripping attack defense
- ✅ Token type validation
- ✅ Role/scope claim support
Testing
pytest tests/
License
MIT
Metadata
Release files for pyzt 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyzt-0.0.4.tar.gz | 21.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyzt-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.0 kB
Release files / pyzt-0.0.4.tar.gz
| Download URL | pyzt-0.0.4.tar.gz |
|---|---|
| Size | 21.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
12bae800765719e7a5733ec72bf008790b057ee74874b2d15d87b1f8c8adb8ca
|
|
BLAKE2b-256 checksum How to use checksums |
f30f120f6601f653c38d0e5e589f778e14d3a49f470f4560417a2e9efb5d9dae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Release files / pyzt-0.0.4-py3-none-any.whl
| Download URL | pyzt-0.0.4-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9f2e2e391e1d65679715f9d7561ef7dd788524428861dcd5c4db32eaf8ad43d9
|
|
BLAKE2b-256 checksum How to use checksums |
3b688737c2c78d04bdece2372233f5987dbd8af8c541ba572b35efcb69ff5ae7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|