Skip to content

modern-python/lite-bootstrap

Repository files navigation

Lite-Bootstrap

Test Coverage Supported versions downloads GitHub stars

lite-bootstrap assists you in creating applications with all the necessary instruments already set up.

With lite-bootstrap, you receive an application with lightweight built-in support for:

  • sentry
  • prometheus
  • opentelemetry
  • pyroscope - with OpenTelemetry trace-profile linking
  • structlog
  • cors
  • swagger - with additional offline version support
  • health-checks

Those instruments can be bootstrapped for:

Lifecycle constraints

A few constraints that aren't obvious from the API:

  • One bootstrapper per application instance. Constructing two FastAPIBootstrappers around the same fastapi.FastAPI (or two FastMcpBootstrappers around the same FastMCP) stacks teardown hooks and re-wraps the lifespan. The library warns and skips the second attachment, but the second bootstrapper's teardown() won't fire on ASGI shutdown.
  • One OpenTelemetryInstrument per process. bootstrap() calls opentelemetry.trace.set_tracer_provider(...), which the OTel SDK enforces as set-once — subsequent calls log a warning and have no effect. teardown() flushes spans and closes exporters but can't reset the process-global pointer.
  • teardown() is idempotent. BaseBootstrapper.teardown() short-circuits if not bootstrapped; per-instrument teardown methods are safe to call multiple times.
  • Partial teardown failures are aggregated. If an instrument's teardown raises, the bootstrapper continues with the rest of the instruments and raises TeardownError at the end with all collected failures.

Usage examples:

Part of modern-python

Browse the full list of templates and libraries in modern-python — see the org profile for the categorized index.

📦 PyPi

📝 License

Acknowledgements

lite-bootstrap is inspired by microbootstrap — a single package that wires up the common observability stack (sentry, prometheus, opentelemetry, logging, cors, swagger, health-checks) for FastAPI / Litestar / FastStream services and for plain scripts.

The following ideas were borrowed:

  • the overall surface — a Bootstrapper per framework that composes a set of instruments,
  • the lifecycle model — each instrument has bootstrap() / teardown() / is_ready() and is skipped when its optional dependency is not installed,
  • the catalog of supported instruments and supported frameworks.

The following intentionally differ:

  • Configuration: lite-bootstrap uses frozen dataclass configs (no pydantic / pydantic-settings runtime dependency), which is what makes it "lite". microbootstrap configures everything through pydantic-settings models.
  • Granular extras: lite-bootstrap ships only orjson as a runtime dependency; every instrument (sentry, otl, logging, pyroscope) and every framework (fastapi, litestar, faststream) is its own extra, with per-pair combos (fastapi-sentry, litestar-otl, faststream-metrics, …) and *-all rollups. You install only what you actually use. microbootstrap bundles the full observability stack (opentelemetry, sentry-sdk, structlog, pyroscope-io, rich, pydantic-settings, …) as base dependencies and only splits framework packages into extras.
  • Scope: lite-bootstrap is deliberately narrow — only instrument wiring. It does not include a Granian server runner or a console writer.