A carefully crafted, thoroughly tested, optimized companion library for SQLAlchemy
A carefully crafted, thoroughly tested, optimized companion library for SQLAlchemy
Check out the project documentation for more information.
A carefully crafted, thoroughly tested, optimized companion library for SQLAlchemy, offering:
SQLModel table=True models directly with repositories and servicesFile Object data type for storing objects:
uuid-utils when installed, otherwise native in Python 3.14+, with UUID4 fallback on older versions).fastnanoid (install with the nanoid extra)pgcrypto for PostgreSQL and the Fernet implementation from cryptography for other databasesArgon2, Passlib, and Pwdlib with automatic salt generation and rehash-on-verify for transparent hash upgrades on loginpyotp (install with the pyotp extra)LIKE, IN, IS NULL/IS NOT NULL, and dates before and/or after.pip install advanced-alchemy[!IMPORTANT]
Check out the installation guide in our official documentation!
Advanced Alchemy includes a set of asynchronous and synchronous repository classes for easy CRUD operations on your SQLAlchemy models.
Click to expand the example
…For a full standalone example, see the sample here
Advanced Alchemy includes an additional service class to make working with a repository easier. This class is designed to accept data as a dictionary or SQLAlchemy model, and it will handle the type conversions for you.
Here's the same example from above but using a service to create the data:
…Advanced Alchemy works with nearly all Python web frameworks. Several helpers for popular libraries are included, and additional PRs to support others are welcomed.
Advanced Alchemy is the official SQLAlchemy integration for Litestar.
In addition to installing with pip install advanced-alchemy,
it can also be installed as a Litestar extra with pip install litestar[sqlalchemy].
Litestar Example
from litestar import Litestar
from litestar.plugins.sqlalchemy import SQLAlchemyPlugin, SQLAlchemyAsyncConfig
# alternately...
# from advanced_alchemy.extensions.litestar import SQLAlchemyAsyncConfig, SQLAlchemyPlugin
alchemy = SQLAlchemyPlugin(
config=SQLAlchemyAsyncConfig(connection_string="sqlite+aiosqlite:///test.sqlite"),
)
app = Litestar(plugins=[alchemy])For a full Litestar example, check here
Flask Example
from flask import Flask
from advanced_alchemy.extensions.flask import AdvancedAlchemy, SQLAlchemySyncConfig
app = Flask(__name__)
alchemy = AdvancedAlchemy(
config=SQLAlchemySyncConfig(connection_string="duckdb:///:memory:"), app=app,
)For a full Flask example, see here
FastAPI Example
from advanced_alchemy.extensions.fastapi import AdvancedAlchemy, SQLAlchemyAsyncConfig
from fastapi import FastAPI
app = FastAPI()
alchemy = AdvancedAlchemy(
config=SQLAlchemyAsyncConfig(connection_string="sqlite+aiosqlite:///test.sqlite"), app=app,
)For a full FastAPI example with optional CLI integration, see here
Pre-built Example Apps
from advanced_alchemy.extensions.starlette import AdvancedAlchemy, SQLAlchemyAsyncConfig
from starlette.applications import Starlette
app = Starlette()
alchemy = AdvancedAlchemy(
config=SQLAlchemyAsyncConfig(connection_string="sqlite+aiosqlite:///test.sqlite"), app=app,
)Pre-built Example Apps
from sanic import Sanic
from sanic_ext import Extend
from advanced_alchemy.extensions.sanic import AdvancedAlchemy, SQLAlchemyAsyncConfig
app = Sanic("AlchemySanicApp")
alchemy = AdvancedAlchemy(
sqlalchemy_config=SQLAlchemyAsyncConfig(connection_string="sqlite+aiosqlite:///test.sqlite"),
)
Extend.register(alchemy)All Litestar Organization projects will always be a community-centered, available for contributions of any size.
Before contributing, please review the contribution guide.
If you have any questions, reach out to us on Discord, our org-wide GitHub discussions page, or the project-specific GitHub discussions page.
An official Litestar Organization Project
No open issues yet, or sync has not completed.