Skip to content

nickatnight/cookiecutter-fastapi-backend

Repository files navigation

GitHub Actions status PyPi Shield License Shield uv version Read The Docs Badge

🍪 cookiecutter-fastapi-backend

Cookiecutter template to build and deploy fastapi backends to your favorite PaaS..batteries included.

Supported PaaS's:

  • Render
  • Platform.sh (Coming soon)
  • Fly.io (Coming soon)
  • DigitalOcean (Coming soon)

Quickstart

Install the latest Cookiecutter if you haven't installed it yet (this requires Cookiecutter 1.4.0 or higher):

# pipx is strongly recommended.
$ pipx install cookiecutter

# If pipx is not an option,
# you can install cookiecutter in your Python user directory.
$ python -m pip install --user cookiecutter

Generate project from GitHub template:

$ pipx run cookiecutter gh:nickatnight/cookiecutter-fastapi-backend

Or from Python code:

from cookiecutter.main import cookiecutter

cookiecutter("gh:nickatnight/cookiecutter-fastapi-backend")

Features

  • 🐳 Docker & Docker Compose integration and optimization for local development. Fast bundles using build stages and uv
  • 💻 Production ready Python web server using FastAPI
  • ✏️ SQLModel Library for interacting with SQL databases from Python code, with Python objects. It is designed to be intuitive, easy to use, highly compatible, and robust
  • 🚈 Alembic Lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python
  • 💾 postgresql Powerful open source object-relational database
  • 🏪 Redis In-memory data structure store, used as a distributed, in-memory key–value database, cache and message broker
  • ⚙️ Common Base models and repository classes for common CRUD operations and database schemas.
  • 🌱 Celery Asynchronous task or job queue
  • 📥 Continuous Integration/Deployment Modular GitHub Actions to lint, test, and deploy to your favorite platform. Automatically includes Codecov reporting.
  • ↩️ pre-commit Git hooks to maintain code quality using modern tooling (ruff, black, isort)
  • 🚀 Sentry Application monitoring and error tracking. You can sign up for free at sentry.io

Input Variables

The generator (cookiecutter) will ask you for some data, you might want to have at hand before generating the project.

The input variables, with their default values (some auto generated) are:

  • project_name: The name of the project
  • project_slug: The development friendly name of the project. By default, based on the project name
  • project_slug_db: The database friendly name of the project. By default, based on the project name
  • author_email: The authors email...for maintainer info in pyproject.toml
  • py_version: The version of Python to install. Options are 3.9, 3.10, and 3.11
  • db_container_name: The name of the database container. Default db
  • backend_container_name: The name of the backend container. Default backend
  • use_celery: Whether to use Celery/Beat and Redis for asynchronous/scheduled tasks. Default no
  • use_sentry: Whether to use Sentry for application monitoring and error tracking. Default no
  • github_username: The username of the GitHub user. Used for badge display in generated project README.md
  • deployments: Deploy to your favorite platform, Render.com (and more to come). Default none

Documentation

See full documentation here.