Skip to content

Latest commit

 

History

History
94 lines (68 loc) · 2.78 KB

README.md

File metadata and controls

94 lines (68 loc) · 2.78 KB

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/