{"id":"b1a1450f-cd3a-4dce-8dfa-d07e39300862","shortId":"aBejf7","kind":"skill","title":"python-sqlalchemy","tagline":"SQLAlchemy ORM patterns for Python database access. Use when defining models, writing queries, implementing upserts, working with JSON columns, or managing database sessions.","description":"# SQLAlchemy ORM Patterns\n\nModern SQLAlchemy 2.0+ patterns for database access in Python applications.\n\n## Model Definition\n\n```python\nfrom sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column\nfrom sqlalchemy import String\nfrom uuid import UUID\nfrom decimal import Decimal\n\nclass Base(DeclarativeBase):\n    pass\n\nclass ProductModel(Base):\n    __tablename__ = \"products\"\n\n    id: Mapped[UUID] = mapped_column(primary_key=True)\n    name: Mapped[str] = mapped_column(String(100))\n    price: Mapped[Decimal]\n    in_stock: Mapped[bool] = mapped_column(default=True)\n```\n\n## Session Management\n\n```python\nfrom sqlalchemy import create_engine\nfrom sqlalchemy.orm import sessionmaker\n\nengine = create_engine(\"postgresql://user:pass@localhost/db\")\nSessionLocal = sessionmaker(bind=engine)\n\ndef get_db():\n    db = SessionLocal()\n    try:\n        yield db\n    finally:\n        db.close()\n```\n\n## Query Patterns\n\n```python\n# Select\nstmt = select(ProductModel).where(ProductModel.price > 100)\nproducts = session.execute(stmt).scalars().all()\n\n# Filter\nproducts = session.query(ProductModel).filter(ProductModel.in_stock == True).all()\n\n# Get by ID\nproduct = session.get(ProductModel, product_id)\n\n# Count\ncount = session.query(ProductModel).count()\n```\n\n## Upsert\n\n```python\nfrom sqlalchemy.dialects.postgresql import insert\n\nstmt = insert(ProductModel).values(\n    id=product_id,\n    name=\"Widget\",\n    price=9.99,\n)\n\n# On conflict, update\nstmt = stmt.on_conflict_do_update(\n    index_elements=[\"id\"],\n    set_={\"name\": stmt.excluded.name, \"price\": stmt.excluded.price},\n)\n\nsession.execute(stmt)\nsession.commit()\n```\n\n## Relationships\n\n```python\nfrom sqlalchemy.orm import relationship\n\nclass UserModel(Base):\n    __tablename__ = \"users\"\n    id: Mapped[int] = mapped_column(primary_key=True)\n    orders: Mapped[list[\"OrderModel\"]] = relationship(back_populates=\"user\")\n\nclass OrderModel(Base):\n    __tablename__ = \"orders\"\n    id: Mapped[int] = mapped_column(primary_key=True)\n    user_id: Mapped[int] = mapped_column(ForeignKey(\"users.id\"))\n    user: Mapped[\"UserModel\"] = relationship(back_populates=\"orders\")\n```\n\n## JSON Columns\n\n```python\nfrom sqlalchemy import JSON\n\nclass ConfigModel(Base):\n    __tablename__ = \"configs\"\n    id: Mapped[int] = mapped_column(primary_key=True)\n    settings: Mapped[dict] = mapped_column(JSON)\n\n# Query JSON field\nconfigs = session.query(ConfigModel).filter(\n    ConfigModel.settings[\"theme\"] == \"dark\"\n).all()\n```\n\nSee references/ for model patterns, query optimization, and async SQLAlchemy.","tags":["python","sqlalchemy","atelier","martinffx","agent-skills","agentic-coding","anthropic","claude-code","claude-skills","code-review","codex","codex-skill"],"capabilities":["skill","source-martinffx","skill-python-sqlalchemy","topic-agent-skills","topic-agentic-coding","topic-anthropic","topic-claude-code","topic-claude-skills","topic-code-review","topic-codex","topic-codex-skill","topic-opencode","topic-prompt-engineering","topic-sdd","topic-spec-driven-development"],"categories":["atelier"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/martinffx/atelier/python-sqlalchemy","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add martinffx/atelier","source_repo":"https://github.com/martinffx/atelier","install_from":"skills.sh"}},"qualityScore":"0.461","qualityRationale":"deterministic score 0.46 from registry signals: · indexed on github topic:agent-skills · 23 github stars · SKILL.md body (2,526 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-18T19:05:23.622Z","embedding":null,"createdAt":"2026-05-10T07:03:12.412Z","updatedAt":"2026-05-18T19:05:23.622Z","lastSeenAt":"2026-05-18T19:05:23.622Z","tsv":"'100':85,138 '2.0':32 '9.99':182 'access':10,36 'applic':39 'async':302 'back':226,254 'base':63,68,210,231,266 'bind':117 'bool':92 'class':62,66,208,229,264 'column':22,49,75,83,94,217,238,247,258,273,281 'config':268,286 'configmodel':265,288 'configmodel.settings':290 'conflict':184,188 'count':161,162,165 'creat':103,110 'dark':292 'databas':9,25,35 'db':121,122,126 'db.close':128 'decim':59,61,88 'declarativebas':46,64 'def':119 'default':95 'defin':13 'definit':41 'dict':279 'element':192 'engin':104,109,111,118 'field':285 'filter':144,148,289 'final':127 'foreignkey':248 'get':120,153 'id':71,155,160,176,178,193,213,234,243,269 'implement':17 'import':45,52,56,60,102,107,170,206,262 'index':191 'insert':171,173 'int':215,236,245,271 'json':21,257,263,282,284 'key':77,219,240,275 'list':223 'localhost/db':114 'manag':24,98 'map':47,48,72,74,80,82,87,91,93,214,216,222,235,237,244,246,251,270,272,278,280 'model':14,40,297 'modern':30 'name':79,179,195 'optim':300 'order':221,233,256 'ordermodel':224,230 'orm':5,28 'pass':65,113 'pattern':6,29,33,130,298 'popul':227,255 'price':86,181,197 'primari':76,218,239,274 'product':70,139,145,156,159,177 'productmodel':67,135,147,158,164,174 'productmodel.in':149 'productmodel.price':137 'python':2,8,38,42,99,131,167,203,259 'python-sqlalchemi':1 'queri':16,129,283,299 'refer':295 'relationship':202,207,225,253 'scalar':142 'see':294 'select':132,134 'session':26,97 'session.commit':201 'session.execute':140,199 'session.get':157 'session.query':146,163,287 'sessionloc':115,123 'sessionmak':108,116 'set':194,277 'skill' 'skill-python-sqlalchemy' 'source-martinffx' 'sqlalchemi':3,4,27,31,51,101,261,303 'sqlalchemy.dialects.postgresql':169 'sqlalchemy.orm':44,106,205 'stmt':133,141,172,186,200 'stmt.excluded.name':196 'stmt.excluded.price':198 'stmt.on':187 'stock':90,150 'str':81 'string':53,84 'tablenam':69,211,232,267 'theme':291 'topic-agent-skills' 'topic-agentic-coding' 'topic-anthropic' 'topic-claude-code' 'topic-claude-skills' 'topic-code-review' 'topic-codex' 'topic-codex-skill' 'topic-opencode' 'topic-prompt-engineering' 'topic-sdd' 'topic-spec-driven-development' 'tri':124 'true':78,96,151,220,241,276 'updat':185,190 'upsert':18,166 'use':11 'user':112,212,228,242,250 'usermodel':209,252 'users.id':249 'uuid':55,57,73 'valu':175 'widget':180 'work':19 'write':15 'yield':125","prices":[{"id":"2b6774f2-9145-41bf-aa62-5198fa237808","listingId":"b1a1450f-cd3a-4dce-8dfa-d07e39300862","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"martinffx","category":"atelier","install_from":"skills.sh"},"createdAt":"2026-05-10T07:03:12.412Z"}],"sources":[{"listingId":"b1a1450f-cd3a-4dce-8dfa-d07e39300862","source":"github","sourceId":"martinffx/atelier/python-sqlalchemy","sourceUrl":"https://github.com/martinffx/atelier/tree/main/skills/python-sqlalchemy","isPrimary":false,"firstSeenAt":"2026-05-10T07:03:12.412Z","lastSeenAt":"2026-05-18T19:05:23.622Z"}],"details":{"listingId":"b1a1450f-cd3a-4dce-8dfa-d07e39300862","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"martinffx","slug":"python-sqlalchemy","github":{"repo":"martinffx/atelier","stars":23,"topics":["agent-skills","agentic-coding","anthropic","claude-code","claude-skills","code-review","codex","codex-skill","opencode","prompt-engineering","sdd","spec-driven-development"],"license":"mit","html_url":"https://github.com/martinffx/atelier","pushed_at":"2026-05-18T06:56:45Z","description":"An atelier for Opencode, Claude Code, and other coding agents: spec-driven workflows, deep thinking, and code quality.","skill_md_sha":"fcecb6352ac5af66208194e0c838f8842c403cec","skill_md_path":"skills/python-sqlalchemy/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/martinffx/atelier/tree/main/skills/python-sqlalchemy"},"layout":"multi","source":"github","category":"atelier","frontmatter":{"name":"python-sqlalchemy","description":"SQLAlchemy ORM patterns for Python database access. Use when defining models, writing queries, implementing upserts, working with JSON columns, or managing database sessions."},"skills_sh_url":"https://skills.sh/martinffx/atelier/python-sqlalchemy"},"updatedAt":"2026-05-18T19:05:23.622Z"}}