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.
# 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
- app_basic : All apis from the basic part of the documentation without database and a single main.py file
- app_graphql : A graphql application using strawberry from https://fastapi.tiangolo.com/advanced/graphql/ and https://strawberry.rocks/docs/integrations/fastapi
- app_spa : An app using a frontend with a Single Application Page (here react).
- app_sql_alchemy : A simple app using postgres and ORM SQLAlchemy from https://fastapi.tiangolo.com/tutorial/sql-databases/
- app_sql_model : An app using postgres and experimental ORM SQLModel from the same author of fastapi
- app_structured : A structured application for bigger projects from the second part of the documentation https://fastapi.tiangolo.com/tutorial/bigger-applications/
- migrations_alembic : a folder generated by alembic for postgres migrations. See https://alembic.sqlalchemy.org/en/latest/
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.
- Update the model in app_sql_alchemy/app/models.py
- Run the following commands
./start.sh makemigrations
./start.sh migrate
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
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).
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
See openapi.json.
With sqlmodel, run this command :
./start.sh fixturesqlmodel
- Create a new app with postgres, full structure and api examples
- Create a short video to show how to use this project