SQLAlchemy Async
Async database access in Python using SQLAlchemy 2.0's native async API.
Definition
SQLAlchemy 2.0 introduced a native async API using Python's `asyncio`. With `async_sessionmaker` and `await db.execute(...)`, database queries don't block the event loop — allowing FastAPI to handle thousands of concurrent connections without threads. The asyncpg driver provides the async PostgreSQL wire protocol.
Why it matters for AI APIs
FastAPI is async-native. Mixing sync database calls in an async handler blocks the event loop and destroys concurrency. SQLAlchemy 2.0 async + asyncpg is the correct pairing: your API stays fully async from HTTP handler to database query, maximizing throughput under load.
In FastAPI AI Kit
The kit ships with SQLAlchemy 2.0 async: `AsyncSession`, `async_sessionmaker`, `AsyncEngine`, and `asyncpg` driver. All models use the 2.0 `Mapped[...]` annotation style. The `get_db()` dependency yields async sessions and handles commit/rollback/close.
