Skip to content

A library for building authentication systems using Authly.

License

Notifications You must be signed in to change notification settings

Anvoria/authly-sdk-py

Repository files navigation

Authly Python SDK

PyPI version Python versions License: MIT

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.

Installation

Install using pip:

pip install authly-sdk

Or using uv:

uv add authly-sdk

Quick Start

from 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}")

Advanced Configuration

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"]
)

Development

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 .

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A library for building authentication systems using Authly.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages