Skip to content

Usage with Litestar

Another example of usage with LiteStar - litestar-sqlalchemy-template

1. Install lite-bootstrap[litestar-all]:

uv add lite-bootstrap[litestar-all]
pip install lite-bootstrap[litestar-all]
poetry add lite-bootstrap[litestar-all]

Read more about available extras here:

2. Define bootstrapper config and build you application:

from lite_bootstrap import LitestarConfig, LitestarBootstrapper


bootstrapper_config = LitestarConfig(
    service_name="microservice",
    service_version="2.0.0",
    service_environment="test",
    cors_allowed_origins=["http://test"],
    health_checks_path="/custom-health/",
    opentelemetry_endpoint="otl",
    prometheus_metrics_path="/custom-metrics/",
    sentry_dsn="https://testdsn@localhost/1",
    swagger_offline_docs=True,
)
bootstrapper = LitestarBootstrapper(bootstrapper_config)
application = bootstrapper.bootstrap()

Read more about available configuration options here:

Logging

Structlog is integrated via Litestar's StructlogPlugin, which makes request.logger available in route handlers:

from litestar import Request, get


@get("/items")
async def list_items(request: Request) -> list[str]:
    request.logger.info("listing items")
    return []