A cookiecutter template for minimal FastAPI server
A cookiecutter template for Python packages.
pip install cookiecutter
cookiecutter gh:nogoodusername/cookiecutter-fastapi-template
You will asked to fill in below details:
author_name
: Main Author of the library (Used in LICENSE, README.md)author_email
: Contact email of the author (Used in LICENSE, README.md)service_name
: Name of the FastAPI service project (Used in Makefile, README.md)service_description
: One line description of the library (Used in LICENSE, README.md)service_port
: Service run port (Used in Makefile and Dockerfile)open_source_license
: Option to select an open source license type.
Create a new repo for service_name
in Github or your preferred Git repository hosting site.
You will find a folder named [service_name
]. Move into the folder, and setup your git repo there.
cd [service_name]
git init .
git add .
git commit -m "Initial commit"
git remote add origin git@[your-package-repo]
git push -u origin master
Install Dev Requirements using pip
make init
You are good to go, you can add code to the service and start developing.
Changelogs are maintained using Keep a Changelog format.
This template provides production & staging sample Dockerfiles.
The dockerization is done using tiangolo/uvicorn-gunicorn-fastapi-docker. This image has autotuning included and adjust paramters based on the server it is running on to get best performance.
You can build your own docker image and run the same using docker run
or docker-compose
version: 3
services:
api:
container_name: api
image: "[docker-image]:latest"
environment:
- FLAVOUR=prod
- PORT={service_port}
ports:
- {service_port}:{service_port}
Find additional configurations for tiangolo/uvicorn-gunicorn-fastapi-docker: