python-database-ops skill
Implements SQLAlchemy 2.0 patterns, asynchronous database sessions, and model relationships in Python.
- GitHub stars
- 81
- Files
- 7
- Last commit
- Nov 7, 2026
- License
- MIT
- Allowed tools
- 3
What does the python-database-ops skill do?
python-database-ops implements SQLAlchemy 2.0 patterns, asynchronous database sessions, and model relationships in Python.
Summary generated from the skill's SKILL.md.
About the python-database-ops skill
Implementing SQLAlchemy 2.0 patterns and asynchronous database sessions is what this skill enables for Python developers. It provides the necessary structures for managing database interactions using modern ORM practices, including declarative base models, relationship mapping, and complex query construction. An agent should load this skill when a task involves designing database schemas, writing asynchronous queries, or setting up connection pools for PostgreSQL or SQLite.
The skill focuses on specific implementation details like the repository pattern, unit of work, and Alembic migrations. It supports asynchronous workflows using asyncpg or aiosqlite and provides patterns for integrating database sessions into FastAPI applications via dependency injection. By utilizing tools like selectinload for eager loading and various filtering functions, it helps produce clean, type-safe database code that adheres to SQLAlchemy 2.0 standards.
Written from the skill's SKILL.md. Every use case is checked against a quote from it.
How to install the python-database-ops skill
Each command copies the skill folder into the client's skills directory. Restart the client or start a new session to load it.Install the python-database-ops skill in Plugin
/plugin marketplace add 0xDarkMatter/claude-mods /plugin install claude-mods@claude-mods
Install the python-database-ops skill in Claude Code
~/.claude/skills/python-database-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-database-ops ~/.claude/skills/python-database-opsInstall the python-database-ops skill in Claude Code (project)
.claude/skills/python-database-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-database-ops .claude/skills/python-database-opsInstall the python-database-ops skill in Codex
~/.agents/skills/python-database-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-database-ops ~/.agents/skills/python-database-opsInstall the python-database-ops skill in Gemini CLI
~/.gemini/skills/python-database-ops/SKILL.md
$ npx degit 0xDarkMatter/claude-mods/skills/python-database-ops ~/.gemini/skills/python-database-opsInstall the python-database-ops skill in Claude.ai
npx degit 0xDarkMatter/claude-mods/skills/python-database-ops python-database-ops && zip -r python-database-ops.zip python-database-ops # claude.ai → Customize → Skills → + → Create skill → Upload a skill → python-database-ops.zip
Automated checks
Ran Nov 15, 2026Full report →Not verified yet. A skill needs a score of 80, no serious finding, and enough data for us to check. How checks work · What to fix for more points
- Source repository linked and reachable0xdarkmatter/claude-mods/skills/python-database-ops is public and reachablegithub.com/0xdarkmatter/claude-mods/tree/HEAD/skills/python- ↗Pass
- Open source license (OSI)MITspdx.org/licenses/MIT.html ↗Pass
- Commit or release in the last yearLast commit 2026-11-07github.com/0xdarkmatter/claude-mods/commits ↗Pass
- No download-and-run or credential theft in scriptsNo scripts in the skill folderPass
- No hidden instructions in SKILL.mdNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗Pass
- Pre-approved tools are scopedBash lets the agent run any shell command without askinggithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗Finding
- SKILL.md follows the Agent Skills formatValid name and description; says when to use it; 188 linesgithub.com/0xdarkmatter/claude-mods/blob/HEAD/skills/python- ↗Pass
SKILL.md
View on GitHubPython Database Patterns
SQLAlchemy 2.0 and database best practices.
SQLAlchemy 2.0 Basics
from sqlalchemy import create_engine, select
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, Session
class Base(DeclarativeBase):
pass
class User(Base):
__tablename__ = "users"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(100))
email: Mapped[str] = mapped_column(String(255), unique=True)
is_active: Mapped[bool] = mapped_column(default=True)
# Create engine and tables
engine = create_engine("postgresql://user:pass@localhost/db")
Base.metadata.create_all(engine)
# Query with 2.0 style
with Session(engine) as session:
stmt = select(User).where(User.is_active == True)
users = session.execute(stmt).scalars().all()
Async SQLAlchemy
from sqlalchemy.ext.asyncio import (
AsyncSession,
async_sessionmaker,
create_async_engine,
)
from sqlalchemy import select
# Async engine
engine = create_async_engine(
"postgresql+asyncpg://user:pass@localhost/db",
echo=False,
pool_size=5,
max_overflow=10,
)
# Session factory
async_session = async_sessionmaker(engine, expire_on_commit=False)
# Usage
async with async_session() as session:
result = await session.execute(select(User).where(User.id == 1))
user = result.scalar_one_or_none()
Model Relationships
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship, Mapped, mapped_column
class User(Base):
__tablename__ = "users"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
# One-to-many
posts: Mapped[list["Post"]] = relationship(back_populates="author")
class Post(Base):
__tablename__ = "posts"
id: Mapped[int] = mapped_column(primary_key=True)
title: Mapped[str]
author_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
# Many-to-one
author: Mapped["User"] = relationship(back_populates="posts")
Common Query Patterns
from sqlalchemy import select, and_, or_, func
# Basic select
stmt = select(User).where(User.is_active == True)
# Multiple conditions
stmt = select(User).where(
and_(
User.is_active == True,
User.age >= 18
)
)
# OR conditions
stmt = select(User).where(
or_(User.role == "admin", User.role == "moderator")
)
# Ordering and limiting
stmt = select(User).order_by(User.created_at.desc()).limit(10)
# Aggregates
stmt = select(func.count(User.id)).where(User.is_active == True)
# Joins
stmt = select(User, Post).join(Post, User.id == Post.author_id)
# Eager loading
from sqlalchemy.orm import selectinload
stmt = select(User).options(selectinload(User.posts))
FastAPI Integration
from fastapi import Depends, FastAPI
from sqlalchemy.ext.asyncio import AsyncSession
from typing import Annotated
async def get_db() -> AsyncGenerator[AsyncSession, None]:
async with async_session() as session:
yield session
DB = Annotated[AsyncSession, Depends(get_db)]
@app.get("/users/{user_id}")
async def get_user(user_id: int, db: DB):
result = await db.execute(select(User).where(User.id == user_id))
user = result.scalar_one_or_none()
if not user:
raise HTTPException(status_code=404)
return user
Quick Reference
| Operation | SQLAlchemy 2.0 Style |
|---|---|
| Select all | select(User) |
| Filter | .where(User.id == 1) |
| First | .scalar_one_or_none() |
| All | .scalars().all() |
| Count | select(func.count(User.id)) |
| Join | .join(Post) |
| Eager load | .options(selectinload(User.posts)) |
Additional Resources
./references/sqlalchemy-async.md- Async patterns, session management./references/connection-pooling.md- Pool configuration, health checks./references/transactions.md- Transaction patterns, isolation levels./references/migrations.md- Alembic setup, migration strategies
Assets
./assets/alembic.ini.template- Alembic configuration template
See Also
Prerequisites:
python-typing-ops- Mapped types and annotationspython-async-ops- Async database sessions
Related Skills:
python-fastapi-ops- Dependency injection for DB sessionspython-pytest-ops- Database fixtures and testing
Files in this skill
7python-database-ops skill questions
How do I install the python-database-ops skill in Claude Code?
Run npx degit 0xDarkMatter/claude-mods/skills/python-database-ops ~/.claude/skills/python-database-ops. Claude Code loads skills from ~/.claude/skills (all projects) or .claude/skills (one project) and uses a skill when its description matches the task.
Which clients can use the python-database-ops skill?
Any client that reads the Agent Skills format: Claude Code, Codex, Gemini CLI and claude.ai (upload as a ZIP). Scripts in the skill run only where the client allows code execution.
What are the compatibility requirements for this skill?
It requires SQLAlchemy 2.0+ and Python 3.10+. For asynchronous operations, you need asyncpg for PostgreSQL or aiosqlite.
How do I perform eager loading in SQLAlchemy 2.0?
You can use the selectinload option to eagerly load relationships.