Cookiecutter FastAPI Starter
A pragmatic, production-minded FastAPI project generator, inspired by
cookiecutter-django.
It generates a project with:
- FastAPI application factory
- Versioned API routes (
/api/v1) - Settings via
pydantic-settings - SQLAlchemy 2.0 session management
- Alembic migrations
- Optional JWT authentication
- A single, consistent API error envelope
- Request ID middleware
- Structured logging
- Health check endpoint
- Pytest test setup
- GitHub Actions CI
- Optional pre-commit hooks
- Optional Docker and Docker Compose files
- Optional Ruff and mypy configuration
Install
pip install cookiecutter-fastapi-starter
Usage
cookiecutter-fastapi-starter
Answer the prompts and you get a runnable project. To skip the prompts and override individual values:
cookiecutter-fastapi-starter --no-input -o ./projects include_auth=no database=sqlite
--help lists the flags. If you already use Cookiecutter, you can skip the
install entirely and point it at the repository:
cookiecutter gh:pratik16102001/cookiecutter-fastapi
Running the generated project
cd my-fastapi-app
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
cp .env.example .env
alembic upgrade head
uvicorn app.main:app --reload
- API: http://localhost:8000
- Interactive docs: http://localhost:8000/docs (disabled when
ENVIRONMENT=production) - Health: http://localhost:8000/api/v1/health
Template options
| Option | Default | Description |
|---|---|---|
project_name |
FastAPI Starter |
Human-readable project name |
project_slug |
derived | Kebab-case folder name |
package_name |
derived | Python import package name |
description |
... | Short project description |
author_name / email |
... | Project metadata |
python_version |
3.12 |
Targeted Python version |
fastapi_version |
0.115.0 |
Pinned FastAPI version |
database |
postgresql |
postgresql or sqlite |
include_auth |
yes |
JWT auth, user model, and auth routes |
cors_origins |
localhost origins | Comma-separated allowed origins |
use_docker |
yes |
Dockerfile and Compose file |
use_ruff |
yes |
Ruff lint configuration |
use_mypy |
yes |
mypy configuration |
use_pre_commit |
yes |
pre-commit hooks |
license |
MIT |
MIT, Apache-2.0, or Proprietary |
Generated layout
my-fastapi-app/
├── app/
│ ├── api/v1/ # Router and route modules
│ ├── core/ # Config, logging, errors, security
│ ├── db/ # Declarative base and session factory
│ ├── middleware/ # Request ID middleware
│ ├── models/ # SQLAlchemy models
│ ├── schemas/ # Pydantic schemas
│ ├── services/ # Business logic and data access
│ └── main.py # Application factory
├── alembic/ # Migration environment and versions
├── tests/
└── pyproject.toml
Every error response uses one shape, carrying the request ID so that a client report can be traced to a log line:
{ "error": { "code": "http_error", "message": "Not Found", "request_id": "..." } }
Before you deploy a generated project
The defaults are tuned for local development. Change these first:
- Set a real
SECRET_KEYin.env. - Set
ENVIRONMENT=production(this also disables/docsand/redoc). - Narrow
allowed_hostsfrom["*"]to your actual hostnames. - Narrow
CORS_ORIGINSto your real front-end origins.
Contributing
See CONTRIBUTING.md and our Code of Conduct. To report a security issue, see SECURITY.md.
Roadmap
- Role-based access control
- Redis cache option
- Celery/RQ background jobs
- OpenAPI client generation
- Kubernetes deployment examples
License
MIT — see LICENSE.
Metadata
Release files for cookiecutter-fastapi-starter 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cookiecutter_fastapi_starter-0.2.0.tar.gz | 21.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cookiecutter_fastapi_starter-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.3 kB