Skip to main content

🛡️ USSO Python Client SDK

The USSO Python Client SDK (usso) provides a universal, secure JWT authentication layer for Python microservices and web frameworks.
It’s designed to integrate seamlessly with the USSO Identity Platform — or any standards-compliant token issuer.


🔗 Relationship to the USSO Platform

This SDK is the official verification client for the USSO identity service, which provides multi-tenant authentication, RBAC, token flows, and more.
You can use the SDK with:

  • Self-hosted USSO via Docker
  • Any identity provider that issues signed JWTs (with proper config)

✨ Features

  • ✅ Token verification for EdDSA, RS256, HS256, and more
  • ✅ Claim validation (exp, nbf, aud, iss)
  • ✅ Remote JWK support for key rotation
  • ✅ Typed payload parsing via UserData (Pydantic)
  • ✅ Token extraction from:
    • Authorization header
    • Cookies
    • Custom headers
  • ✅ FastAPI integration with dependency injection
  • ✅ Django middleware for request-based user resolution
  • 🧪 90% tested with pytest and tox

📦 Installation

pip install usso

With framework extras:

pip install "usso[fastapi]"     # for FastAPI integration
pip install "usso[django]"      # for Django integration

🚀 Quick Start (FastAPI)

from usso.fastapi.integration import get_authenticator
from usso.schemas import JWTConfig, JWTHeaderConfig, UserData
from usso.jwt.enums import Algorithm

config = JWTConfig(
    key="your-ed25519-public-key",
    issuer="https://sso.example.com",
    audience="api.example.com",
    type=Algorithm.EdDSA,
    header=JWTHeaderConfig(type="Authorization"),
)

authenticator = get_authenticator(config)


@app.get("/me")
def get_me(user: UserData = Depends(authenticator)):
    return {"user_id": user.sub, "roles": user.roles}

🧱 Project Structure

src/usso/
├── fastapi/            # FastAPI adapter
├── django/             # Django middleware
├── jwt/                # Core JWT logic and algorithms
├── session/            # Stateless session support
├── models/             # JWTConfig, UserData, etc.
├── exceptions/         # Shared exceptions
├── authenticator.py    # High-level API (token + user resolution)

🐳 Integrate with USSO (Docker)

Run your own identity provider:

docker run -p 8000:8000 ghcr.io/ussoio/usso:latest

Then configure your app to verify tokens issued by this service, using its public JWKS endpoint:

JWTConfig(
    jwks_url="http://localhost:8000/.well-known/jwks.json",
    ...
)

🧪 Testing

pytest
tox

USSO Lite for standalone FastAPI applications

Install the local identity dependencies and mount the router:

pip install "usso[lite,fastapi]"
from fastapi import FastAPI
from usso.lite import EXCEPTION_HANDLERS, LiteConfig, create_lite_router

app = FastAPI()
config = LiteConfig(
    database_url="sqlite+aiosqlite:///./identity.db",
    issuer="https://api.example.com",
    audience="api.example.com",
    otp_sender=send_otp,  # async (identifier_type, identifier, code)
)
app.include_router(create_lite_router(config))
for exception, handler in EXCEPTION_HANDLERS.items():
    app.add_exception_handler(exception, handler)

Lite emits the same UserData-compatible claims as USSO and publishes its public signing key at /.well-known/jwks.json. A service can therefore move to full USSO by changing its issuer/JWKS configuration without changing its authorization code.

Security defaults:

  • public registration cannot assign roles or scopes;
  • user-management routes require admin:usso/lite/users (or a broader USSO scope);
  • OTP values are never returned by HTTP unless expose_otp_in_response=True is explicitly enabled for local development;
  • refresh tokens are single-use and sessions are checked on every local authenticated request;
  • login, registration, and OTP requests are rate-limited.

For initial provisioning, pass a trusted FastAPI dependency as admin_dependency= (for example, a deployment-only API-key dependency), use POST /users to create the first scoped administrator, then remove that bootstrap dependency. Do not grant the admin scope through default_scopes, because defaults apply to every public registration.


🤝 Contributing

We welcome contributions!


📝 License

MIT License © [mahdikiani]

Metadata

Release files for usso 0.33.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for usso 0.33.6
File Size Uploaded Provenance Actions
usso-0.33.6.tar.gz 205.0 kB Without provenance Details for usso-0.33.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for usso 0.33.6
File Interpreter ABI Platform Actions
usso-0.33.6-py3-none-any.whl Python 3 none any Details for usso-0.33.6-py3-none-any.whl

Total release size: 282.4 kB

Release files / usso-0.33.6.tar.gz

Download URL usso-0.33.6.tar.gz
Size 205.0 kB
Tags Source
SHA-256 checksum
How to use checksums
277e8bf5a302562866038718594c0559b5927343bb634cf436e0adcc962c4134
BLAKE2b-256 checksum
How to use checksums
60d8c78f6c144f528e02a87ba7bfa6bc3f1b2e66c739662ad72491d3806d910f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / usso-0.33.6-py3-none-any.whl

Download URL usso-0.33.6-py3-none-any.whl
Size 77.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d52b61068e343bae81e40ab4bc4a987d155e0854f1ec8aaca946ccbdc81e7a83
BLAKE2b-256 checksum
How to use checksums
6f108fbfb6efde8c8d604729832eee746900f28a49072d4ff7eb38dbd02c6422
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for usso 0.33.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.33.6 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page