The files here are the "full example" from the FastAPI-Users documenation plus some modifications for async SQLAlchemy 1.4 (maybe also 2.0?). All together it produces a simple example of using SQLAlchemy-Continuum with the transaction table having a relationship to the user.
But for most users I think the plugin.py
, middleware.py
and users.py
files gives the basic gist of what is needed to use FastAPI with SQLAlchemy-Continuum.
EDIT: it appears less than two weeks ago an update to FastAPI may make all of the issues I was facing moot. https://github.com/tiangolo/fastapi/releases/tag/0.74.1 Keep an eye on newer versions of FastAPI and see if this gist is relevant to you in the future.
file tree
.
├── app
│ ├── crud.py
│ ├── database.py
│ ├── help.md
│ ├── main.py
│ ├── middlewares.py
│ ├── models.py
│ ├── plugin.py
│ ├── schemas.py
│ └── users.py
├── scripts
│ └── init.sh
├── docker-compose.yml
├── main.py
├── poetry.lock
└── pyproject.toml
dependencies
[tool.poetry.dependencies]
python = "^3.8"
fastapi = "^0.74.1"
uvicorn = "^0.17.5"
asyncpg = "^0.25.0"
sqlalchemy-continuum = {git = "https://github.com/kvesteri/sqlalchemy-continuum.git"}
fastapi-users = "^9.2.5"
fastapi-users-db-sqlalchemy = "^2.0.4"
starlette-context = "^0.3.3"
docker-compose.yml
version: "3.9"
services:
db:
image: postgres:10
environment:
- POSTGRES_USER=db_user
- POSTGRES_PASSWORD=db_pass
- PGDATA=/var/lib/postgresql/data/pgdata
ports:
- "5432:5432"
volumes:
- ./scripts:/docker-entrypoint-initdb.d
admin:
image: adminer
restart: always
ports:
- 8081:8080
depends_on:
- db
scripts/init.sh
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<EOF
CREATE EXTENSION IF NOT EXISTS btree_gist;
EOF
It appears the latest updates to FastAPI give new functionality to middleware which may make this gist obsolete in the future. But currently FastAPI-Users does not support this new version so I can not look further into it.
https://github.com/tiangolo/fastapi/releases/tag/0.74.1