{"id":"1f71755d-584e-434c-931a-84e7ef1e48df","shortId":"gJVAWY","kind":"skill","title":"python-peewee","tagline":"Use when working with Peewee ORM patterns, especially DatabaseProxy setup, scoped connection/transaction handling, and SQLite-based tests.","description":"# Python Peewee\n\n## Overview\n\nUse Peewee with `DatabaseProxy`, scoped connection handling, explicit transactions, and isolated SQLite tests. Core principle: initialize the database at the boundary, then keep models and tests deterministic.\n\n## Use When\n\n- Defining Peewee models or a shared `BaseModel`.\n- Wiring `DatabaseProxy` for app and test databases.\n- Choosing `connection_context()` vs `atomic()`.\n- Writing SQLite-backed fixtures for model tests.\n\n## Quick Reference\n\n| Need | Pattern |\n| --- | --- |\n| Deferred database binding | `DatabaseProxy()` |\n| Model base class | `class BaseModel(Model)` with `Meta.database` |\n| Scoped connection | `with db.connection_context():` |\n| Transactional writes | `with db.atomic():` |\n| SQLite tests | temporary `SqliteDatabase` fixture |\n\n## Workflow\n\n1. Define one `DatabaseProxy` and one `BaseModel` for the model graph.\n2. Initialize the proxy once at the app/test boundary.\n3. Use `connection_context()` to open and close connections for scoped work.\n4. Use `atomic()` around write units that must commit or roll back together.\n5. In tests, bind the proxy to an isolated SQLite database and create/drop tables inside the fixture.\n\n## Setup\n\n### DatabaseProxy & BaseModel\n\n```python\nfrom peewee import DatabaseProxy, Model\n\ndb_proxy = DatabaseProxy()\n\nclass BaseModel(Model):\n    class Meta:\n        database = db_proxy\n```\n\n### Initialize DB\n\n```python\nfrom peewee import SqliteDatabase\n\ndb = SqliteDatabase(\"app.db\", pragmas={\"foreign_keys\": 1})\ndb_proxy.initialize(db)\n```\n\n## Connections and Transactions\n\n### Read (no transaction)\n\n```python\nwith db_proxy.obj.connection_context():\n    rows = MyModel.select().limit(100)\n```\n\n### Write (atomic)\n\n```python\nwith db_proxy.obj.atomic():\n    a.save()\n    b.save()\n```\n\n### Combined\n\n```python\ndb = db_proxy.obj\nwith db.connection_context():\n    with db.atomic():\n        ...\n```\n\nUse `connection_context()` for scoped connections (open/close).\nUse `atomic()` for atomic writes (BEGIN/COMMIT/ROLLBACK).\n\n## SQLite Test Fixture\n\n```python\nimport pytest\nfrom peewee import SqliteDatabase\n\n@pytest.fixture\ndef test_db(tmp_path):\n    db = SqliteDatabase(str(tmp_path / \"test.db\"))\n    db_proxy.initialize(db)\n    with db.connection_context():\n        db.create_tables([MyModel])\n    yield db\n    with db.connection_context():\n        db.drop_tables([MyModel])\n```\n\nUse in function-based pytest tests:\n\n```python\ndef test_create_user(test_db):\n    with test_db.atomic():\n        user = User.create(name=\"Ada\")\n\n    assert User.get_by_id(user.id).name == \"Ada\"\n```\n\n## Common Mistakes\n\n- Querying models before `db_proxy.initialize(db)` has run.\n- Holding one global open connection for the whole process when scoped connections would be clearer.\n- Using `atomic()` as a substitute for opening a connection in code paths that also need explicit connection lifetime.\n- Reusing a persistent app database in tests.\n\n## Red Flags\n\n- Tests that depend on table state from previous tests.\n- Peewee models bound directly to a production database in module import code.\n- Write operations performed without a transaction boundary.","tags":["python","peewee","skills","narumiruna","agent-skills"],"capabilities":["skill","source-narumiruna","skill-python-peewee","topic-agent-skills"],"categories":["skills"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/narumiruna/skills/python-peewee","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add narumiruna/skills","source_repo":"https://github.com/narumiruna/skills","install_from":"skills.sh"}},"qualityScore":"0.453","qualityRationale":"deterministic score 0.45 from registry signals: · indexed on github topic:agent-skills · 7 github stars · SKILL.md body (3,117 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:13:47.129Z","embedding":null,"createdAt":"2026-05-18T19:13:47.129Z","updatedAt":"2026-05-18T19:13:47.129Z","lastSeenAt":"2026-05-18T19:13:47.129Z","tsv":"'1':112,207 '100':223 '2':123 '3':132 '4':144 '5':157 'a.save':229 'ada':310,317 'also':355 'app':64,363 'app.db':203 'app/test':130 'around':147 'assert':311 'atom':72,146,225,248,250,343 'b.save':230 'back':76,155 'base':20,90,295 'basemodel':60,93,118,176,187 'begin/commit/rollback':252 'bind':87,160 'bound':380 'boundari':45,131,396 'choos':68 'class':91,92,186,189 'clearer':341 'close':139 'code':352,389 'combin':231 'commit':152 'common':318 'connect':30,69,98,134,140,210,241,245,331,338,350,358 'connection/transaction':15 'context':70,101,135,219,237,242,279,287 'core':38 'creat':301 'create/drop':169 'databas':42,67,86,167,191,364,385 'databaseproxi':12,28,62,88,115,175,181,185 'db':183,192,195,201,209,233,266,269,276,284,304,324 'db.atomic':105,239 'db.connection':100,236,278,286 'db.create':280 'db.drop':288 'db_proxy.initialize':208,275,323 'db_proxy.obj':234 'db_proxy.obj.atomic':228 'db_proxy.obj.connection':218 'def':264,299 'defer':85 'defin':54,113 'depend':371 'determinist':51 'direct':381 'especi':11 'explicit':32,357 'fixtur':77,110,173,255 'flag':368 'foreign':205 'function':294 'function-bas':293 'global':329 'graph':122 'handl':16,31 'hold':327 'id':314 'import':180,199,257,261,388 'initi':40,124,194 'insid':171 'isol':35,165 'keep':47 'key':206 'lifetim':359 'limit':222 'meta':190 'meta.database':96 'mistak':319 'model':48,56,79,89,94,121,182,188,321,379 'modul':387 'must':151 'mymodel':282,290 'mymodel.select':221 'name':309,316 'need':83,356 'one':114,117,328 'open':137,330,348 'open/close':246 'oper':391 'orm':9 'overview':24 'path':268,273,353 'pattern':10,84 'peewe':3,8,23,26,55,179,198,260,378 'perform':392 'persist':362 'pragma':204 'previous':376 'principl':39 'process':335 'product':384 'proxi':126,162,184,193 'pytest':258,296 'pytest.fixture':263 'python':2,22,177,196,216,226,232,256,298 'python-peewe':1 'queri':320 'quick':81 'read':213 'red':367 'refer':82 'reus':360 'roll':154 'row':220 'run':326 'scope':14,29,97,142,244,337 'setup':13,174 'share':59 'skill' 'skill-python-peewee' 'source-narumiruna' 'sqlite':19,36,75,106,166,253 'sqlite-back':74 'sqlite-bas':18 'sqlitedatabas':109,200,202,262,270 'state':374 'str':271 'substitut':346 'tabl':170,281,289,373 'temporari':108 'test':21,37,50,66,80,107,159,254,265,297,300,303,366,369,377 'test.db':274 'test_db.atomic':306 'tmp':267,272 'togeth':156 'topic-agent-skills' 'transact':33,102,212,215,395 'unit':149 'use':4,25,52,133,145,240,247,291,342 'user':302,307 'user.create':308 'user.get':312 'user.id':315 'vs':71 'whole':334 'wire':61 'without':393 'work':6,143 'workflow':111 'would':339 'write':73,103,148,224,251,390 'yield':283","prices":[{"id":"d7e474ff-73d4-4222-90d3-d33b3143c97c","listingId":"1f71755d-584e-434c-931a-84e7ef1e48df","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"narumiruna","category":"skills","install_from":"skills.sh"},"createdAt":"2026-05-18T19:13:47.129Z"}],"sources":[{"listingId":"1f71755d-584e-434c-931a-84e7ef1e48df","source":"github","sourceId":"narumiruna/skills/python-peewee","sourceUrl":"https://github.com/narumiruna/skills/tree/main/skills/python-peewee","isPrimary":false,"firstSeenAt":"2026-05-18T19:13:47.129Z","lastSeenAt":"2026-05-18T19:13:47.129Z"}],"details":{"listingId":"1f71755d-584e-434c-931a-84e7ef1e48df","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"narumiruna","slug":"python-peewee","github":{"repo":"narumiruna/skills","stars":7,"topics":["agent-skills"],"license":"mit","html_url":"https://github.com/narumiruna/skills","pushed_at":"2026-05-17T11:15:28Z","description":null,"skill_md_sha":"4274e5e615af85f091ee589ade5bc50f0802c26c","skill_md_path":"skills/python-peewee/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/narumiruna/skills/tree/main/skills/python-peewee"},"layout":"multi","source":"github","category":"skills","frontmatter":{"name":"python-peewee","description":"Use when working with Peewee ORM patterns, especially DatabaseProxy setup, scoped connection/transaction handling, and SQLite-based tests."},"skills_sh_url":"https://skills.sh/narumiruna/skills/python-peewee"},"updatedAt":"2026-05-18T19:13:47.129Z"}}