Official Mythos SDK for Python — launch token verification, usage reporting, and handshake
Project description
mythos-sdk
Official Mythos SDK for Python — launch token verification, usage reporting, and handshake.
Install
pip install mythos-sdk[fastapi]
Quick start
from fastapi import FastAPI, Depends
from mythos_sdk import require_launch_token, report_usage, create_handshake_router, create_listing_callback_handler
app = FastAPI()
# Example storage for dynamically registered listing IDs
registered_listing_ids: set[str] = set()
async def get_listing_ids() -> list[str]:
return list(registered_listing_ids)
# Handshake endpoint — Mythos pings this before publishing your listing
app.include_router(create_handshake_router())
# Listing registration callback — Mythos calls this after your listing is registered
async def on_registered(listing_id: str) -> None:
registered_listing_ids.add(listing_id)
app.add_api_route(
"/.well-known/mythos-listing-registered",
create_listing_callback_handler(on_registered),
methods=["GET", "POST"],
)
# Protected route — verifies and consumes the launch token automatically
@app.get("/dashboard")
async def dashboard(session = Depends(require_launch_token(resolve_listing_ids=get_listing_ids))):
# session = MythosSession(user_id, email, display_name, listing_id, session_jti)
await report_usage(session.session_jti, credits=1, reason="page-view")
return {"ok": True}
Environment variables
| Variable | Required | Default | Description |
|---|---|---|---|
MYTHOS_LISTING_ID |
No* | — | Your listing ID |
MYTHOS_LISTING_IDS |
No* | — | Comma-separated listing IDs (overrides above) |
MYTHOS_API_URL |
No | https://api.mythos.work |
API base URL override |
*Optional when you provide resolve_listing_ids; otherwise one of MYTHOS_LISTING_ID or MYTHOS_LISTING_IDS is required.
API
require_launch_token(resolve_listing_ids=None)
FastAPI dependency. Verifies the RS256 launch token from ?lt=, enforces single-use semantics, and returns a MythosSession. Listing IDs are read from MYTHOS_LISTING_ID(S) by default; pass resolve_listing_ids to supply them dynamically (e.g. from storage populated by create_listing_callback_handler). Returns 401 if the token is missing, invalid, or already consumed.
report_usage(session_jti, *, credits, reason=None)
Reports credit consumption against a session. Call after delivering value to the user.
create_handshake_router()
Returns a FastAPI APIRouter that mounts GET /.well-known/mythos-handshake. Mythos calls this endpoint during listing publish to confirm the SDK is installed and reachable.
create_listing_callback_handler(on_registered)
Returns a FastAPI-compatible async handler. Mount it at the route you configure with app.add_api_route (or a router). It validates the ?lt= token, awaits on_registered(listing_id) on success, and responds with { "ok": True }. Use the callback to persist the listing ID so resolve_listing_ids can read it. Returns 401 for missing/invalid tokens and 503 for unexpected errors.
verify_launch_token(token, resolve_listing_ids=None)
Low-level token verifier. Validates the launch token and returns the decoded MythosSession. Listing IDs are read from MYTHOS_LISTING_ID(S) by default; pass resolve_listing_ids to supply them dynamically. Use require_launch_token() dependency instead for most cases.
Security
- Tokens verified via RS256 against the Mythos JWKS endpoint
alg: nonerejected as a hard block- Single-use enforcement is non-skippable (ADR-0003)
- JWKS keys cached 10 minutes with automatic re-fetch on key rotation
License
Apache-2.0 — see LICENSE.
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 mythos_sdk-0.0.5.tar.gz.
File metadata
- Download URL: mythos_sdk-0.0.5.tar.gz
- Upload date:
- Size: 91.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fcdb7baf9eb6af57f531ddbffdcd45edb8c5ad325efc48cdd0300d2eaf464cf
|
|
| MD5 |
4c56dcab4e31c210fd54c7e12e2ad698
|
|
| BLAKE2b-256 |
572de0622400f179b6d642d6c57d61042f80a8aa2557989f47528d64d05f6cf9
|
Provenance
The following attestation bundles were made for mythos_sdk-0.0.5.tar.gz:
Publisher:
publish.yml on Mythoswork/mythos-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mythos_sdk-0.0.5.tar.gz -
Subject digest:
1fcdb7baf9eb6af57f531ddbffdcd45edb8c5ad325efc48cdd0300d2eaf464cf - Sigstore transparency entry: 2136889337
- Sigstore integration time:
-
Permalink:
Mythoswork/mythos-sdk@67025f4bef04b9fe606d3bd90a1603dc641e6f92 -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/Mythoswork
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@67025f4bef04b9fe606d3bd90a1603dc641e6f92 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mythos_sdk-0.0.5-py3-none-any.whl.
File metadata
- Download URL: mythos_sdk-0.0.5-py3-none-any.whl
- Upload date:
- Size: 9.6 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 |
185610bf18ac570608953d195799876f875ec39d1e48a261f7665ac455cd053c
|
|
| MD5 |
921701265dc716090c0e8186e96267f4
|
|
| BLAKE2b-256 |
4dc397a75b5827b41572cce534fdebaa216af9c816c5ce213bb21b883ea921d8
|
Provenance
The following attestation bundles were made for mythos_sdk-0.0.5-py3-none-any.whl:
Publisher:
publish.yml on Mythoswork/mythos-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mythos_sdk-0.0.5-py3-none-any.whl -
Subject digest:
185610bf18ac570608953d195799876f875ec39d1e48a261f7665ac455cd053c - Sigstore transparency entry: 2136889342
- Sigstore integration time:
-
Permalink:
Mythoswork/mythos-sdk@67025f4bef04b9fe606d3bd90a1603dc641e6f92 -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/Mythoswork
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@67025f4bef04b9fe606d3bd90a1603dc641e6f92 -
Trigger Event:
push
-
Statement type: