Skip to content

execreate/fastapi-template

Repository files navigation

FastAPI template

A starting point for your FastAPI application.

Features

  1. UV for dependency management. Simply run uv sync to set up your env, read more about UV at https://docs.astral.sh/uv/
    • Run uv sync --group=telemetry if you want to install OpenTelemetry instruments as well
  2. Docker compose for local development and testing
  3. SQLAlchemy for ORM (uses async engine) and Alembic for database migrations
  4. Simple authentication for the documentation page (to showcase how auth can be handled in a FastAPI app)
  5. CRUD operations generic class with pagination
  6. Async testing suite with Pytest
  7. ClickStack integration for logs and metrics

Start coding

Just click on that green Use this template button to start coding. There is a dummy app that is already implemented for you so that you can quickly learn how to use the CRUD factory.

Make sure to mark the app/ folder as source in your IDE otherwise you'll get import errors. And since all your code (except tests) lives inside app/ folder, you should import modules like this:

from core.config import settings

and NOT like this:

# this will throw an error!
from app.core.config import settings

Tests

Adapt the database connection string and run tests with:

ENVIRONMENT=test pytest

Use docker-compose to run your app:

docker compose up -d

Auto-generated docs

If you run the code without any changes, you'll find the documentation page here. The default username is docs_user and the password is simple_password.

Telemetry

After you add new dependencies, run the following command to also automatically add OpenTelemetry instruments for those new dependencies:

uv add --group telemetry $(opentelemetry-bootstrap -a requirements)

This template uses ClickStack.

About

FastAPI app template with SQL Alchemy & Alembic, async tests and a fullstack observability setup.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published