A Cookiecutter template for production-ready FastAPI services — managed with uv and ready to ship with Docker and Docker Compose.
Every generated project comes with:
- clean FastAPI app (
src/layout, settings viapydantic-settings, CORS, lifespan hooks, health/readiness probes) - multi-stage Dockerfile (uv builder → slim runtime, non-root user)
- docker-compose.yml with a healthchecked API service (and an optional PostgreSQL service)
.env.exampledriving all configurationscripts/build.shandscripts/deploy.shto build & deploy the stackpytesttests,ruffconfig, and aMakefileof shortcuts
You'll be prompted to enter values. Then it creates your project in the current
working directory based on those answers. No local install needed — run it with
uvx (or pipx run / pip install cookiecutter):
uvx cookiecutter gh:Kurdzik/cookiecutter-python-fastapi-templateYou can also point Cookiecutter at a local checkout:
uvx cookiecutter path/to/cookiecutter-python-fastapi-templateThen:
cd my-fastapi-service
cp .env.example .env
./scripts/build.sh
./scripts/deploy.sh # -> http://localhost:8000/docs| Variable | Description | Default |
|---|---|---|
project_name |
Human-readable name | My FastAPI Service |
project_slug |
Directory / repo name (kebab-case) | derived from project_name |
package_name |
Importable Python package (snake_case) | derived from project_slug |
project_description |
Short description | — |
author_name |
Author name (also used in the MIT LICENSE) |
Your Name |
author_email |
Author email | you@example.com |
version |
Initial version | 0.1.0 |
python_version |
Python version for the app and Docker images | 3.12 |
app_port |
Port the API listens on | 8000 |
use_postgres |
Add a PostgreSQL service + async SQLAlchemy | yes |
my-fastapi-service/
├── Dockerfile
├── docker-compose.yml
├── .env.example
├── Makefile
├── pyproject.toml
├── scripts/
│ ├── build.sh
│ └── deploy.sh
├── src/
│ └── my_fastapi_service/
│ ├── main.py
│ ├── config.py
│ ├── db.py # only when use_postgres = yes
│ └── api/
│ ├── router.py
│ └── routes/health.py
└── tests/
The template ships with a bake test using
pytest-cookies:
uv sync
uv run pytestMIT — see LICENSE.