advanced-alchemy-fastapi
SKILL.md
FastAPI
Execution Workflow
- Configure
SQLAlchemyAsyncConfigand attachAdvancedAlchemyto the FastAPI app. - Build request-scoped session dependencies with
Depends(alchemy.provide_session()). - Provide services through async generators and
Service.new(session=...)context managers. - Keep routers thin and return service-converted schema objects or paginated schema collections.
- Register routers only after the service and dependency layer is coherent.
Implementation Rules
- Use
AnnotatedplusDependsfor session and service injection to keep signatures explicit. - Set
commit_modeintentionally; do not rely on implicit transaction assumptions. - Keep
response_modelaligned with the schema returned byto_schema(). - Avoid passing ORM instances directly through FastAPI responses.
Example Pattern
from advanced_alchemy.extensions.fastapi import AdvancedAlchemy, AsyncSessionConfig, SQLAlchemyAsyncConfig
from fastapi import FastAPI
alchemy = AdvancedAlchemy(
config=SQLAlchemyAsyncConfig(
connection_string="sqlite+aiosqlite:///test.sqlite",
session_config=AsyncSessionConfig(expire_on_commit=False),
create_all=True,
commit_mode="autocommit",
),
app=FastAPI(),
)
Validation Checklist
- Confirm the session dependency is request-scoped and closes after each request.
- Confirm service providers yield the expected service type and release resources.
- Confirm response models match the schema conversion output.
- Confirm routers are mounted only once and startup or shutdown lifecycle is not duplicated.
Cross-Skill Handoffs
- Use
advanced-alchemy-routingfor CRUD endpoint shape. - Use
advanced-alchemy-servicesfor service-backed FastAPI handlers. - Use
advanced-alchemy-cliif the project needs Advanced Alchemy migration commands alongside the app.
Advanced Alchemy References
Weekly Installs
5
Repository
alti3/litestar-skillsGitHub Stars
5
First Seen
7 days ago
Security Audits
Installed on
cline5
gemini-cli5
github-copilot5
codex5
kimi-cli5
cursor5