Life is short, I Use Python with pyzt.
Project description
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
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 pyzt-0.0.4.tar.gz.
File metadata
- Download URL: pyzt-0.0.4.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12bae800765719e7a5733ec72bf008790b057ee74874b2d15d87b1f8c8adb8ca
|
|
| MD5 |
de48e89f349f00dff8aa07565e8585e9
|
|
| BLAKE2b-256 |
f30f120f6601f653c38d0e5e589f778e14d3a49f470f4560417a2e9efb5d9dae
|
File details
Details for the file pyzt-0.0.4-py3-none-any.whl.
File metadata
- Download URL: pyzt-0.0.4-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f2e2e391e1d65679715f9d7561ef7dd788524428861dcd5c4db32eaf8ad43d9
|
|
| MD5 |
076a54d83c5f27e0071471c80b1aae9d
|
|
| BLAKE2b-256 |
3b688737c2c78d04bdece2372233f5987dbd8af8c541ba572b35efcb69ff5ae7
|