Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 3.42 KB

readme.md

File metadata and controls

51 lines (39 loc) · 3.42 KB

fastapi-sqlalchemy-template

Coverage CI License GitHub stars uv Ruff ty

Description

Dockerized FastAPI, SQLAlchemy 2 and PostgreSQL app template with DI.

Key features

  • tests on pytest with automatic rollback after each test case
  • IOC (Inversion of Control) container built on modern-di
  • Observability tools integration built on lite-bootstrap
  • Linting and formatting with ruff, type checking with ty
  • Alembic for DB migrations

Authentication is intentionally omitted: pick the scheme that fits your project and add it as a FastAPI dependency.

After git clone run

just --list

Tracing in production

Setting OPENTELEMETRY_ENDPOINT turns tracing on, and by default every request is traced. In a benchmark of GET /api/decks/{id}/, that cut throughput by about 40%. Sampling with the standard OpenTelemetry variables brings that down to about 20%:

OTEL_TRACES_SAMPLER=parentbased_traceidratio
OTEL_TRACES_SAMPLER_ARG=0.1

This keeps one trace in ten, and follows the caller's decision when a request arrives with a trace context. Errors still reach Sentry when SENTRY_DSN is set.

The template also turns off the ASGI send and receive spans (opentelemetry_exclude_spans in app/settings.py), so each request records its server span and database spans only. With every request traced, that raised throughput by 5 to 8% in the same benchmark. Remove the setting if you need those spans.

📝 License

Part of modern-python

Browse the full list of templates and libraries in modern-python; the org profile has the categorized index.