ArnaudC / fastapi-docker-compose

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Description

Fast api is a modern, fast (high-performance), web framework for building APIs with Python 3.7+ based on standard Python type hints.
This is a quick start with inspired from https://fastapi.tiangolo.com/deployment/docker/#build-a-docker-image-for-fastapi.

Usage

# 1. Edit FAST_API_APP in .env to select which app to use. app_basic is a simple app. See bellow for a description of available applications.
./start.sh init
# 2. Open FastApi OpenApi documentation
google-chrome http://localhost:53187/docs
# 3. Debug spa app
./start.sh npmrunstart
# 4. Open spa app
google-chrome http://localhost:3000

FastAPI : available apps

Frontend

The frontend was initialized with this command :

npx create-react-app frontend
npm run start # See port in .env

In production, the content of frontend/build is mounted as a static app in fastapi. It could also be possible to serve it with nginx.

Postgres migrations with alembic

  1. Update the model in app_sql_alchemy/app/models.py
  2. Run the following commands
./start.sh makemigrations
./start.sh migrate

Debug with Vscode

Debug works with debugpy on the server and remote debug in the IDE.

  • In docker-compose.yml, ensure the command executed for fastapi starts with 'python -m debugpy uvicorn ...'
  • In docker-compose.yml, ensure the debug port matches with the port in .vscode/launch.json
  • Run the server with './start.sh init' and then the debugger

Production

In docker-compose.yml, ensure the command executed for fastapi starts with 'gunicorn ...' with the correct number of workers (Number of recommended workers is 2 x number_of_cores + 1).

Official fastapi docker compose

This project is inspired from the official fast api docker compose project.
See folder called '{{cookiecutter.project_slug}}' in https://github.com/tiangolo/full-stack-fastapi-postgresql

Get openApi schema

See openapi.json.

Fixtures (sqlmodel)

With sqlmodel, run this command :

./start.sh fixturesqlmodel

TODO

  • Create a new app with postgres, full structure and api examples
  • Create a short video to show how to use this project

About


Languages

Language:Python 80.0%Language:Shell 9.6%Language:Dockerfile 2.4%Language:JavaScript 2.4%Language:HTML 2.2%Language:Smarty 1.7%Language:CSS 1.0%Language:Mako 0.5%