Framework Integration

Advanced Alchemy integrates with multiple Python web frameworks.

Overview

Advanced Alchemy provides framework-specific extensions for:

Litestar

Async web framework integration

Litestar Integration
FastAPI

Async web framework integration

FastAPI Integration
Flask

Sync web framework integration

Flask Integration
Sanic

Async web framework integration

https://sanicframework.org/
Starlette

Async web framework integration

https://www.starlette.io/

Framework Comparison

Framework Characteristics

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