Skip to content

cloudeyes/fastalchemy

Repository files navigation

FastAlchemy

Build Status codecov

SQLAlchemy Middleware for FastAPI inspired by the official tutorial.

Install

pip install fastapi fastalchemy

Features

  • Super-easy configuration: simply put database.py and models.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()

Details

Please peek tests/app folder if you want to know the way to create database.py and models py.