SQLAlchemy and Alembic 2 · Updating and raw SQL
Use the async API
Create an async engine and session for asyncio apps such as FastAPI. Use an async driver like asyncpg.
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
engine = create_async_engine("postgresql+asyncpg://user:pass@localhost/db")
Session = async_sessionmaker(engine, expire_on_commit=False)
Official SQLAlchemy and Alembic 2 documentation
More updating and raw sql commands
All updating and raw sql commands · SQLAlchemy and Alembic 2 cheatsheet