Framework Integration¶
Advanced Alchemy integrates with multiple Python web frameworks.
Overview¶
Advanced Alchemy provides framework-specific extensions for:
Litestar (async)
FastAPI (async)
Flask (sync)
Sanic (async)
Starlette (async)
Framework Comparison¶
Framework |
Async Support |
Integration Method |
Session Management |
|---|---|---|---|
Litestar |
Yes |
SQLAlchemyPlugin |
Dependency injection |
FastAPI |
Yes |
AdvancedAlchemy extension |
Depends() |
Flask |
No (sync) |
AdvancedAlchemy extension |
Request context |
Quick Start¶
Litestar
from litestar import Litestar
from advanced_alchemy.extensions.litestar import SQLAlchemyPlugin, SQLAlchemyAsyncConfig
alchemy = SQLAlchemyPlugin(
config=SQLAlchemyAsyncConfig(connection_string="sqlite+aiosqlite:///test.sqlite"),
)
app = Litestar(plugins=[alchemy])
FastAPI
from fastapi import FastAPI
from advanced_alchemy.extensions.fastapi import AdvancedAlchemy, SQLAlchemyAsyncConfig
app = FastAPI()
alchemy = AdvancedAlchemy(
config=SQLAlchemyAsyncConfig(connection_string="sqlite+aiosqlite:///test.sqlite"),
app=app,
)
Flask
from flask import Flask
from advanced_alchemy.extensions.flask import AdvancedAlchemy, SQLAlchemySyncConfig
app = Flask(__name__)
alchemy = AdvancedAlchemy(
config=SQLAlchemySyncConfig(connection_string="sqlite:///test.sqlite"),
app=app,
)
Next Steps¶
Litestar Integration - Litestar integration details
FastAPI Integration - FastAPI integration details
Flask Integration - Flask integration details