项目作者: nogoodusername

项目描述 :
A cookiecutter template for minimal FastAPI server
高级语言: Python
项目地址: git://github.com/nogoodusername/cookiecutter-fastapi-template.git


CookieCutter FastAPI Template

A cookiecutter template for Python packages.

Stack

Requirements

  • Cookiecutter
  1. pip install cookiecutter

Usage

  1. Generate Your FastAPI Project

    1. 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.

  2. Add a Git Repo

    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.

    1. cd [service_name]
    2. git init .
    3. git add .
    4. git commit -m "Initial commit"
    5. git remote add origin git@[your-package-repo]
    6. git push -u origin master
  3. Install Dev Requirements

    Install Dev Requirements using pip

    1. make init
  4. Add your service code and start developing

    You are good to go, you can add code to the service and start developing.


Deployments

Changelog

Changelogs are maintained using Keep a Changelog format.

Deployment using Docker image

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

  1. version: 3
  2. services:
  3. api:
  4. container_name: api
  5. image: "[docker-image]:latest"
  6. environment:
  7. - FLAVOUR=prod
  8. - PORT={service_port}
  9. ports:
  10. - {service_port}:{service_port}

Docker image configurations

Find additional configurations for tiangolo/uvicorn-gunicorn-fastapi-docker:


Sample project generated from this template

https://github.com/nogoodusername/fastapi-userless-service