GitHub CopilotTypeScriptDatabase
Python + SQLAlchemy Rules for GitHub Copilot
GitHub Copilot coding rules for Python + SQLAlchemy projects. Best practices, patterns, and conventions.
.github/copilot-instructions.md
# Python + SQLAlchemy Rules for GitHub Copilot
# Python + SQLAlchemy 2.0 Rules
## Modern SQLAlchemy
- Use SQLAlchemy 2.0+ syntax — not 1.x legacy patterns
- Declarative mapped classes with `mapped_column`
- Type annotations on all column mappings
- Async engine with asyncpg for async applications
```python
from sqlalchemy.orm import Mapped, mapped_column, DeclarativeBase
class Base(DeclarativeBase):
pass
class User(Base):
__tablename__ = "users"
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(unique=True, index=True)
name: Mapped[str | None]
```
## Session Management
- One session per request — use dependency injection
- Context managers for session lifecycle
- Async sessions for async applications
## Query Patterns
- `select()` function — not `session.query()`
- Explicit `joinedload` / `selectinload` to avoid N+1
- Paginate with `offset` / `limit` or keyset pagination
## Migrations
- Alembic for all schema changes
- Never modify existing migration files
- Autogenerate migrations then review before applyingHow to use with GitHub Copilot
Create `.github/copilot-instructions.md` in your repository. GitHub Copilot uses these to customize suggestions across your whole repo.
#copilot#typescript#python-sqlalchemy#ai-coding-rules
Related Rules
TypeScript Cursor Rules
CursorTypeScript
Cursor rules for TypeScript: enforce strict mode, eliminate any types, and write type-safe code with these .cursorrules configurations.
Code Style
typescript · strictCopy Ready
TypeScript Windsurf Rules
WindsurfTypeScript
Windsurf rules for TypeScript: strict type safety, functional patterns, and modern TypeScript conventions.
Code Style
typescript · windsurfCopy Ready
TypeScript GitHub Copilot Instructions
GitHub CopilotTypeScript
GitHub Copilot custom instructions for TypeScript: strict types, modern patterns, and team conventions.
Code Style
typescript · copilotCopy Ready
React GitHub Copilot Instructions
GitHub CopilotReact
GitHub Copilot instructions for React: hooks, patterns, and best practices for modern React apps.
Code Style
react · copilotCopy Ready