python-database-patterns — python-database-patterns setup for AI agents python-database-patterns, PyAgent, community, python-database-patterns setup for AI agents, ide skills, Claude Code, Cursor, Windsurf

v1.0.0
GitHub

About this Skill

Perfect for Python Database Agents needing advanced SQLAlchemy 2.0 integration for database management and optimization. python-database-patterns is a skill that utilizes SQLAlchemy 2.0 to implement best practices for database management in Python applications.

Features

Utilizes SQLAlchemy 2.0 for database operations
Supports DeclarativeBase for database table definitions
Enables usage of Mapped and mapped_column for data type definitions
Allows for creation of database sessions using Session from sqlalchemy.orm
Implements database best practices for optimal performance

# Core Topics

UndiFineD UndiFineD
[4]
[0]
Updated: 3/6/2026

Agent Capability Analysis

The python-database-patterns skill by UndiFineD is an open-source community AI agent skill for Claude Code and other IDE workflows, helping agents execute tasks with better context, repeatability, and domain-specific guidance. Optimized for python-database-patterns setup for AI agents.

Ideal Agent Persona

Perfect for Python Database Agents needing advanced SQLAlchemy 2.0 integration for database management and optimization.

Core Value

Empowers agents to interact with databases using SQLAlchemy 2.0, providing declarative base classes, mapped columns, and session management, while following database best practices and utilizing libraries like sqlalchemy.orm.

Capabilities Granted for python-database-patterns

Automating database schema creation
Generating database queries using select and mapped_column
Debugging database connections with create_engine and Session

! Prerequisites & Limits

  • Requires SQLAlchemy 2.0 installation
  • Python 3.x compatibility required
Labs Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

python-database-patterns

Install python-database-patterns, an AI agent skill for AI agent workflows and automation. Works with Claude Code, Cursor, and Windsurf with one-command...

SKILL.md
Readonly

Python Database Patterns

SQLAlchemy 2.0 and database best practices.

SQLAlchemy 2.0 Basics

python
1from sqlalchemy import create_engine, select 2from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, Session 3 4class Base(DeclarativeBase): 5 pass 6 7class User(Base): 8 __tablename__ = "users" 9 10 id: Mapped[int] = mapped_column(primary_key=True) 11 name: Mapped[str] = mapped_column(String(100)) 12 email: Mapped[str] = mapped_column(String(255), unique=True) 13 is_active: Mapped[bool] = mapped_column(default=True) 14 15# Create engine and tables 16engine = create_engine("postgresql://user:pass@localhost/db") 17Base.metadata.create_all(engine) 18 19# Query with 2.0 style 20with Session(engine) as session: 21 stmt = select(User).where(User.is_active == True) 22 users = session.execute(stmt).scalars().all()

Async SQLAlchemy

python
1from sqlalchemy.ext.asyncio import ( 2 AsyncSession, 3 async_sessionmaker, 4 create_async_engine, 5) 6from sqlalchemy import select 7 8# Async engine 9engine = create_async_engine( 10 "postgresql+asyncpg://user:pass@localhost/db", 11 echo=False, 12 pool_size=5, 13 max_overflow=10, 14) 15 16# Session factory 17async_session = async_sessionmaker(engine, expire_on_commit=False) 18 19# Usage 20async with async_session() as session: 21 result = await session.execute(select(User).where(User.id == 1)) 22 user = result.scalar_one_or_none()

Model Relationships

python
1from sqlalchemy import ForeignKey 2from sqlalchemy.orm import relationship, Mapped, mapped_column 3 4class User(Base): 5 __tablename__ = "users" 6 7 id: Mapped[int] = mapped_column(primary_key=True) 8 name: Mapped[str] 9 10 # One-to-many 11 posts: Mapped[list["Post"]] = relationship(back_populates="author") 12 13class Post(Base): 14 __tablename__ = "posts" 15 16 id: Mapped[int] = mapped_column(primary_key=True) 17 title: Mapped[str] 18 author_id: Mapped[int] = mapped_column(ForeignKey("users.id")) 19 20 # Many-to-one 21 author: Mapped["User"] = relationship(back_populates="posts")

