scistudio.api.app

Canonical import root: from scistudio.api.app import ...

Self-contained public-API reference — 1 symbols from this module's __all__, with signatures and docstrings inlined. Generated; do not hand-edit.

create_app — function

Stability: provisional · Since 0.3.5

create_app(*, guard: 'GuardFactory | None' = None, lifespan_hooks: 'Sequence[LifespanHook]' = (), capabilities: 'Capabilities | None' = None, routers: 'Sequence[APIRouter]' = ()) -> 'FastAPI'

Create and configure the FastAPI application.

Called with no arguments — as scistudio serve, scistudio gui and the desktop shell do — this is the open-source backend exactly as before: the loopback token guards /api/webmcp/*, every other route is unauthenticated, no lifespan hooks run, and every capability is off.

The keyword arguments let an edition configure its deployment on the same backend:

guard A scistudio.api.seam.GuardFactory installed in place of the loopback token middleware. The guard decides which paths it protects; no loopback token is minted. Requests under a self-authenticating prefix bypass it, as they bypass the default guard. lifespan_hooks Instances of scistudio.api.seam.LifespanHook entered in order at startup, after the core runtime exists, and exited in reverse before it stops. capabilities The scistudio.api.seam.Capabilities declared to the frontend through the served page; all off when omitted. routers Routers included after every built-in route and before the SPA mount. A router included on the returned app afterwards would sit behind the SPA mount at / and never be reached, so an edition's routes are passed here. Built-in routes win a path collision.

A sketch of the enterprise edition's launch path::

from scistudio.api.app import create_app
from scistudio.api.seam import Capabilities, IdentityCapability, mcp

app = create_app(
    guard=hub_guard,  # (app, GuardContext) -> ASGI app
    lifespan_hooks=[validate_callback, report_activity],
    capabilities=Capabilities(
        # The edition's own logout route: it ends the SciStudio
        # session, then returns where the browser goes next.
        identity=IdentityCapability(user=hub_user, logout_url="/api/session/logout"),
        transfer=True,
    ),
    routers=[transfer_router],
)