Python quickstart
Python 3.9+.
pip install latchvector-sso
# framework extras pull nothing in unless imported:
pip install "latchvector-sso[fastapi]" # or [flask], [django]
1. Protect an API
Your API verifies tokens locally — no call to the SSO service per request.
from latchvector_sso import TokenVerifier
# Build once at startup — caches the discovery document and signing keys.
verifier = TokenVerifier(
issuer="https://sso.yourdomain.com",
audience="https://api.yourcompany.com", # your registered identifier
)
principal = verifier.verify_authorization_header(request.headers.get("Authorization"))
FastAPI, Flask, and Django dependencies/decorators ship in the framework submodules — see the README.
2. Log a user in
from latchvector_sso import SsoClient, TokenPair
sso = SsoClient(issuer="https://sso.yourdomain.com",
audience="https://api.yourcompany.com")
result = sso.login(email, password)
if isinstance(result, TokenPair):
access, refresh = result.access_token, result.refresh_token
Rotate with sso.refresh(refresh_token); persist the new refresh token.
3. Manage resources
from latchvector_sso import ManagementClient
mgmt = ManagementClient(issuer, lambda: current_access_token)
mgmt.users.create(organizationId=org_id, email=email, fullName=name, roleId=role_id)
mgmt.applications.create(organizationId=org_id, identifier=identifier, name=name)
Anything new is reachable via mgmt.request(...).
:::tip Full reference The PyPI README covers machine-to-machine, multitenancy, webhooks, and go-live checks. Full endpoint list: API reference. :::