Python Library for XSHL Session
Project description
py-xshl-session
Session in JWT
Python library for managing JWT/JWE sessions with key management and XSHL Target integration.
- 🇷🇺 Russian version: see
README_RU.md - 📚 Full docs:
docs/index.md→ Quickstart, Guides, API, Security - 🌐 Localized docs (RU):
docs/ru/index.md
Features
- 🔐 JWT/JWE support for signing and encryption
- 🎯 XSHL integration: Target-aware JWKS loading
- ⚡ Background refresh of JWKS with TTL
- 🛡️ Extended claims validation via custom
SessionClaims - 📦 JWE serialization/deserialization helpers
- 🔍 Built-in request tracing
Constants
DEFAULT_SESSION_VERSION = 1DEFAULT_SESSION_EXPIRES = 120DEFAULT_UID = "00000000-0000-0000-0000-000000000000"DEFAULT_STR = "undef"
Quickstart
See docs/quickstart.md for a complete guide.
from xshl.session.keys import Keys
from xshl.session import Session, ConfigSession
import uuid
keys = Keys(name="session_name", url="https://example.org/jwks.json")
config = ConfigSession(
keys=keys,
app=uuid.uuid4(),
audience=["service-api"],
header={"alg": "RS256", "kid": "<kid>"},
version=1,
expires=3600,
key=b"<private-key-pem>"
)
session = Session(config, "trace-1", "trace-2")
session.sub = "user-123"
session.aud = "service-api"
session.scope = ["read", "write"]
jwt_token = session.jwt
Note: Session.jwt uses a JsonDumps context internally to serialize claims because Authlib JWT encoding does not expose a default hook for JSON; see API docs.
Merge note: all claims are copied on session + token, and claims in Session.merge_attributes are merged.
JWE helpers:
protected = {"alg": "RSA-OAEP-256", "enc": "A256GCM", "kid": "<kid>"}
serialized = session.serialize(b"payload", protected)
plaintext = session.deserialize(serialized)
Documentation
- API details in
docs/api.md - Configuration and operational tips in
docs/guides.md - Security recommendations in
docs/security.md
License
GPL v3 — see LICENSE and COPYRIGHT.
Contributing
- Issues and feature requests: open on GitHub
- Pull requests welcome. Please ensure:
- Tests pass
- Lint/style are respected
- Tests are added for new functionality
- You understand GPL v3 requirements for contributions
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 xshl_session-0.0.2.tar.gz.
File metadata
- Download URL: xshl_session-0.0.2.tar.gz
- Upload date:
- Size: 37.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1ae28c3702a5236d878756b0c8c39a214aace9eb25d6804aa187a8546c35450
|
|
| MD5 |
9aed7ef2aa72a11a3c9ecdd9cd981c50
|
|
| BLAKE2b-256 |
d358598f919adc886b2973d4e003757925ed44b52fec57f0753c68cfc4c3730c
|
File details
Details for the file xshl_session-0.0.2-py3-none-any.whl.
File metadata
- Download URL: xshl_session-0.0.2-py3-none-any.whl
- Upload date:
- Size: 35.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9233702238c4171c131646c2e93f7da3d4c1a43c00838128f1ca0eec0eec73d
|
|
| MD5 |
2a92845dd7431aaf25842fb4ca5f69c2
|
|
| BLAKE2b-256 |
6223a6526aba9b6ac4850d78300df0dcb71c82602362328cf7816c39e6fdd78b
|