sqlalchemy_helpers.fastapi module

FastAPI integration of database management.

async sqlalchemy_helpers.fastapi.make_db_session(manager) Iterator[AsyncSession][source]

Generate database sessions for FastAPI request handlers.

This lets users declare the session as a dependency in request handler functions, e.g.:

@app.get("/path")
def process_path(db_session: AsyncSession = Depends(make_db_session)):
    query = select(Model).filter_by(...)
    result = await db_session.execute(query)
    ...
Returns:

A sqlalchemy.ext.asyncio.AsyncSession object for the current request

sqlalchemy_helpers.fastapi.manager_from_config(db_settings, *args, **kwargs)[source]

Get the database manager using the Flask app’s configuration.

async sqlalchemy_helpers.fastapi.syncdb(db_settings)[source]

Run DatabaseManager.sync() on the command-line.