The purpose of the project to experiment with async FastAPI framework.
- to create simple crud api
- use SQLAlchemy as BD backend
- find how to manage migrations in SQLAlchemy
- simplify SQLAlchemy ORM usage
- run docker over poetry
What is used?
- poetry for dependency management.
- FastAPI as a web server
- alembic as a db migration tool
- fastapi-sqlalchemy for integration SQLAlchemy into FastAPI
- sqlalchemy_mixins to able use Django-like queries for SQLAlchemy
alembic init alembic
alembic revision --autogenerate -m "First migration"
in docker
docker-compose run web alembic upgrade head
locally
alembic upgrade head
docker-compose run up --build --force-recreate
in docker
docker-compose run web uvicorn demo:app --host 0.0.0.0 --port 8000 --reload
locally
uvicorn demo:app --reload
in PowerShell run:
>> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
>> Invoke-WebRequest "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-Win
dows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFiles\Docker\docker-compose.exe
Docker Compose wait for container X before starting Y
version: "2.1"
services:
db:
image: postgres:latest
container_name: postgres
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5433"]
interval: 30s
timeout: 5s
retries: 5
...
or
version: "3"
services:
web:
build: .
container_name: fastapi-web
restart: always
depends_on:
- db
...
http://localhost:5050/browser/
use these credentials to login: pgadmin4@pgadmin.org
:admin