advanced-alchemy

Implements SQLAlchemy repository, service, and migration patterns with Advanced Alchemy.

Updated Aug 17, 2026
One-click install
npx skills add https://github.com/renjianguo666/litecms --skill advanced-alchemy-renjianguo666
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: advanced-alchemy
Source: https://github.com/renjianguo666/litecms/tree/main/.agents/skills/advanced-alchemy
Command: npx skills add https://github.com/renjianguo666/litecms --skill advanced-alchemy-renjianguo666

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires advanced-alchemy, sqlalchemy, alembic, and includes references (resource) components.

What problem does it solve? Building database layers with raw SQLAlchemy requires repetitive boilerplate for base models, audit columns, repositories, session wiring, and migrations. This Skill guides the creation of Advanced Alchemy models, repositories, services, and Alembic migrations with correct framework integration. ## Core Features & Use Cases - Model and Base Class Selection: Choose between UUIDAuditBase, UUIDv7AuditBase, BigIntAuditBase, NanoIDAuditBase, and mixins like SlugKey, UniqueMixin, and SentinelMixin. - Repository and Service Layer: Build SQLAlchemyAsyncRepository and SQLAlchemyAsyncRepositoryService classes with lifecycle hooks, match_fields, filters, and OffsetPagination. - Framework Integration: Wire sessions and commit modes into Litestar, FastAPI, Flask, Sanic, or Starlette using the matching extension guide. - Use Case: When adding a new Tag entity to a FastAPI app, generate the model, repository, service with an inner Repo class, wire it via provide_service, and create the Alembic migration. ## Quick Start Ask the AI to create an Advanced Alchemy model, repository, and service for a new entity in your Litestar or FastAPI project.

Frequently Asked Questions about advanced-alchemy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a model, repository, and service with Advanced Alchemy?

Define a model inheriting from UUIDAuditBase with Mapped column annotations, create a SQLAlchemyAsyncRepository subclass with model_type set, then build a SQLAlchemyAsyncRepositoryService with an inner Repo class and repository_type pointing to it. Set match_fields if you use upsert.

Advanced Alchemy vs raw SQLAlchemy: which should I use?

Advanced Alchemy adds opinionated base classes, audit timestamps, repositories, services, and framework plugins on top of SQLAlchemy 2.0. Use it when you want a complete CRUD layer; use raw SQLAlchemy or sqlspec when you need direct SQL control or non-SQLAlchemy drivers.

Does Advanced Alchemy work with FastAPI and Flask?

Yes, Advanced Alchemy ships first-party extensions for Litestar, FastAPI, Flask, Sanic, and Starlette. Each extension provides session lifecycle management, commit modes, and an Alembic CLI integration, with framework-specific DI patterns like Depends for FastAPI.

Why should Advanced Alchemy model modules avoid from __future__ import annotations?

SQLAlchemy 2.0 introspects Mapped[...] annotations at class-creation time, and postponed annotation evaluation breaks that introspection. Model modules must omit the future import, while consumer modules like handlers, services, and tests may use it freely.

How do I add pagination and filtering to Advanced Alchemy list endpoints?

Pass filter objects like LimitOffset, SearchFilter, CollectionFilter, OrderBy, and BeforeAfter to service list_and_count methods. Return results via to_schema as OffsetPagination, which includes items, total, limit, and offset for frontend tables.

When should I use commit_mode autocommit versus manual?

Use autocommit for standard CRUD endpoints where a 2xx response means the work succeeded, and autocommit_include_redirect for POST-then-redirect flows. Use manual when a handler has multiple commit points or must persist writes before returning an error status.