SQLAlchemy Middleware for FastAPI inspired by the official tutorial.
pip install fastapi fastalchemy
- Super-easy configuration: simply put
database.py
andmodels.py
files in your project folder with the following code.
from fastapi import FastAPI
from fastalchemy import SQLAlchemyMiddleware, db
from models import User
app = FastAPI()
app.add_middleware(SQLAlchemyMiddleware)
@app.get('/users')
def get_users():
return db.query(User).order_by(User.id).all()
Please peek tests/app
folder if you want to know the way to create database.py
and models
py.