Cookiecutter template to build and deploy fastapi backends..batteries included.
Install the latest Cookiecutter if you haven't installed it yet (this requires Cookiecutter 1.4.0 or higher):
pip install cookiecutter
Generate project:
cookiecutter https://github.com/nickatnight/cookiecutter-fastapi-backend.git
- Docker & Docker Compose integration and optimization for local development. Fast bundles using build stages and Poetry
- Production ready Python web server using Uvicorn
- Python FastAPI:
- Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic).
- Intuitive: Great editor support. Completion everywhere. Less time debugging.
- Easy: Designed to be easy to use and learn. Less time reading docs.
- Short: Minimize code duplication. Multiple features from each parameter declaration.
- Robust: Get production-ready code. With automatic interactive documentation.
- Standards-based: Based on (and fully compatible with) the open standards for APIs: OpenAPI and JSON Schema.
- Many other features including automatic validation, serialization, interactive documentation, authentication with OAuth2 JWT tokens, etc.
- 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
- CORS (Cross Origin Resource Sharing).
- NGINX High Performance Load Balancer, Web Server, & Reverse Proxy
- Let's Encrypt A free, automated, and open certificate authority (CA), provided by the Internet Security Research Group (ISRG)...with automatic cert renewal
- PostgresSQL Powerfull open source object-relational database
- AsyncPG Database interface library designed specifically for PostgreSQL and Python/asyncio
- Redis In-memory data structure store, used as a distributed, in-memory key–value database, cache and message broker
- Continuous Integration/Deployment Modular GitHub Actions to lint, build, test, and deploy to DigitalOcean cloud
- pre-commit Git hooks to maintain code quality
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 projectproject_slug
: The development friendly name of the project. By default, based on the project nameproject_slug_db
: The database friendly name of the project. By default, based on the project nameauthor_email
: The authors email...used for certbotdb_container_name
: The name of the database container. Defaultdb
backend_container_name
: The name of the backend container. Defaultbackend
nginx_container_name
: The name of the nginx web server container. Defaultnginx
doctl_version
: The version name of DigitalOcean Command Line Interface to use. Default1.92.0
github_username
: The username of the GitHub user. Used for badge display in generated projectREADME.md
include_example_api
: Include example API, models, schemas, and script to init db data. Options arey
orn
deployments
: Includedocker-compose
files needed for deployment step in GitHub Action. Options arey
orn
After using this generator, your new project (the directory created) will contain an extensive README.md
with instructions for development, deployment, etc. You can view it here
This project uses Poetry to manage dev environment. Once installed:
- install packages with
poetry install
- run tests with
poetry run pytest tests