Skip to main content

A pragmatic, production-minded FastAPI project generator

Project description

Cookiecutter FastAPI Starter

PyPI version Python versions CI License: MIT

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

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_KEY in .env.
  • Set ENVIRONMENT=production (this also disables /docs and /redoc).
  • Narrow allowed_hosts from ["*"] to your actual hostnames.
  • Narrow CORS_ORIGINS to 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cookiecutter_fastapi_starter-0.2.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cookiecutter_fastapi_starter-0.2.0-py3-none-any.whl (31.0 kB view details)

Uploaded Python 3

File details

Details for the file cookiecutter_fastapi_starter-0.2.0.tar.gz.

File metadata

File hashes

Hashes for cookiecutter_fastapi_starter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 37279730e180b16e71b96522aa9ef05bb1dee8fcb57da33c9034ca4e98c5e0a7
MD5 9dc850463dea2f5b27d5e299431cdbec
BLAKE2b-256 fbc84261680e481ccf49aef6c10982575befcd93503509d6c98552243ba30117

See more details on using hashes here.

Provenance

The following attestation bundles were made for cookiecutter_fastapi_starter-0.2.0.tar.gz:

Publisher: publish.yml on pratik16102001/cookiecutter-fastapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cookiecutter_fastapi_starter-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cookiecutter_fastapi_starter-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28124a77e56813729338359238ddefe4075cb0d3eea7e900a6fe282170d7f63c
MD5 d9356a709ce3a15ce7ffdcabc514610d
BLAKE2b-256 4efa287f62fac921f1de868c75b2f484e1718c237db41d52a9b78209cb6f2956

See more details on using hashes here.

Provenance

The following attestation bundles were made for cookiecutter_fastapi_starter-0.2.0-py3-none-any.whl:

Publisher: publish.yml on pratik16102001/cookiecutter-fastapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page