Common Query Patterns

python
1from sqlalchemy import select, and_, or_, func 2 3# Basic select 4stmt = select(User).where(User.is_active == True) 5 6# Multiple conditions 7stmt = select(User).where( 8 and_( 9 User.is_active == True, 10 User.age >= 18 11 ) 12) 13 14# OR conditions 15stmt = select(User).where( 16 or_(User.role == "admin", User.role == "moderator") 17) 18 19# Ordering and limiting 20stmt = select(User).order_by(User.created_at.desc()).limit(10) 21 22# Aggregates 23stmt = select(func.count(User.id)).where(User.is_active == True) 24 25# Joins 26stmt = select(User, Post).join(Post, User.id == Post.author_id) 27 28# Eager loading 29from sqlalchemy.orm import selectinload 30stmt = select(User).options(selectinload(User.posts))

FastAPI Integration

python
1from fastapi import Depends, FastAPI 2from sqlalchemy.ext.asyncio import AsyncSession 3from typing import Annotated 4 5async def get_db() -> AsyncGenerator[AsyncSession, None]: 6 async with async_session() as session: 7 yield session 8 9DB = Annotated[AsyncSession, Depends(get_db)] 10 11@app.get("/users/{user_id}") 12async def get_user(user_id: int, db: DB): 13 result = await db.execute(select(User).where(User.id == user_id)) 14 user = result.scalar_one_or_none() 15 if not user: 16 raise HTTPException(status_code=404) 17 return user

Quick Reference

OperationSQLAlchemy 2.0 Style
Select allselect(User)
Filter.where(User.id == 1)
First.scalar_one_or_none()
All.scalars().all()
Countselect(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-patterns - Mapped types and annotations
  • python-async-patterns - Async database sessions

Related Skills:

  • python-fastapi-patterns - Dependency injection for DB sessions
  • python-pytest-patterns - Database fixtures and testing

FAQ & Installation Steps

These questions and steps mirror the structured data on this page for better search understanding.

? Frequently Asked Questions

What is python-database-patterns?

Perfect for Python Database Agents needing advanced SQLAlchemy 2.0 integration for database management and optimization. python-database-patterns is a skill that utilizes SQLAlchemy 2.0 to implement best practices for database management in Python applications.

How do I install python-database-patterns?

Run the command: npx killer-skills add UndiFineD/PyAgent. It works with Cursor, Windsurf, VS Code, Claude Code, and 19+ other IDEs.

What are the use cases for python-database-patterns?

Key use cases include: Automating database schema creation, Generating database queries using select and mapped_column, Debugging database connections with create_engine and Session.

Which IDEs are compatible with python-database-patterns?

This skill is compatible with Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer. Use the Killer-Skills CLI for universal one-command installation.

Are there any limitations for python-database-patterns?

Requires SQLAlchemy 2.0 installation. Python 3.x compatibility required.

How To Install

  1. 1. Open your terminal

    Open the terminal or command line in your project directory.

  2. 2. Run the install command

    Run: npx killer-skills add UndiFineD/PyAgent. The CLI will automatically detect your IDE or AI agent and configure the skill.

  3. 3. Start using the skill

    The skill is now active. Your AI agent can use python-database-patterns immediately in the current project.

Related Skills

Looking for an alternative to python-database-patterns or another community skill for your workflow? Explore these related open-source skills.

View All

widget-generator

Logo of f
f

f.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source — self-host for your organization with complete privacy.

149.6k
0
AI

flags

Logo of vercel
vercel

flags is a Next.js feature management skill that enables developers to efficiently add or modify framework feature flags, streamlining React application development.

138.4k
0
Browser

zustand

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
AI

data-fetching

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
AI