A lightweight and secure Python library for building authentication systems using Authly. This SDK provides simple tools to verify JWT tokens against Authly's identity provider.
Install using pip:
pip install authly-sdkOr using uv:
uv add authly-sdkfrom authly_sdk import AuthlyClient, TokenInvalidError, TokenExpiredError
# 1. Initialize the client
client = AuthlyClient(
issuer="https://auth.example.com",
audience="your-api-identifier"
)
# 2. Verify a token
try:
token = "eyJhbGciOiJSUzI1NiIs..."
claims = client.verify(token)
# Access standard and custom claims with full IDE support
print(f"User Subject: {claims['sub']}")
print(f"Session ID: {claims['sid']}")
print(f"Permissions: {claims['permissions']}")
except TokenExpiredError:
print("The token has expired")
except TokenInvalidError as e:
print(f"Invalid token: {e}")You can customize the JWKS path or allowed algorithms:
client = AuthlyClient(
issuer="https://auth.example.com",
audience="your-api",
jwks_path="/.well-known/jwks.json",
algorithms=["RS256"]
)We use uv for dependency management.
# Install dev dependencies
uv sync --dev
# Run type checks
uv run basedpyright src
# Format code
uv run ruff format .This project is licensed under the MIT License - see the LICENSE file for details.