sqlalchemy-async-session-factory¶
Factory functions for async SQLAlchemy engine and session management with connection pooling.
Installation¶
pip install sqlalchemy-async-session-factory
Public API¶
Function |
Purpose |
|---|---|
|
Create async engine with pool config |
|
Create |
|
FastAPI |
|
Suppress pool warnings during shutdown |
|
Pool event handlers (monitoring) |
Usage¶
from sqlalchemy_async_session_factory import (
create_async_engine_with_pool,
create_async_session_maker,
create_session_dependency,
)
engine = create_async_engine_with_pool("postgresql+asyncpg://...")
session_maker = create_async_session_maker(engine)
get_session = create_session_dependency(session_maker)
# FastAPI dependency injection
@app.get("/users")
async def list_users(session=Depends(get_session)):
...