Skip to content

Litestar

  • Start here: Frameworks
  • Common recipes: micro.install(app) opens the app on startup and binds the active app inside route handlers, so patterns resolve their backends ambiently without explicit backend= wiring. Call it after Litestar(...), which builds the middleware stack at construction.

grelmicro.integrations.litestar

Litestar integration that opens a Grelmicro app and binds it per request.

install

install(
    app: Litestar, micro: Grelmicro, *, ambient: bool = True
) -> None

Wire micro into a Litestar app.

Opens async with micro: on startup and closes it after shutdown, so the components are registered before the first request. Startup hooks and lifespan managers already passed to Litestar(...) keep running.

When ambient is True, wraps the app's ASGI handler so patterns resolve through Grelmicro.current() inside route handlers. The wrap sits outside every middleware Litestar built, so one that resolves a backend ambiently always runs inside the request scope.

Call it after the app is built, since Litestar builds its middleware stack at construction time:

from litestar import Litestar

from grelmicro import Grelmicro

micro = Grelmicro(uses=[...])
app = Litestar(route_handlers=[...])
micro.install(app)

Prefer the polymorphic micro.install(app), which detects the framework and calls this for you.

PARAMETER DESCRIPTION
app

The Litestar application to wire.

TYPE: Litestar

micro

The Grelmicro app to open in the lifespan and bind per request.

TYPE: Grelmicro

ambient

Wrap the app's ASGI handler with GrelmicroMiddleware so patterns resolve ambiently inside route handlers. Default True. Pass False to skip it.

TYPE: bool DEFAULT: True