yeezy-na-izi / FastAPI-template

πŸš€ Useful FastAPI template, which use tortoise-orm

Repository from Github https://github.comyeezy-na-izi/FastAPI-templateRepository from Github https://github.comyeezy-na-izi/FastAPI-template

FastAPI Template

Useful and multifunction FastApi template

FastApi CodeFactor CodeStyle PythonVersions

Features

  • aiogram 3 as a main library
  • pyrogram as a database library
  • poetry as a dependency manager
  • 🎨 OpenAPI docs on api/docs and api/redoc
  • πŸ›  Docker support with docker-compose

Usage

Create project

  • πŸ“Œ Create and clone repo from this template
  • πŸ”‘ Rename example.toml to config.toml and change api settings

Install dependencies

  • 🐍 Install poetry with command pip install poetry
  • πŸ“Ž Install dependencies with command poetry install

Run project

  • πŸš€ Run project via python -m app

Docker

You can start the project with docker using this command:

docker-compose -f deploy/docker-compose.yml --project-directory . up --build

But you have to rebuild image every time you modify poetry.lock or pyproject.toml with this command:

docker-compose -f deploy/docker-compose.yml --project-directory . build

Project structure

$ tree "app"
app
β”œβ”€β”€ __init__.py
β”œβ”€β”€ __main__.py  # Startup script. Starts uvicorn.
β”œβ”€β”€ application.py  # FastAPI application configuration.
β”œβ”€β”€ settings.py  # Main configuration settings for project.
β”œβ”€β”€ api  # Package with all handlers.
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── router.py  # Main router.
β”œβ”€β”€ db  # module contains db models
β”‚   └── __init__.py
β”œβ”€β”€ events
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ shutdown.py  # Shutdown event.
β”‚   └── startup.py  # Startup event.
β”œβ”€β”€ middlewares  # Package contains middlewares.
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── main.py  # Main middleware.
└── static  # Static content.
    └── docs
        β”œβ”€β”€ redoc.standalone.js
        β”œβ”€β”€ swagger-ui-bundle.js
        └── swagger-ui.css

Pre-commit checker

To install pre-commit simply run inside the shell:

pre-commit install

pre-commit is very useful to check your code before publishing it. It's configured using .pre-commit-config.yaml file.

By default, it runs:

  • black (formats your code);
  • flake8 (spots possible bugs);

You can read more about pre-commit here: https://pre-commit.com/

About

πŸš€ Useful FastAPI template, which use tortoise-orm


Languages

Language:Python 95.2%Language:Dockerfile 4.8%