A pragmatic, production-minded FastAPI project generator
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters