Cookiecutter FastAPI

This template generator creates a FastAPI application for a REST API.

Features

  • Python 3.9+ (configurable)
  • Poetry based dependency management
  • FastAPI
  • Correct ASGI Lifespan events management for FastAPI
  • Session management, login/logout
  • Cache using Redis (aioredis)
  • Postgres asynchronous database access based on Encode Databases
  • Docker image for deployment based on multi-stage builds
  • Development tasks registered in a Makefile for easy access and management
  • Mercurial/Git hooks for pre-commit and pre-push events
  • Linting based on flake8 (and plugins), blue, mypy and isort
  • Asynchronous tests based on pytest, httpx and alt-pytest-asyncio

Instructions

You must have cookiecutter installed:

$ pip install --user cookiecutter

Usage

You can use this template directly from its repository:

$ cookiecutter https://github.com/andredias/cookiecutter-fastapi.git

You will be prompted to enter a bunch of project config values. Then, Cookiecutter will generate a project from the template, using the values that you entered.

That's it!

Similar Projects

There are a few templates and generators for FastAPI projects. All of them have their own opinionated group of implementation choices. Since I couldn't find any who met my needs or design preferences, I decided to create one of my own.