Skip to main content

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(userId, email, displayName, listingId, sessionJti)
    await report_usage(session.sessionJti, 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: none rejected 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mythos_sdk-0.0.6.tar.gz (92.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mythos_sdk-0.0.6-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file mythos_sdk-0.0.6.tar.gz.

File metadata

  • Download URL: mythos_sdk-0.0.6.tar.gz
  • Upload date:
  • Size: 92.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for mythos_sdk-0.0.6.tar.gz
Algorithm Hash digest
SHA256 0aa26a4a0db9c99e5654a81429da781bcd6ac76af9df1bbb58aaf7eee39efa3f
MD5 d95d361d732c7d4096a99516dd0368d9
BLAKE2b-256 cbc75d5ad6d173fd78275303abc78eb7d30300a3d271a5ea11c3c130235c34a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mythos_sdk-0.0.6.tar.gz:

Publisher: publish.yml on Mythoswork/mythos-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mythos_sdk-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: mythos_sdk-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for mythos_sdk-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 96ca396379a69d99fa0dc3da2ca1be643422e9ab69d403a96b5bdd4c8b58ecbe
MD5 0474ae7439e08049b0316353d68c1a37
BLAKE2b-256 1f24eb393691ff8c39c5d5776ca87fa9c660c465918ed4b96896d088eee15238

See more details on using hashes here.

Provenance

The following attestation bundles were made for mythos_sdk-0.0.6-py3-none-any.whl:

Publisher: publish.yml on Mythoswork/mythos-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page