Quickstart¶
This walkthrough takes you from an empty project to a FastAPI service with metrics, health checks, CORS, Swagger, and structured logging, wired up in a few lines. The same pattern applies to Litestar, FastStream, FastMCP, and framework-free services.
1. Install¶
Install lite-bootstrap with the FastAPI extras. fastapi-all pulls in every
supported instrument:
Want only some instruments? See the extras matrix in Installation.
2. Bootstrap your application¶
Create main.py:
from fastapi import FastAPI
from lite_bootstrap import FastAPIConfig, FastAPIBootstrapper
config = FastAPIConfig(
service_name="my-service",
service_version="1.0.0",
service_environment="local",
prometheus_metrics_path="/metrics",
health_checks_enabled=True,
health_checks_path="/health",
cors_allowed_origins=["*"],
swagger_offline_docs=True,
)
app: FastAPI = FastAPIBootstrapper(config).bootstrap()
@app.get("/")
async def root() -> dict[str, str]:
return {"hello": "world"}
bootstrap() returns a ready FastAPI app with every configured instrument
attached.
3. Run it¶
4. What you get¶
With the config above, your service now exposes:
- Prometheus metrics at
/metrics, for your scraper. - A health check at
/health, for your orchestrator's readiness probe. - Swagger UI at
/docs, with offline assets so it renders without a CDN. - CORS headers for the configured origins.
- Structured logging via
structlog, on by default (opt out withlogging_enabled=False).
5. Enable more¶
Logging, health checks, Prometheus and Swagger are on by default whenever their extras are installed. OpenTelemetry, Sentry, Pyroscope and CORS stay off until you set their config fields; unset (or empty) fields are skipped automatically.
config = FastAPIConfig(
service_name="my-service",
service_version="1.0.0",
service_environment="local",
# tracing — spans exported to your OTLP endpoint
opentelemetry_endpoint="http://localhost:4317",
# error reporting
sentry_dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
# continuous profiling (needs the `pyroscope` extra)
pyroscope_endpoint="http://localhost:4040",
)
To see which instruments were enabled or skipped at startup, inspect the bootstrapper.
skipped_instruments lists only instruments skipped by configuration; a configured instrument
whose extra is not installed is skipped with an InstrumentDependencyMissingWarning instead.
bootstrapper = FastAPIBootstrapper(config)
app = bootstrapper.bootstrap()
print(bootstrapper.build_summary()) # human-readable summary
for cls, reason in bootstrapper.skipped_instruments:
print(f"skipped {cls.__name__}: {reason}")
Next steps¶
- Configuration: every config field and per-instrument option.
- Integrations: Litestar, FastStream, FastMCP, and framework-free services.