Backend SDK for torii — verify JWTs, manage users, react to events from your Python server.
Project description
torii-backend
Backend SDK for torii — verify end-user JWTs without a per-request round trip and manage users from your Python server.
v0.x — API may still change.
Setup
-
Sign in to app.torii.so and from your dashboard copy:
- your issuer URL (e.g.
https://acme.torii.so) - a secret key (
sk_test_…for development,sk_live_…for production)
- your issuer URL (e.g.
-
Install the SDK:
pip install torii-backend # or, with the FastAPI dependency adapter: pip install "torii-backend[fastapi]"
Python 3.9+.
-
Verify an end-user JWT:
from torii_backend import verify_token auth = verify_token(token, issuer="https://acme.torii.so") print(auth.user_id, auth.environment_id, auth.email_verified)
The first call fetches the issuer's JWKS; subsequent calls reuse the cache and rotate keys automatically (handled by
PyJWT). No round trip per request. -
Call the backend REST API:
import os from torii_backend import create_torii_client torii = create_torii_client(secret_key=os.environ["TORII_SECRET_KEY"]) user = torii.users.get(user_id)
FastAPI
from fastapi import Depends, FastAPI
from torii_backend.fastapi import require_auth
app = FastAPI()
auth_dep = require_auth(issuer="https://acme.torii.so")
@app.get("/me")
def me(auth = Depends(auth_dep)):
return {"user_id": auth.user_id}
Backend API
page = torii.users.list(limit=50)
user = torii.users.create(email="x@y.com")
torii.users.ban(user.id)
sessions = torii.sessions.list_for_user(user.id)
torii.sessions.revoke_all_for_user(user.id)
PATCH semantics (users.update)
users.update is a tri-state PATCH: each updatable field can be set, cleared, or left alone. Pass only the kwargs you want on the wire — pydantic v2's model_fields_set tracks which fields were explicitly provided, and the SDK serializes via model_dump(exclude_unset=True) so untouched fields never appear in the request body.
torii.users.update(
user_id,
name="Ada", # → server updates name
phone=None, # → server clears phone (sent as JSON null)
# address not passed → server leaves alone
)
Wire body for the call above:
{ "name": "Ada", "phone": null }
| Call | Field on wire | Server effect |
|---|---|---|
users.update(id, name="Ada") |
"name": "Ada" |
update name |
users.update(id, phone=None) |
"phone": null |
clear phone |
users.update(id) (no field kwargs) |
omitted | leave alone |
You can also build a request explicitly — useful when assembling the patch dynamically:
from torii_backend import ToriiUpdateUserInput
patch = ToriiUpdateUserInput(name="Ada", phone=None)
torii.users.update(user_id, patch)
License
MIT
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 torii_backend-0.0.3.tar.gz.
File metadata
- Download URL: torii_backend-0.0.3.tar.gz
- Upload date:
- Size: 42.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c68718516d359417df5c3e867dbeb9a18944f3a1d6f706e367bf8af8fed9ced4
|
|
| MD5 |
773574a2021f1ee5101977e307b0b331
|
|
| BLAKE2b-256 |
b1c1385fa1d48bc6418919a51dfaa6e94d49a326c8f883c331352a96d976761d
|
Provenance
The following attestation bundles were made for torii_backend-0.0.3.tar.gz:
Publisher:
release.yml on Torii-ApS/torii-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torii_backend-0.0.3.tar.gz -
Subject digest:
c68718516d359417df5c3e867dbeb9a18944f3a1d6f706e367bf8af8fed9ced4 - Sigstore transparency entry: 1665850341
- Sigstore integration time:
-
Permalink:
Torii-ApS/torii-sdk-python@1ef6cf63426c0e035e854fc5476fa67a1a2fb1f2 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/Torii-ApS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1ef6cf63426c0e035e854fc5476fa67a1a2fb1f2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file torii_backend-0.0.3-py3-none-any.whl.
File metadata
- Download URL: torii_backend-0.0.3-py3-none-any.whl
- Upload date:
- Size: 50.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b8aa0a4d79bbdd837b1a2661f83e5d6d5e8bd952c34115330447526997510eb
|
|
| MD5 |
63362089350eeaf1c34d2b6dbd204802
|
|
| BLAKE2b-256 |
a060b7b5bfe9cedd195d55a9e915b8d02e04b8ad21f995063325f37385f15e5a
|
Provenance
The following attestation bundles were made for torii_backend-0.0.3-py3-none-any.whl:
Publisher:
release.yml on Torii-ApS/torii-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torii_backend-0.0.3-py3-none-any.whl -
Subject digest:
4b8aa0a4d79bbdd837b1a2661f83e5d6d5e8bd952c34115330447526997510eb - Sigstore transparency entry: 1665850584
- Sigstore integration time:
-
Permalink:
Torii-ApS/torii-sdk-python@1ef6cf63426c0e035e854fc5476fa67a1a2fb1f2 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/Torii-ApS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1ef6cf63426c0e035e854fc5476fa67a1a2fb1f2 -
Trigger Event:
push
-
Statement type: