[{"data":1,"prerenderedAt":2712},["ShallowReactive",2],{"page-\u002Fcli-runtime-systems-integration\u002Flocal-state-and-sqlite-in-python-clis\u002F":3,"content-directory":1868},{"id":4,"title":5,"body":6,"date":1852,"description":1853,"difficulty":1854,"draft":1855,"extension":1856,"meta":1857,"navigation":233,"path":1858,"seo":1859,"stem":1860,"tags":1861,"updated":1852,"__hash__":1867},"content\u002Fcli-runtime-systems-integration\u002Flocal-state-and-sqlite-in-python-clis\u002Findex.md","Local State and SQLite in Python CLIs",{"type":7,"value":8,"toc":1827},"minimark",[9,19,32,36,41,90,94,97,100,111,117,123,127,135,156,163,166,181,185,192,526,560,579,587,597,672,683,686,697,701,708,950,976,980,983,1001,1019,1022,1030,1034,1040,1084,1090,1094,1101,1408,1439,1442,1446,1452,1599,1622,1626,1682,1686,1705,1709,1714,1717,1721,1728,1732,1735,1739,1751,1762,1765,1769,1781,1785,1823],[10,11,12,13,18],"p",{},"Most CLIs start stateless and then, one feature at a time, begin to remember things. A sync tool records what it has already uploaded. An API client caches responses so it does not hit rate limits. A deployment tool keeps a history of what was deployed where. A task runner remembers which inputs it has processed. The first version of each of these is usually a JSON file, and for a handful of values that is fine. But JSON files have no queries, no indexes, no partial updates and no concurrency control: every change rewrites the whole file, two concurrent runs need ",[14,15,17],"a",{"href":16},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Ffile-locking-for-concurrent-cli-runs\u002F","a lock",", and \"show me the last 20 runs that failed\" means loading everything into memory.",[10,20,21,22,26,27,31],{},"SQLite solves all of that and ships with Python. One file, transactional writes, safe concurrent access from several processes, SQL for queries, and no server to install. This topic covers using it well from a CLI: where the database belongs, the connection settings that matter, transactions, evolving the schema between releases, caching and history as two common uses, and testing. It sits in the ",[14,23,25],{"href":24},"\u002Fcli-runtime-systems-integration\u002F","CLI Runtime & Systems Integration"," section next to ",[14,28,30],{"href":29},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002F","filesystem paths and atomic writes",", which covers the file-level foundations.",[33,34],"inline-diagram",{"name":35},"sql-topic-map",[37,38,40],"h2",{"id":39},"tldr","TL;DR",[42,43,44,52,58,64,70,80],"ul",{},[45,46,47,51],"li",{},[48,49,50],"strong",{},"Reach for SQLite when state is queried, grows, or is written by concurrent runs."," Keep JSON or TOML for small, human-edited configuration.",[45,53,54,57],{},[48,55,56],{},"Put the database in the user's state or cache directory,"," never in the current directory or next to the code.",[45,59,60,63],{},[48,61,62],{},"Open connections with a few pragmas:"," WAL journal mode, a busy timeout, foreign keys on. Close them explicitly.",[45,65,66,69],{},[48,67,68],{},"Wrap each logical change in one transaction"," and keep transactions short.",[45,71,72,79],{},[48,73,74,75],{},"Version the schema with ",[76,77,78],"code",{},"PRAGMA user_version"," and apply numbered migrations at startup, inside a transaction.",[45,81,82,89],{},[48,83,84,85,88],{},"Test against a real SQLite file in ",[76,86,87],{},"tmp_path",","," not mocks; it is fast enough and catches real locking and migration bugs.",[37,91,93],{"id":92},"when-sqlite-is-the-right-store","When SQLite is the right store",[10,95,96],{},"Not all state belongs in a database. The deciding questions are who edits it, how big it gets, and whether more than one process writes it.",[33,98],{"name":99},"sql-store-choice",[10,101,102,105,106,110],{},[48,103,104],{},"Configuration"," that users edit by hand belongs in TOML or YAML, read as described in ",[14,107,109],{"href":108},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Freading-toml-config-with-tomllib\u002F","reading TOML config with tomllib",". A database is the wrong place for anything a person should open in an editor.",[10,112,113,116],{},[48,114,115],{},"A few machine-written values"," — a last-run timestamp, a cursor — fit comfortably in a small JSON file written atomically. The overhead of a schema is not worth it.",[10,118,119,122],{},[48,120,121],{},"Anything that grows or is queried"," — history, inventories, processed-item markers, caches with expiry, queues — belongs in SQLite. The point where a JSON file becomes painful arrives earlier than people expect: as soon as you want \"only the entries from last week\", or two cron jobs touch the same file.",[37,124,126],{"id":125},"where-the-database-lives","Where the database lives",[10,128,129,130,134],{},"A CLI's database is per-user application data. Use ",[14,131,133],{"href":132},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fstoring-app-data-with-platformdirs\u002F","platformdirs"," to find the right directory on each platform, and choose between two of them deliberately:",[42,136,137,147],{},[45,138,139,142,143,146],{},[48,140,141],{},"State directory"," (",[76,144,145],{},"user_state_path",") for data the user would be upset to lose: history, records of what has been synced, queued work.",[45,148,149,142,152,155],{},[48,150,151],{},"Cache directory",[76,153,154],{},"user_cache_path",") for data that can be rebuilt: HTTP response caches, downloaded indexes. Users and cleanup tools may delete it at any time, and your tool must cope.",[10,157,158,159,162],{},"Never put the database in the current working directory — it litters every project — and never inside the installed package, which may be read-only or replaced on upgrade. Let an environment variable override the path (",[76,160,161],{},"MYTOOL_DB=\u002Ftmp\u002Ftest.db","); tests and power users both rely on it.",[33,164],{"name":165},"sql-file-layout",[10,167,168,169,172,173,176,177,180],{},"SQLite in WAL mode keeps two companion files next to the database, ",[76,170,171],{},"-wal"," and ",[76,174,175],{},"-shm",". They are normal and must stay with the main file; a tool that copies or backs up its database should use SQLite's backup API (",[76,178,179],{},"conn.backup()",") rather than copying files mid-write.",[37,182,184],{"id":183},"opening-a-connection-properly","Opening a connection properly",[10,186,187,188,191],{},"Python's ",[76,189,190],{},"sqlite3"," defaults are conservative and date from a time when SQLite was used differently. A CLI should set a few things on every connection:",[193,194,199],"pre",{"className":195,"code":196,"language":197,"meta":198,"style":198},"language-python shiki shiki-themes github-light github-dark","# src\u002Fmytool\u002Fdb.py\nfrom __future__ import annotations\n\nimport os\nimport sqlite3\nfrom pathlib import Path\n\nfrom platformdirs import user_state_path\n\n\ndef db_path() -> Path:\n    override = os.environ.get(\"MYTOOL_DB\")\n    return Path(override) if override else user_state_path(\"mytool\") \u002F \"mytool.db\"\n\n\ndef connect(path: Path | None = None) -> sqlite3.Connection:\n    path = path or db_path()\n    path.parent.mkdir(parents=True, exist_ok=True)\n    conn = sqlite3.connect(path, timeout=10.0)       # wait up to 10 s for a lock\n    conn.row_factory = sqlite3.Row                    # rows behave like dicts\n    conn.execute(\"PRAGMA journal_mode = WAL\")         # readers do not block the writer\n    conn.execute(\"PRAGMA foreign_keys = ON\")          # off by default in SQLite\n    conn.execute(\"PRAGMA synchronous = NORMAL\")       # safe with WAL, much faster\n    return conn\n","python","",[76,200,201,210,228,235,244,252,265,270,283,288,293,306,325,358,363,368,393,410,437,462,476,491,505,518],{"__ignoreMap":198},[202,203,206],"span",{"class":204,"line":205},"line",1,[202,207,209],{"class":208},"sJ8bj","# src\u002Fmytool\u002Fdb.py\n",[202,211,213,217,221,224],{"class":204,"line":212},2,[202,214,216],{"class":215},"szBVR","from",[202,218,220],{"class":219},"sj4cs"," __future__",[202,222,223],{"class":215}," import",[202,225,227],{"class":226},"sVt8B"," annotations\n",[202,229,231],{"class":204,"line":230},3,[202,232,234],{"emptyLinePlaceholder":233},true,"\n",[202,236,238,241],{"class":204,"line":237},4,[202,239,240],{"class":215},"import",[202,242,243],{"class":226}," os\n",[202,245,247,249],{"class":204,"line":246},5,[202,248,240],{"class":215},[202,250,251],{"class":226}," sqlite3\n",[202,253,255,257,260,262],{"class":204,"line":254},6,[202,256,216],{"class":215},[202,258,259],{"class":226}," pathlib ",[202,261,240],{"class":215},[202,263,264],{"class":226}," Path\n",[202,266,268],{"class":204,"line":267},7,[202,269,234],{"emptyLinePlaceholder":233},[202,271,273,275,278,280],{"class":204,"line":272},8,[202,274,216],{"class":215},[202,276,277],{"class":226}," platformdirs ",[202,279,240],{"class":215},[202,281,282],{"class":226}," user_state_path\n",[202,284,286],{"class":204,"line":285},9,[202,287,234],{"emptyLinePlaceholder":233},[202,289,291],{"class":204,"line":290},10,[202,292,234],{"emptyLinePlaceholder":233},[202,294,296,299,303],{"class":204,"line":295},11,[202,297,298],{"class":215},"def",[202,300,302],{"class":301},"sScJk"," db_path",[202,304,305],{"class":226},"() -> Path:\n",[202,307,309,312,315,318,322],{"class":204,"line":308},12,[202,310,311],{"class":226},"    override ",[202,313,314],{"class":215},"=",[202,316,317],{"class":226}," os.environ.get(",[202,319,321],{"class":320},"sZZnC","\"MYTOOL_DB\"",[202,323,324],{"class":226},")\n",[202,326,328,331,334,337,340,343,346,349,352,355],{"class":204,"line":327},13,[202,329,330],{"class":215},"    return",[202,332,333],{"class":226}," Path(override) ",[202,335,336],{"class":215},"if",[202,338,339],{"class":226}," override ",[202,341,342],{"class":215},"else",[202,344,345],{"class":226}," user_state_path(",[202,347,348],{"class":320},"\"mytool\"",[202,350,351],{"class":226},") ",[202,353,354],{"class":215},"\u002F",[202,356,357],{"class":320}," \"mytool.db\"\n",[202,359,361],{"class":204,"line":360},14,[202,362,234],{"emptyLinePlaceholder":233},[202,364,366],{"class":204,"line":365},15,[202,367,234],{"emptyLinePlaceholder":233},[202,369,371,373,376,379,382,385,388,390],{"class":204,"line":370},16,[202,372,298],{"class":215},[202,374,375],{"class":301}," connect",[202,377,378],{"class":226},"(path: Path ",[202,380,381],{"class":215},"|",[202,383,384],{"class":219}," None",[202,386,387],{"class":215}," =",[202,389,384],{"class":219},[202,391,392],{"class":226},") -> sqlite3.Connection:\n",[202,394,396,399,401,404,407],{"class":204,"line":395},17,[202,397,398],{"class":226},"    path ",[202,400,314],{"class":215},[202,402,403],{"class":226}," path ",[202,405,406],{"class":215},"or",[202,408,409],{"class":226}," db_path()\n",[202,411,413,416,420,422,425,428,431,433,435],{"class":204,"line":412},18,[202,414,415],{"class":226},"    path.parent.mkdir(",[202,417,419],{"class":418},"s4XuR","parents",[202,421,314],{"class":215},[202,423,424],{"class":219},"True",[202,426,427],{"class":226},", ",[202,429,430],{"class":418},"exist_ok",[202,432,314],{"class":215},[202,434,424],{"class":219},[202,436,324],{"class":226},[202,438,440,443,445,448,451,453,456,459],{"class":204,"line":439},19,[202,441,442],{"class":226},"    conn ",[202,444,314],{"class":215},[202,446,447],{"class":226}," sqlite3.connect(path, ",[202,449,450],{"class":418},"timeout",[202,452,314],{"class":215},[202,454,455],{"class":219},"10.0",[202,457,458],{"class":226},")       ",[202,460,461],{"class":208},"# wait up to 10 s for a lock\n",[202,463,465,468,470,473],{"class":204,"line":464},20,[202,466,467],{"class":226},"    conn.row_factory ",[202,469,314],{"class":215},[202,471,472],{"class":226}," sqlite3.Row                    ",[202,474,475],{"class":208},"# rows behave like dicts\n",[202,477,479,482,485,488],{"class":204,"line":478},21,[202,480,481],{"class":226},"    conn.execute(",[202,483,484],{"class":320},"\"PRAGMA journal_mode = WAL\"",[202,486,487],{"class":226},")         ",[202,489,490],{"class":208},"# readers do not block the writer\n",[202,492,494,496,499,502],{"class":204,"line":493},22,[202,495,481],{"class":226},[202,497,498],{"class":320},"\"PRAGMA foreign_keys = ON\"",[202,500,501],{"class":226},")          ",[202,503,504],{"class":208},"# off by default in SQLite\n",[202,506,508,510,513,515],{"class":204,"line":507},23,[202,509,481],{"class":226},[202,511,512],{"class":320},"\"PRAGMA synchronous = NORMAL\"",[202,514,458],{"class":226},[202,516,517],{"class":208},"# safe with WAL, much faster\n",[202,519,521,523],{"class":204,"line":520},24,[202,522,330],{"class":215},[202,524,525],{"class":226}," conn\n",[10,527,528,529,531,532,535,536,539,540,543,544,547,548,551,552,555,556,559],{},"Each line earns its place. The ",[76,530,450],{}," makes a connection wait for a lock instead of failing immediately with ",[76,533,534],{},"database is locked"," when another run is writing. ",[48,537,538],{},"WAL mode"," lets readers and one writer proceed at the same time, which is what you want when a long ",[76,541,542],{},"history"," query overlaps a running ",[76,545,546],{},"sync",". ",[48,549,550],{},"Foreign keys"," are off by default for backward compatibility and should be on for any schema that uses them. ",[76,553,554],{},"synchronous = NORMAL"," in WAL mode keeps the database consistent after a crash while avoiding an ",[76,557,558],{},"fsync"," on every commit — a large speed-up for tools that write many small transactions.",[10,561,562,565,566,569,570,574,575,578],{},[76,563,564],{},"sqlite3.Row"," makes results addressable by column name (",[76,567,568],{},"row[\"started_at\"]","), which keeps query code readable and lets you convert rows to dictionaries for ",[14,571,573],{"href":572},"\u002Fadvanced-input-parsing-user-experience\u002Foutput-formats-for-data-clis\u002Fadding-a-format-flag-for-table-json-and-csv\u002F","JSON output"," with ",[76,576,577],{},"dict(row)",".",[37,580,582,583,586],{"id":581},"transactions-and-the-with-conn-trap","Transactions, and the ",[76,584,585],{},"with conn:"," trap",[10,588,589,590,592,593,596],{},"Every change that must happen completely or not at all belongs in one transaction. The ",[76,591,190],{}," connection is a context manager that commits on success and rolls back on an exception — but it does ",[48,594,595],{},"not"," close the connection, which surprises almost everyone the first time:",[193,598,600],{"className":195,"code":599,"language":197,"meta":198,"style":198},"from contextlib import closing\n\nwith closing(connect()) as conn:          # closes the connection at the end\n    with conn:                            # one transaction: commit or roll back\n        conn.execute(\"INSERT INTO runs (command, started_at) VALUES (?, ?)\", (\"sync\", now))\n        conn.execute(\"UPDATE items SET synced = 1 WHERE id IN (SELECT id FROM pending)\")\n",[76,601,602,614,618,635,646,663],{"__ignoreMap":198},[202,603,604,606,609,611],{"class":204,"line":205},[202,605,216],{"class":215},[202,607,608],{"class":226}," contextlib ",[202,610,240],{"class":215},[202,612,613],{"class":226}," closing\n",[202,615,616],{"class":204,"line":212},[202,617,234],{"emptyLinePlaceholder":233},[202,619,620,623,626,629,632],{"class":204,"line":230},[202,621,622],{"class":215},"with",[202,624,625],{"class":226}," closing(connect()) ",[202,627,628],{"class":215},"as",[202,630,631],{"class":226}," conn:          ",[202,633,634],{"class":208},"# closes the connection at the end\n",[202,636,637,640,643],{"class":204,"line":237},[202,638,639],{"class":215},"    with",[202,641,642],{"class":226}," conn:                            ",[202,644,645],{"class":208},"# one transaction: commit or roll back\n",[202,647,648,651,654,657,660],{"class":204,"line":246},[202,649,650],{"class":226},"        conn.execute(",[202,652,653],{"class":320},"\"INSERT INTO runs (command, started_at) VALUES (?, ?)\"",[202,655,656],{"class":226},", (",[202,658,659],{"class":320},"\"sync\"",[202,661,662],{"class":226},", now))\n",[202,664,665,667,670],{"class":204,"line":254},[202,666,650],{"class":226},[202,668,669],{"class":320},"\"UPDATE items SET synced = 1 WHERE id IN (SELECT id FROM pending)\"",[202,671,324],{"class":226},[10,673,674,675,678,679,578],{},"Keep transactions short. A write transaction holds SQLite's single write lock until it commits; if a command opens one and then spends a minute downloading files, every other run waits — or times out. Do the slow work first, then write the results in one quick transaction. Always use ",[76,676,677],{},"?"," placeholders rather than formatting values into SQL; the reasons are the same as for ",[14,680,682],{"href":681},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Favoiding-shell-injection-in-python-clis\u002F","avoiding shell injection",[33,684],{"name":685},"sql-transaction-scope",[10,687,688,689,692,693,696],{},"On Python 3.12 and later, ",[76,690,691],{},"sqlite3.connect(..., autocommit=False)"," gives PEP 249-compliant transaction handling, where a transaction is always open and ",[76,694,695],{},"commit()"," is explicit. Either style works; pick one and use it consistently across the codebase.",[37,698,700],{"id":699},"evolving-the-schema-between-releases","Evolving the schema between releases",[10,702,703,704,707],{},"The schema of a CLI's database changes as the tool grows, and users upgrade from any old version to the newest one. You cannot ask them to delete their history. The standard approach uses SQLite's built-in ",[76,705,706],{},"user_version"," field — an integer stored in the database header — and a list of numbered migrations applied in order at startup.",[193,709,711],{"className":195,"code":710,"language":197,"meta":198,"style":198},"MIGRATIONS = [\n    \"CREATE TABLE runs (id INTEGER PRIMARY KEY, command TEXT NOT NULL, started_at TEXT NOT NULL)\",\n    \"ALTER TABLE runs ADD COLUMN exit_code INTEGER\",\n    \"CREATE INDEX runs_started ON runs (started_at)\",\n]\n\n\ndef migrate(conn: sqlite3.Connection) -> int:\n    conn.isolation_level = None                    # explicit transactions, DDL included\n    current = conn.execute(\"PRAGMA user_version\").fetchone()[0]\n    for number, sql in enumerate(MIGRATIONS[current:], start=current + 1):\n        conn.execute(\"BEGIN IMMEDIATE\")\n        try:\n            conn.execute(sql)\n            conn.execute(f\"PRAGMA user_version = {number}\")\n            conn.execute(\"COMMIT\")\n        except BaseException:\n            conn.execute(\"ROLLBACK\")\n            raise\n    conn.isolation_level = \"\"                      # back to the default for normal use\n    return len(MIGRATIONS)\n",[76,712,713,723,731,738,745,750,754,758,774,786,807,846,855,862,867,892,901,911,920,925,937],{"__ignoreMap":198},[202,714,715,718,720],{"class":204,"line":205},[202,716,717],{"class":219},"MIGRATIONS",[202,719,387],{"class":215},[202,721,722],{"class":226}," [\n",[202,724,725,728],{"class":204,"line":212},[202,726,727],{"class":320},"    \"CREATE TABLE runs (id INTEGER PRIMARY KEY, command TEXT NOT NULL, started_at TEXT NOT NULL)\"",[202,729,730],{"class":226},",\n",[202,732,733,736],{"class":204,"line":230},[202,734,735],{"class":320},"    \"ALTER TABLE runs ADD COLUMN exit_code INTEGER\"",[202,737,730],{"class":226},[202,739,740,743],{"class":204,"line":237},[202,741,742],{"class":320},"    \"CREATE INDEX runs_started ON runs (started_at)\"",[202,744,730],{"class":226},[202,746,747],{"class":204,"line":246},[202,748,749],{"class":226},"]\n",[202,751,752],{"class":204,"line":254},[202,753,234],{"emptyLinePlaceholder":233},[202,755,756],{"class":204,"line":267},[202,757,234],{"emptyLinePlaceholder":233},[202,759,760,762,765,768,771],{"class":204,"line":272},[202,761,298],{"class":215},[202,763,764],{"class":301}," migrate",[202,766,767],{"class":226},"(conn: sqlite3.Connection) -> ",[202,769,770],{"class":219},"int",[202,772,773],{"class":226},":\n",[202,775,776,779,781,783],{"class":204,"line":285},[202,777,778],{"class":226},"    conn.isolation_level ",[202,780,314],{"class":215},[202,782,384],{"class":219},[202,784,785],{"class":208},"                    # explicit transactions, DDL included\n",[202,787,788,791,793,796,799,802,805],{"class":204,"line":290},[202,789,790],{"class":226},"    current ",[202,792,314],{"class":215},[202,794,795],{"class":226}," conn.execute(",[202,797,798],{"class":320},"\"PRAGMA user_version\"",[202,800,801],{"class":226},").fetchone()[",[202,803,804],{"class":219},"0",[202,806,749],{"class":226},[202,808,809,812,815,818,821,824,826,829,832,834,837,840,843],{"class":204,"line":295},[202,810,811],{"class":215},"    for",[202,813,814],{"class":226}," number, sql ",[202,816,817],{"class":215},"in",[202,819,820],{"class":219}," enumerate",[202,822,823],{"class":226},"(",[202,825,717],{"class":219},[202,827,828],{"class":226},"[current:], ",[202,830,831],{"class":418},"start",[202,833,314],{"class":215},[202,835,836],{"class":226},"current ",[202,838,839],{"class":215},"+",[202,841,842],{"class":219}," 1",[202,844,845],{"class":226},"):\n",[202,847,848,850,853],{"class":204,"line":308},[202,849,650],{"class":226},[202,851,852],{"class":320},"\"BEGIN IMMEDIATE\"",[202,854,324],{"class":226},[202,856,857,860],{"class":204,"line":327},[202,858,859],{"class":215},"        try",[202,861,773],{"class":226},[202,863,864],{"class":204,"line":360},[202,865,866],{"class":226},"            conn.execute(sql)\n",[202,868,869,872,875,878,881,884,887,890],{"class":204,"line":365},[202,870,871],{"class":226},"            conn.execute(",[202,873,874],{"class":215},"f",[202,876,877],{"class":320},"\"PRAGMA user_version = ",[202,879,880],{"class":219},"{",[202,882,883],{"class":226},"number",[202,885,886],{"class":219},"}",[202,888,889],{"class":320},"\"",[202,891,324],{"class":226},[202,893,894,896,899],{"class":204,"line":370},[202,895,871],{"class":226},[202,897,898],{"class":320},"\"COMMIT\"",[202,900,324],{"class":226},[202,902,903,906,909],{"class":204,"line":395},[202,904,905],{"class":215},"        except",[202,907,908],{"class":219}," BaseException",[202,910,773],{"class":226},[202,912,913,915,918],{"class":204,"line":412},[202,914,871],{"class":226},[202,916,917],{"class":320},"\"ROLLBACK\"",[202,919,324],{"class":226},[202,921,922],{"class":204,"line":439},[202,923,924],{"class":215},"            raise\n",[202,926,927,929,931,934],{"class":204,"line":464},[202,928,778],{"class":226},[202,930,314],{"class":215},[202,932,933],{"class":320}," \"\"",[202,935,936],{"class":208},"                      # back to the default for normal use\n",[202,938,939,941,944,946,948],{"class":204,"line":478},[202,940,330],{"class":215},[202,942,943],{"class":219}," len",[202,945,823],{"class":226},[202,947,717],{"class":219},[202,949,324],{"class":226},[10,951,952,953,956,957,959,960,963,964,967,968,970,971,975],{},"Because both the change and the version bump happen in one explicit transaction, a crash mid-migration leaves the database at the previous version, ready to retry. The explicit ",[76,954,955],{},"BEGIN"," matters: in its default mode Python's ",[76,958,190],{}," does not open a transaction before ",[76,961,962],{},"CREATE"," or ",[76,965,966],{},"ALTER"," statements, so ",[76,969,585],{}," alone would not make a schema change atomic. ",[14,972,974],{"href":973},"\u002Fcli-runtime-systems-integration\u002Flocal-state-and-sqlite-in-python-clis\u002Fmigrating-a-cli-sqlite-schema\u002F","Migrating a CLI's SQLite schema"," extends this with table rebuilds, downgrade protection and backups before risky changes.",[37,977,979],{"id":978},"two-common-uses-caches-and-history","Two common uses: caches and history",[10,981,982],{},"Two patterns account for most CLI databases, and both have their own guides.",[10,984,985,988,989,992,993,996,997,578],{},[48,986,987],{},"An HTTP response cache"," stores API responses keyed by URL, with a fetched-at time and an expiry. It turns repeated ",[76,990,991],{},"mytool show"," calls into instant local reads, keeps the tool usable offline, and reduces pressure on rate limits. Expiry, ",[76,994,995],{},"ETag"," revalidation and size limits are what separate a cache from a slowly growing pile of stale data — see ",[14,998,1000],{"href":999},"\u002Fcli-runtime-systems-integration\u002Flocal-state-and-sqlite-in-python-clis\u002Fcaching-http-responses-on-disk-in-a-cli\u002F","caching HTTP responses on disk in a CLI",[10,1002,1003,1006,1007,172,1010,1013,1014,1018],{},[48,1004,1005],{},"A run history"," records what the tool did: which command, when, with what result, and a few key details. It answers support questions (\"what did the deploy on Tuesday actually do?\"), powers ",[76,1008,1009],{},"mytool history",[76,1011,1012],{},"mytool last",", and gives users a way to export their own records. ",[14,1015,1017],{"href":1016},"\u002Fcli-runtime-systems-integration\u002Flocal-state-and-sqlite-in-python-clis\u002Frecording-and-querying-cli-run-history\u002F","Recording and querying CLI run history"," builds both sides.",[33,1020],{"name":1021},"sql-uses",[10,1023,1024,1025,1029],{},"The general recipe for everything else is in ",[14,1026,1028],{"href":1027},"\u002Fcli-runtime-systems-integration\u002Flocal-state-and-sqlite-in-python-clis\u002Fstoring-cli-state-in-sqlite\u002F","storing CLI state in SQLite",", which wraps the connection, migrations and queries in a small repository class that commands use without writing SQL themselves.",[37,1031,1033],{"id":1032},"concurrency-between-runs","Concurrency between runs",[10,1035,1036,1037,1039],{},"SQLite allows many readers and one writer at a time. With WAL mode and a busy timeout, that is enough for almost every CLI: two runs that both write will take turns, each waiting up to the timeout for the other's transaction to finish. Problems only appear in three situations. Long write transactions block others — keep them short, as above. Network filesystems such as NFS and SMB do not implement the locking SQLite needs reliably; keep the database on local disk, which platformdirs paths are. And if a write genuinely must not run twice concurrently — two ",[76,1038,546],{}," runs processing the same queue — a transaction is not enough on its own, because each run could read the same pending items before either writes. Claim work atomically instead:",[193,1041,1043],{"className":195,"code":1042,"language":197,"meta":198,"style":198},"with conn:\n    claimed = conn.execute(\n        \"UPDATE jobs SET claimed_by = ? WHERE id = (SELECT id FROM jobs \"\n        \"WHERE claimed_by IS NULL ORDER BY id LIMIT 1) RETURNING id, payload\",\n        (run_id,),\n    ).fetchone()\n",[76,1044,1045,1052,1062,1067,1074,1079],{"__ignoreMap":198},[202,1046,1047,1049],{"class":204,"line":205},[202,1048,622],{"class":215},[202,1050,1051],{"class":226}," conn:\n",[202,1053,1054,1057,1059],{"class":204,"line":212},[202,1055,1056],{"class":226},"    claimed ",[202,1058,314],{"class":215},[202,1060,1061],{"class":226}," conn.execute(\n",[202,1063,1064],{"class":204,"line":230},[202,1065,1066],{"class":320},"        \"UPDATE jobs SET claimed_by = ? WHERE id = (SELECT id FROM jobs \"\n",[202,1068,1069,1072],{"class":204,"line":237},[202,1070,1071],{"class":320},"        \"WHERE claimed_by IS NULL ORDER BY id LIMIT 1) RETURNING id, payload\"",[202,1073,730],{"class":226},[202,1075,1076],{"class":204,"line":246},[202,1077,1078],{"class":226},"        (run_id,),\n",[202,1080,1081],{"class":204,"line":254},[202,1082,1083],{"class":226},"    ).fetchone()\n",[10,1085,1086,1089],{},[76,1087,1088],{},"UPDATE ... RETURNING"," (SQLite 3.35+, included with current Python builds) claims and reads a row in one statement, so two runs can never take the same job.",[37,1091,1093],{"id":1092},"backups-resets-and-damaged-files","Backups, resets and damaged files",[10,1095,1096,1097,1100],{},"Once a tool keeps state, users will eventually need to back it up, move it to a new machine, or start over — and occasionally a disk problem or an interrupted copy will leave a file SQLite cannot read. A small ",[76,1098,1099],{},"db"," command group covers all of it and saves a lot of support time:",[193,1102,1104],{"className":195,"code":1103,"language":197,"meta":198,"style":198},"import sqlite3\nfrom contextlib import closing\nfrom pathlib import Path\n\n\ndef backup(src: Path, dest: Path) -> None:\n    \"\"\"Consistent copy, safe while other runs are using the database.\"\"\"\n    with closing(sqlite3.connect(src)) as source, closing(sqlite3.connect(dest)) as target:\n        source.backup(target)\n\n\ndef check(path: Path) -> str:\n    \"\"\"Return 'ok' or SQLite's description of the damage.\"\"\"\n    try:\n        with closing(sqlite3.connect(path)) as conn:\n            return conn.execute(\"PRAGMA integrity_check\").fetchone()[0]\n    except sqlite3.DatabaseError as exc:          # \"file is not a database\"\n        return str(exc)\n\n\ndef reset(path: Path) -> Path | None:\n    \"\"\"Move the database aside rather than deleting it; return where it went.\"\"\"\n    if not path.exists():\n        return None\n    aside = path.with_suffix(\".db.bak\")\n    path.replace(aside)\n    for extra in (\"-wal\", \"-shm\"):\n        Path(f\"{path}{extra}\").unlink(missing_ok=True)\n    return aside\n",[76,1105,1106,1112,1122,1132,1136,1140,1155,1160,1177,1182,1186,1190,1205,1210,1217,1229,1245,1261,1272,1276,1280,1296,1301,1312,1319,1335,1341,1363,1400],{"__ignoreMap":198},[202,1107,1108,1110],{"class":204,"line":205},[202,1109,240],{"class":215},[202,1111,251],{"class":226},[202,1113,1114,1116,1118,1120],{"class":204,"line":212},[202,1115,216],{"class":215},[202,1117,608],{"class":226},[202,1119,240],{"class":215},[202,1121,613],{"class":226},[202,1123,1124,1126,1128,1130],{"class":204,"line":230},[202,1125,216],{"class":215},[202,1127,259],{"class":226},[202,1129,240],{"class":215},[202,1131,264],{"class":226},[202,1133,1134],{"class":204,"line":237},[202,1135,234],{"emptyLinePlaceholder":233},[202,1137,1138],{"class":204,"line":246},[202,1139,234],{"emptyLinePlaceholder":233},[202,1141,1142,1144,1147,1150,1153],{"class":204,"line":254},[202,1143,298],{"class":215},[202,1145,1146],{"class":301}," backup",[202,1148,1149],{"class":226},"(src: Path, dest: Path) -> ",[202,1151,1152],{"class":219},"None",[202,1154,773],{"class":226},[202,1156,1157],{"class":204,"line":267},[202,1158,1159],{"class":320},"    \"\"\"Consistent copy, safe while other runs are using the database.\"\"\"\n",[202,1161,1162,1164,1167,1169,1172,1174],{"class":204,"line":272},[202,1163,639],{"class":215},[202,1165,1166],{"class":226}," closing(sqlite3.connect(src)) ",[202,1168,628],{"class":215},[202,1170,1171],{"class":226}," source, closing(sqlite3.connect(dest)) ",[202,1173,628],{"class":215},[202,1175,1176],{"class":226}," target:\n",[202,1178,1179],{"class":204,"line":285},[202,1180,1181],{"class":226},"        source.backup(target)\n",[202,1183,1184],{"class":204,"line":290},[202,1185,234],{"emptyLinePlaceholder":233},[202,1187,1188],{"class":204,"line":295},[202,1189,234],{"emptyLinePlaceholder":233},[202,1191,1192,1194,1197,1200,1203],{"class":204,"line":308},[202,1193,298],{"class":215},[202,1195,1196],{"class":301}," check",[202,1198,1199],{"class":226},"(path: Path) -> ",[202,1201,1202],{"class":219},"str",[202,1204,773],{"class":226},[202,1206,1207],{"class":204,"line":327},[202,1208,1209],{"class":320},"    \"\"\"Return 'ok' or SQLite's description of the damage.\"\"\"\n",[202,1211,1212,1215],{"class":204,"line":360},[202,1213,1214],{"class":215},"    try",[202,1216,773],{"class":226},[202,1218,1219,1222,1225,1227],{"class":204,"line":365},[202,1220,1221],{"class":215},"        with",[202,1223,1224],{"class":226}," closing(sqlite3.connect(path)) ",[202,1226,628],{"class":215},[202,1228,1051],{"class":226},[202,1230,1231,1234,1236,1239,1241,1243],{"class":204,"line":370},[202,1232,1233],{"class":215},"            return",[202,1235,795],{"class":226},[202,1237,1238],{"class":320},"\"PRAGMA integrity_check\"",[202,1240,801],{"class":226},[202,1242,804],{"class":219},[202,1244,749],{"class":226},[202,1246,1247,1250,1253,1255,1258],{"class":204,"line":395},[202,1248,1249],{"class":215},"    except",[202,1251,1252],{"class":226}," sqlite3.DatabaseError ",[202,1254,628],{"class":215},[202,1256,1257],{"class":226}," exc:          ",[202,1259,1260],{"class":208},"# \"file is not a database\"\n",[202,1262,1263,1266,1269],{"class":204,"line":412},[202,1264,1265],{"class":215},"        return",[202,1267,1268],{"class":219}," str",[202,1270,1271],{"class":226},"(exc)\n",[202,1273,1274],{"class":204,"line":439},[202,1275,234],{"emptyLinePlaceholder":233},[202,1277,1278],{"class":204,"line":464},[202,1279,234],{"emptyLinePlaceholder":233},[202,1281,1282,1284,1287,1290,1292,1294],{"class":204,"line":478},[202,1283,298],{"class":215},[202,1285,1286],{"class":301}," reset",[202,1288,1289],{"class":226},"(path: Path) -> Path ",[202,1291,381],{"class":215},[202,1293,384],{"class":219},[202,1295,773],{"class":226},[202,1297,1298],{"class":204,"line":493},[202,1299,1300],{"class":320},"    \"\"\"Move the database aside rather than deleting it; return where it went.\"\"\"\n",[202,1302,1303,1306,1309],{"class":204,"line":507},[202,1304,1305],{"class":215},"    if",[202,1307,1308],{"class":215}," not",[202,1310,1311],{"class":226}," path.exists():\n",[202,1313,1314,1316],{"class":204,"line":520},[202,1315,1265],{"class":215},[202,1317,1318],{"class":219}," None\n",[202,1320,1322,1325,1327,1330,1333],{"class":204,"line":1321},25,[202,1323,1324],{"class":226},"    aside ",[202,1326,314],{"class":215},[202,1328,1329],{"class":226}," path.with_suffix(",[202,1331,1332],{"class":320},"\".db.bak\"",[202,1334,324],{"class":226},[202,1336,1338],{"class":204,"line":1337},26,[202,1339,1340],{"class":226},"    path.replace(aside)\n",[202,1342,1344,1346,1349,1351,1353,1356,1358,1361],{"class":204,"line":1343},27,[202,1345,811],{"class":215},[202,1347,1348],{"class":226}," extra ",[202,1350,817],{"class":215},[202,1352,142],{"class":226},[202,1354,1355],{"class":320},"\"-wal\"",[202,1357,427],{"class":226},[202,1359,1360],{"class":320},"\"-shm\"",[202,1362,845],{"class":226},[202,1364,1366,1369,1371,1373,1375,1378,1381,1384,1386,1388,1391,1394,1396,1398],{"class":204,"line":1365},28,[202,1367,1368],{"class":226},"        Path(",[202,1370,874],{"class":215},[202,1372,889],{"class":320},[202,1374,880],{"class":219},[202,1376,1377],{"class":226},"path",[202,1379,1380],{"class":219},"}{",[202,1382,1383],{"class":226},"extra",[202,1385,886],{"class":219},[202,1387,889],{"class":320},[202,1389,1390],{"class":226},").unlink(",[202,1392,1393],{"class":418},"missing_ok",[202,1395,314],{"class":215},[202,1397,424],{"class":219},[202,1399,324],{"class":226},[202,1401,1403,1405],{"class":204,"line":1402},29,[202,1404,330],{"class":215},[202,1406,1407],{"class":226}," aside\n",[10,1409,1410,1411,427,1414,172,1417,1420,1421,1424,1425,1428,1429,172,1431,1433,1434,1438],{},"Expose them as ",[76,1412,1413],{},"mytool db backup FILE",[76,1415,1416],{},"mytool db check",[76,1418,1419],{},"mytool db reset",". The backup uses SQLite's online backup API, which produces a consistent snapshot even while another run is writing — unlike copying the file, which can capture a half-applied transaction. ",[76,1422,1423],{},"reset"," moves the file aside instead of deleting it, so a user who resets by mistake can recover. And when opening the database fails with ",[76,1426,1427],{},"sqlite3.DatabaseError"," during normal use, the error message should name the file and suggest ",[76,1430,1416],{},[76,1432,1419],{},", rather than surfacing a traceback; ",[14,1435,1437],{"href":1436},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Ffriendly-error-messages-and-tracebacks\u002F","friendly error messages and tracebacks"," shows where that handler belongs.",[10,1440,1441],{},"For caches, the policy can be simpler: if the cache database is unreadable, delete it and continue. Nothing in a cache is worth an error message.",[37,1443,1445],{"id":1444},"testing-database-code","Testing database code",[10,1447,1448,1449,1451],{},"Use real SQLite in tests. It runs in-process, a fresh database file in ",[76,1450,87],{}," costs a millisecond or two, and it exercises the actual SQL, pragmas and migrations — which mocks never do.",[193,1453,1455],{"className":195,"code":1454,"language":197,"meta":198,"style":198},"import pytest\n\nfrom mytool import db\n\n\n@pytest.fixture\ndef conn(tmp_path, monkeypatch):\n    monkeypatch.setenv(\"MYTOOL_DB\", str(tmp_path \u002F \"test.db\"))\n    connection = db.connect()\n    db.migrate(connection)\n    yield connection\n    connection.close()\n\n\ndef test_migrations_reach_latest_version(conn):\n    assert conn.execute(\"PRAGMA user_version\").fetchone()[0] == len(db.MIGRATIONS)\n",[76,1456,1457,1464,1468,1480,1484,1488,1493,1503,1525,1535,1540,1548,1553,1557,1561,1571],{"__ignoreMap":198},[202,1458,1459,1461],{"class":204,"line":205},[202,1460,240],{"class":215},[202,1462,1463],{"class":226}," pytest\n",[202,1465,1466],{"class":204,"line":212},[202,1467,234],{"emptyLinePlaceholder":233},[202,1469,1470,1472,1475,1477],{"class":204,"line":230},[202,1471,216],{"class":215},[202,1473,1474],{"class":226}," mytool ",[202,1476,240],{"class":215},[202,1478,1479],{"class":226}," db\n",[202,1481,1482],{"class":204,"line":237},[202,1483,234],{"emptyLinePlaceholder":233},[202,1485,1486],{"class":204,"line":246},[202,1487,234],{"emptyLinePlaceholder":233},[202,1489,1490],{"class":204,"line":254},[202,1491,1492],{"class":301},"@pytest.fixture\n",[202,1494,1495,1497,1500],{"class":204,"line":267},[202,1496,298],{"class":215},[202,1498,1499],{"class":301}," conn",[202,1501,1502],{"class":226},"(tmp_path, monkeypatch):\n",[202,1504,1505,1508,1510,1512,1514,1517,1519,1522],{"class":204,"line":272},[202,1506,1507],{"class":226},"    monkeypatch.setenv(",[202,1509,321],{"class":320},[202,1511,427],{"class":226},[202,1513,1202],{"class":219},[202,1515,1516],{"class":226},"(tmp_path ",[202,1518,354],{"class":215},[202,1520,1521],{"class":320}," \"test.db\"",[202,1523,1524],{"class":226},"))\n",[202,1526,1527,1530,1532],{"class":204,"line":285},[202,1528,1529],{"class":226},"    connection ",[202,1531,314],{"class":215},[202,1533,1534],{"class":226}," db.connect()\n",[202,1536,1537],{"class":204,"line":290},[202,1538,1539],{"class":226},"    db.migrate(connection)\n",[202,1541,1542,1545],{"class":204,"line":295},[202,1543,1544],{"class":215},"    yield",[202,1546,1547],{"class":226}," connection\n",[202,1549,1550],{"class":204,"line":308},[202,1551,1552],{"class":226},"    connection.close()\n",[202,1554,1555],{"class":204,"line":327},[202,1556,234],{"emptyLinePlaceholder":233},[202,1558,1559],{"class":204,"line":360},[202,1560,234],{"emptyLinePlaceholder":233},[202,1562,1563,1565,1568],{"class":204,"line":365},[202,1564,298],{"class":215},[202,1566,1567],{"class":301}," test_migrations_reach_latest_version",[202,1569,1570],{"class":226},"(conn):\n",[202,1572,1573,1576,1578,1580,1582,1584,1587,1590,1592,1595,1597],{"class":204,"line":370},[202,1574,1575],{"class":215},"    assert",[202,1577,795],{"class":226},[202,1579,798],{"class":320},[202,1581,801],{"class":226},[202,1583,804],{"class":219},[202,1585,1586],{"class":226},"] ",[202,1588,1589],{"class":215},"==",[202,1591,943],{"class":219},[202,1593,1594],{"class":226},"(db.",[202,1596,717],{"class":219},[202,1598,324],{"class":226},[10,1600,1601,1602,1605,1606,1609,1610,1613,1614,1617,1618,1621],{},"Add three kinds of tests beyond ordinary queries. A ",[48,1603,1604],{},"migration test"," builds a database at an old version with representative data, runs ",[76,1607,1608],{},"migrate()"," and checks the data survived. A ",[48,1611,1612],{},"concurrency test"," runs two processes that write at once and asserts nothing was lost, as in the multi-process test from ",[14,1615,1616],{"href":16},"file locking for concurrent CLI runs",". And a ",[48,1619,1620],{},"corruption test"," points the tool at a file that is not a database and checks the error message tells the user what to do.",[37,1623,1625],{"id":1624},"common-pitfalls","Common pitfalls",[42,1627,1628,1644,1653,1661,1667,1676],{},[45,1629,1630,1633,1634,1636,1637,1640,1641,578],{},[48,1631,1632],{},"Forgetting to close."," ",[76,1635,585],{}," manages transactions, not the connection. Use ",[76,1638,1639],{},"contextlib.closing"," or an explicit ",[76,1642,1643],{},"close()",[45,1645,1646,1649,1650,1652],{},[48,1647,1648],{},"Formatting values into SQL."," Always use ",[76,1651,677],{}," placeholders. The only exception is identifiers and pragmas you control, such as the migration number.",[45,1654,1655,1658,1659,578],{},[48,1656,1657],{},"Long write transactions."," Holding the write lock during network calls makes concurrent runs fail with ",[76,1660,534],{},[45,1662,1663,1666],{},[48,1664,1665],{},"Storing the database in the working directory"," or inside the package.",[45,1668,1669,1672,1673,1675],{},[48,1670,1671],{},"No schema version."," Without ",[76,1674,706],{},", the first schema change becomes a guessing game about what each user's database looks like.",[45,1677,1678,1681],{},[48,1679,1680],{},"Treating the cache as precious."," If the tool fails when the cache directory is deleted, the data was not a cache.",[37,1683,1685],{"id":1684},"key-takeaways","Key takeaways",[42,1687,1688,1691,1694,1697,1702],{},[45,1689,1690],{},"SQLite gives a CLI transactional, queryable, concurrency-safe state in one file with no extra dependency.",[45,1692,1693],{},"Keep configuration in TOML, small values in JSON, and anything that grows or is queried in SQLite.",[45,1695,1696],{},"Open connections with a timeout, WAL mode and foreign keys on, and close them explicitly.",[45,1698,74,1699,1701],{},[76,1700,78],{}," and apply migrations transactionally at startup.",[45,1703,1704],{},"Test with real database files, including migrations from old versions and concurrent writers.",[37,1706,1708],{"id":1707},"frequently-asked-questions","Frequently asked questions",[1710,1711,1713],"h3",{"id":1712},"should-i-use-an-orm-such-as-sqlalchemy","Should I use an ORM such as SQLAlchemy?",[10,1715,1716],{},"For a CLI's local state, usually not. A handful of tables and queries are easy to write in SQL, and an ORM adds import time to every command — often more than the rest of the tool combined. If you already depend on SQLAlchemy for other reasons, its Core layer is a reasonable middle ground.",[1710,1718,1720],{"id":1719},"is-sqlite-safe-if-the-user-presses-ctrl-c-during-a-write","Is SQLite safe if the user presses Ctrl-C during a write?",[10,1722,1723,1724,578],{},"Yes. An interrupted transaction is rolled back automatically the next time the database is opened, so the data is either fully written or not at all. Make sure your own cleanup does not mask the interruption — see ",[14,1725,1727],{"href":1726},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fhandling-keyboard-interrupt-cleanly\u002F","handling KeyboardInterrupt cleanly",[1710,1729,1731],{"id":1730},"how-big-can-the-database-get-before-it-is-a-problem","How big can the database get before it is a problem?",[10,1733,1734],{},"Far bigger than a CLI is likely to need — SQLite handles gigabytes comfortably. What matters more is pruning: caches need expiry and size caps, and history needs a retention policy, or the file grows forever on long-lived machines.",[1710,1736,1738],{"id":1737},"can-users-inspect-the-database-themselves","Can users inspect the database themselves?",[10,1740,1741,1742,1744,1745,172,1747,1750],{},"Yes, with the ",[76,1743,190],{}," command-line shell or any SQLite browser, which is a real advantage over custom binary formats. Treat the schema as internal, though: offer ",[76,1746,542],{},[76,1748,1749],{},"export"," commands as the supported interface, so you remain free to change tables between releases.",[1710,1752,1754,1755,963,1758,1761],{"id":1753},"what-about-shelve-or-dbm-from-the-standard-library","What about ",[76,1756,1757],{},"shelve",[76,1759,1760],{},"dbm"," from the standard library?",[10,1763,1764],{},"They are key-value stores without queries, transactions across keys or reliable concurrent access, and the underlying format differs between platforms. SQLite is a better default for anything beyond a trivial cache.",[1710,1766,1768],{"id":1767},"should-sensitive-values-go-in-the-database","Should sensitive values go in the database?",[10,1770,1771,1772,1776,1777,1780],{},"Not secrets. Tokens and passwords belong in the operating system's keyring, as described in ",[14,1773,1775],{"href":1774},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fstoring-tokens-with-keyring\u002F","storing tokens with keyring","; the database can hold a reference such as the profile name. For data that is sensitive but not secret — customer names in a history table, say — create the file with owner-only permissions (",[76,1778,1779],{},"0o600",") and document what it contains, so users and administrators can decide how to treat it.",[37,1782,1784],{"id":1783},"related","Related",[42,1786,1787,1792,1798,1802,1807,1811,1817],{},[45,1788,1789,1790],{},"Up: ",[14,1791,25],{"href":24},[45,1793,1794,1795],{},"Down: ",[14,1796,1797],{"href":1027},"Storing CLI state in SQLite",[45,1799,1794,1800],{},[14,1801,974],{"href":973},[45,1803,1794,1804],{},[14,1805,1806],{"href":999},"Caching HTTP responses on disk in a CLI",[45,1808,1794,1809],{},[14,1810,1017],{"href":1016},[45,1812,1813,1814],{},"Sideways: ",[14,1815,1816],{"href":29},"Filesystem paths and atomic writes",[45,1818,1813,1819],{},[14,1820,1822],{"href":1821},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fcaching-expensive-work-between-cli-runs\u002F","Caching expensive work between CLI runs",[1824,1825,1826],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":198,"searchDepth":212,"depth":212,"links":1828},[1829,1830,1831,1832,1833,1835,1836,1837,1838,1839,1840,1841,1842,1851],{"id":39,"depth":212,"text":40},{"id":92,"depth":212,"text":93},{"id":125,"depth":212,"text":126},{"id":183,"depth":212,"text":184},{"id":581,"depth":212,"text":1834},"Transactions, and the with conn: trap",{"id":699,"depth":212,"text":700},{"id":978,"depth":212,"text":979},{"id":1032,"depth":212,"text":1033},{"id":1092,"depth":212,"text":1093},{"id":1444,"depth":212,"text":1445},{"id":1624,"depth":212,"text":1625},{"id":1684,"depth":212,"text":1685},{"id":1707,"depth":212,"text":1708,"children":1843},[1844,1845,1846,1847,1848,1850],{"id":1712,"depth":230,"text":1713},{"id":1719,"depth":230,"text":1720},{"id":1730,"depth":230,"text":1731},{"id":1737,"depth":230,"text":1738},{"id":1753,"depth":230,"text":1849},"What about shelve or dbm from the standard library?",{"id":1767,"depth":230,"text":1768},{"id":1783,"depth":212,"text":1784},"2026-10-02","Use SQLite for a CLI’s local state: where the database lives, connection settings, transactions, schema migrations, HTTP caches, run history and tests.","intermediate",false,"md",{},"\u002Fcli-runtime-systems-integration\u002Flocal-state-and-sqlite-in-python-clis",{"title":5,"description":1853},"cli-runtime-systems-integration\u002Flocal-state-and-sqlite-in-python-clis\u002Findex",[1862,1863,1864,1865,1866],"sqlite","state","persistence","caching","filesystem","VS9C6Yj00NDRLHc76j4zEBD-WFcctH5Wd5Jpv3FUh6A",[1869,1872,1875,1878,1881,1884,1887,1890,1893,1896,1899,1902,1905,1908,1911,1914,1917,1920,1923,1926,1929,1932,1935,1938,1941,1944,1947,1950,1953,1956,1959,1962,1965,1968,1971,1974,1977,1980,1983,1986,1989,1992,1995,1998,2001,2004,2007,2010,2013,2016,2019,2022,2025,2028,2031,2034,2037,2040,2043,2046,2049,2052,2055,2058,2061,2064,2067,2070,2073,2076,2079,2082,2085,2088,2091,2094,2097,2100,2103,2106,2109,2112,2115,2118,2121,2124,2127,2130,2133,2136,2139,2142,2145,2148,2151,2154,2157,2160,2163,2166,2169,2172,2175,2178,2181,2184,2187,2190,2191,2194,2197,2200,2203,2206,2209,2212,2215,2218,2221,2224,2227,2230,2233,2236,2239,2242,2245,2248,2251,2254,2257,2260,2263,2266,2269,2272,2275,2278,2281,2284,2286,2289,2292,2295,2298,2301,2304,2307,2310,2313,2316,2319,2322,2325,2328,2331,2334,2337,2340,2343,2346,2349,2352,2355,2358,2361,2364,2367,2370,2373,2376,2379,2382,2385,2388,2391,2394,2397,2400,2403,2406,2409,2412,2415,2418,2421,2424,2427,2430,2433,2436,2439,2442,2445,2448,2451,2454,2457,2460,2463,2466,2469,2472,2475,2478,2481,2484,2487,2490,2493,2496,2499,2502,2505,2508,2511,2514,2517,2520,2523,2526,2529,2532,2535,2538,2541,2544,2547,2550,2553,2556,2559,2562,2565,2568,2571,2574,2577,2580,2583,2586,2589,2592,2595,2598,2601,2604,2607,2610,2613,2616,2619,2622,2625,2628,2631,2634,2637,2640,2643,2646,2649,2652,2655,2658,2661,2664,2667,2670,2673,2676,2679,2682,2685,2688,2691,2694,2697,2700,2703,2706,2709],{"path":1870,"title":1871},"\u002Fabout","About Python CLI Toolcraft",{"path":1873,"title":1874},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies","Advanced Argument Validation Strategies",{"path":1876,"title":1877},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fparsing-nested-json-arguments-in-python-clis","Parsing Nested JSON Args in Python CLIs",{"path":1879,"title":1880},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-dates-and-durations-in-cli-arguments","Validating Dates and Durations in Python CLI Arguments",{"path":1882,"title":1883},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-dependent-and-conflicting-options","Validating Dependent and Conflicting CLI Options",{"path":1885,"title":1886},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-file-and-directory-paths-in-clis","Validating File and Directory Paths in CLIs",{"path":1888,"title":1889},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-urls-hosts-and-ports","Validating URLs, Hosts and Ports in Python CLI Arguments",{"path":1891,"title":1892},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fwriting-custom-click-parameter-types","Writing Custom Click Parameter Types",{"path":1894,"title":1895},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Fbrowsing-records-with-a-textual-datatable","Browsing Records with a Textual DataTable Picker",{"path":1897,"title":1898},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Fbuilding-your-first-textual-app","Building Your First Textual App for a Python CLI",{"path":1900,"title":1901},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Fchoosing-between-a-cli-a-prompt-flow-and-a-tui","Choosing Between a CLI, a Prompt Flow and a TUI",{"path":1903,"title":1904},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual","Building Terminal UIs with Textual for Python CLIs",{"path":1906,"title":1907},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Frunning-background-work-in-textual-with-workers","Running Background Work in Textual with Workers",{"path":1909,"title":1910},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Fstyling-textual-apps-with-tcss","Styling Textual Apps with TCSS",{"path":1912,"title":1913},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Ftesting-textual-apps-with-pilot","Testing Textual Apps with Pilot",{"path":1915,"title":1916},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fadding-examples-and-epilogs-to-help-output","Adding Examples and Epilogs to Help Output",{"path":1918,"title":1919},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fdocumenting-environment-variables-in-help","Documenting Environment Variables in CLI Help",{"path":1921,"title":1922},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fgenerating-man-pages-and-docs-from-a-cli","Generating Man Pages and Docs from a CLI",{"path":1924,"title":1925},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation","CLI Help Output and Documentation",{"path":1927,"title":1928},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Frich-formatted-help-with-rich-click","Rich-Formatted Help for Click CLIs with rich-click",{"path":1930,"title":1931},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fversioning-and-deprecating-cli-flags","Versioning and Deprecating CLI Flags",{"path":1933,"title":1934},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fwriting-help-text-users-actually-read","Writing Help Text Users Actually Read",{"path":1936,"title":1937},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fadapting-output-to-terminal-width","Adapting Python CLI Output to Terminal Width",{"path":1939,"title":1940},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fdetecting-ci-environments-and-non-interactive-shells","Detecting CI Environments and Non-Interactive Shells",{"path":1942,"title":1943},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Ffixing-unicode-and-encoding-errors-on-windows","Fixing Unicode and Encoding Errors on Windows in Python CLIs",{"path":1945,"title":1946},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fhandling-ansi-escape-codes-on-windows-consoles","Handling ANSI Escape Codes on Windows Consoles",{"path":1948,"title":1949},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility","Cross-Platform Terminal Compatibility for Python CLIs",{"path":1951,"title":1952},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Frespecting-no-color-and-force-color","Respecting NO_COLOR and FORCE_COLOR in Python CLIs",{"path":1954,"title":1955},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fsupporting-dumb-terminals-and-screen-readers","Supporting Dumb Terminals and Screen Readers in a Python CLI",{"path":1957,"title":1958},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fchoosing-exit-codes-for-cli-tools","Choosing Exit Codes for CLI Tools",{"path":1960,"title":1961},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fdesigning-an-exception-hierarchy-for-a-cli","Designing an Exception Hierarchy for a Python CLI",{"path":1963,"title":1964},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fdid-you-mean-suggestions-for-mistyped-input","Did You Mean…? Suggestions for Mistyped CLI Input",{"path":1966,"title":1967},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Ffriendly-error-messages-and-tracebacks","Friendly Error Messages and Tracebacks",{"path":1969,"title":1970},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fhandling-keyboard-interrupt-cleanly","Handling Keyboard Interrupt Cleanly",{"path":1972,"title":1973},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes","Error Handling and Exit Codes for CLIs",{"path":1975,"title":1976},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Freporting-machine-readable-errors-in-json-mode","Reporting Machine-Readable Errors in JSON Mode",{"path":1978,"title":1979},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fwriting-crash-reports-users-can-send","Writing Crash Reports Users Can Send",{"path":1981,"title":1982},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fconfig-precedence-flags-env-files-defaults","Config Precedence: Flags, Env, Files, Defaults",{"path":1984,"title":1985},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fdiscovering-project-config-files-by-walking-up-directories","Discovering Project Config Files by Walking Up Directories",{"path":1987,"title":1988},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars","Handling Config Files and Env Vars in CLIs",{"path":1990,"title":1991},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Floading-yaml-configs-safely-in-cli-apps","Loading YAML configs safely in CLI apps",{"path":1993,"title":1994},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Freading-toml-config-with-tomllib","Reading TOML Config with tomllib in Python CLIs",{"path":1996,"title":1997},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Ftyped-settings-with-pydantic-settings","Typed Settings with pydantic-settings in Python CLIs",{"path":1999,"title":2000},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fvalidating-config-files-with-json-schema","Validating Config Files with JSON Schema in a Python CLI",{"path":2002,"title":2003},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fwriting-a-config-init-and-edit-command","Writing a Config Init and Edit Command for a Python CLI",{"path":2005,"title":2006},"\u002Fadvanced-input-parsing-user-experience","Advanced Input Parsing for Python CLIs",{"path":2008,"title":2009},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Fadding-progress-bars-and-spinners-to-python-clis","Progress Bars and Spinners for Python CLIs",{"path":2011,"title":2012},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Fbuilding-interactive-prompts-and-menus","Building Interactive Prompts and Menus in Python CLIs",{"path":2014,"title":2015},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Fbuilding-tree-views-with-rich","Building Tree Views with Rich in a Python CLI",{"path":2017,"title":2018},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich","Interactive Terminal UI with Rich",{"path":2020,"title":2021},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Flive-dashboards-with-rich-live","Live Dashboards with Rich Live in Python CLIs",{"path":2023,"title":2024},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Frendering-markdown-and-syntax-highlighting-with-rich","Rendering Markdown and Syntax Highlighting with Rich",{"path":2026,"title":2027},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Frendering-tables-and-json-with-rich","Rendering Tables and JSON with Rich",{"path":2029,"title":2030},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Ftheming-rich-output-consistently","Theming Rich Output Consistently in Python CLIs",{"path":2032,"title":2033},"\u002Fadvanced-input-parsing-user-experience\u002Foutput-formats-for-data-clis\u002Fadding-a-format-flag-for-table-json-and-csv","Adding a Format Flag for Table, JSON and CSV Output",{"path":2035,"title":2036},"\u002Fadvanced-input-parsing-user-experience\u002Foutput-formats-for-data-clis\u002Fcustom-output-templates-with-a-format-string","Custom Output Templates with a Format String in Python CLIs",{"path":2038,"title":2039},"\u002Fadvanced-input-parsing-user-experience\u002Foutput-formats-for-data-clis\u002Fexporting-cli-results-to-files","Exporting CLI Results to Files from a Python CLI",{"path":2041,"title":2042},"\u002Fadvanced-input-parsing-user-experience\u002Foutput-formats-for-data-clis","Output Formats for Data-Heavy Python CLIs",{"path":2044,"title":2045},"\u002Fadvanced-input-parsing-user-experience\u002Foutput-formats-for-data-clis\u002Fselecting-fields-and-columns-from-cli-output","Selecting Fields and Columns from Python CLI Output",{"path":2047,"title":2048},"\u002Fadvanced-input-parsing-user-experience\u002Foutput-formats-for-data-clis\u002Fwriting-csv-and-tsv-output-correctly","Writing CSV and TSV Output Correctly from a Python CLI",{"path":2050,"title":2051},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Fargcomplete-for-argparse-clis","Tab Completion for argparse CLIs with argcomplete",{"path":2053,"title":2054},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Fdynamic-completion-values-from-apis-and-files","Dynamic Completion Values from APIs and Files",{"path":2056,"title":2057},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Fenabling-tab-completion-in-click-and-typer","Enabling Tab Completion in Click and Typer",{"path":2059,"title":2060},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis","Shell Completion for Python CLIs",{"path":2062,"title":2063},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Finstalling-shell-completion-for-bash-zsh-fish","Installing Shell Completion for bash, zsh, fish",{"path":2065,"title":2066},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Fshipping-completion-scripts-with-packages","Shipping Shell Completion Scripts with a Python CLI",{"path":2068,"title":2069},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Ftesting-shell-completion-in-python-clis","Testing Shell Completion in Python CLIs",{"path":2071,"title":2072},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-trace-ids-and-context-to-cli-logs","Adding Trace IDs and Context to Python CLI Logs",{"path":2074,"title":2075},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-verbose-and-quiet-logging-flags","Adding Verbose and Quiet Logging Flags",{"path":2077,"title":2078},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps","Structured Logging for CLI Apps",{"path":2080,"title":2081},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Flogging-with-structlog-in-a-cli","Logging with structlog in a Python CLI",{"path":2083,"title":2084},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fseparating-logs-from-program-output","Separating Logs from Program Output in a Python CLI",{"path":2086,"title":2087},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fstructured-json-logging-in-python-clis","Structured JSON Logging in Python CLIs",{"path":2089,"title":2090},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fwriting-rotating-log-files-from-a-cli","Writing Rotating Log Files from a Python CLI",{"path":2092,"title":2093},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fdetecting-tty-and-adapting-output","Detecting a TTY and Adapting Output",{"path":2095,"title":2096},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Femitting-json-output-for-scripting","Emitting JSON Output for Scripting",{"path":2098,"title":2099},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fhandling-broken-pipe-and-sigpipe","Handling Broken Pipe and SIGPIPE",{"path":2101,"title":2102},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes","Working with stdin, stdout and Pipes",{"path":2104,"title":2105},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fnull-delimited-input-and-xargs-compatibility","Null-Delimited Input and xargs Compatibility in Python CLIs",{"path":2107,"title":2108},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fprocessing-large-files-and-ndjson-streams","Processing Large Files and NDJSON Streams in Python CLIs",{"path":2110,"title":2111},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Freading-piped-input-in-python-clis","Reading Piped Input in Python CLIs",{"path":2113,"title":2114},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fbuilding-an-api-client-cli-with-httpx","Building an API Client CLI with httpx",{"path":2116,"title":2117},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fdownloading-files-with-progress-in-python","Downloading Files with Progress in Python CLIs",{"path":2119,"title":2120},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis","Calling HTTP APIs from Python CLIs",{"path":2122,"title":2123},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fmocking-http-in-cli-tests-with-respx","Mocking HTTP in Python CLI Tests with respx",{"path":2125,"title":2126},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Foauth-device-flow-login-for-clis","OAuth Device Flow Login for Python CLIs",{"path":2128,"title":2129},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fpaginating-api-results-in-a-cli","Paginating API Results in a Python CLI",{"path":2131,"title":2132},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fretries-and-backoff-for-cli-http-calls","Retries and Backoff for CLI HTTP Calls",{"path":2134,"title":2135},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fuploading-files-with-multipart-and-progress","Uploading Files with Multipart and Progress in a Python CLI",{"path":2137,"title":2138},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fcancelling-async-tasks-on-ctrl-c","Cancelling Async Tasks on Ctrl+C in Python CLIs",{"path":2140,"title":2141},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis","Concurrency and Async in Python CLIs",{"path":2143,"title":2144},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fmultiprocessing-for-cpu-bound-cli-tasks","Multiprocessing for CPU-Bound CLI Tasks",{"path":2146,"title":2147},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fparallelising-cli-work-with-thread-pools","Parallelising CLI Work with Thread Pools",{"path":2149,"title":2150},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Frate-limiting-concurrent-requests-in-clis","Rate-Limiting Concurrent Requests in Python CLIs",{"path":2152,"title":2153},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Frunning-async-code-in-typer-and-click","Running Async Code in Typer and Click",{"path":2155,"title":2156},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fshowing-progress-for-concurrent-tasks","Showing Progress for Concurrent Tasks in a Python CLI",{"path":2158,"title":2159},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fstructured-concurrency-with-taskgroups-in-clis","Structured Concurrency with TaskGroups in Python CLIs",{"path":2161,"title":2162},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fcross-platform-paths-with-pathlib","Cross-Platform Paths with pathlib in CLIs",{"path":2164,"title":2165},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Ffile-locking-for-concurrent-cli-runs","File Locking for Concurrent CLI Runs in Python",{"path":2167,"title":2168},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fhandling-file-permissions-and-umask-in-clis","Handling File Permissions and umask in Python CLIs",{"path":2170,"title":2171},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes","Filesystem Paths and Atomic Writes for CLIs",{"path":2173,"title":2174},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fsafe-temporary-files-and-directories","Safe Temporary Files and Directories in CLIs",{"path":2176,"title":2177},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fstoring-app-data-with-platformdirs","Storing CLI App Data with platformdirs",{"path":2179,"title":2180},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fwalking-directory-trees-with-ignore-rules","Walking Directory Trees with Ignore Rules in a Python CLI",{"path":2182,"title":2183},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fwriting-files-atomically-in-python-clis","Writing Files Atomically in Python CLIs",{"path":2185,"title":2186},"\u002Fcli-runtime-systems-integration","CLI Runtime & Systems Integration for Python",{"path":2188,"title":2189},"\u002Fcli-runtime-systems-integration\u002Flocal-state-and-sqlite-in-python-clis\u002Fcaching-http-responses-on-disk-in-a-cli","Caching HTTP Responses on Disk in a Python CLI",{"path":1858,"title":5},{"path":2192,"title":2193},"\u002Fcli-runtime-systems-integration\u002Flocal-state-and-sqlite-in-python-clis\u002Fmigrating-a-cli-sqlite-schema","Migrating a CLI’s SQLite Schema Between Releases",{"path":2195,"title":2196},"\u002Fcli-runtime-systems-integration\u002Flocal-state-and-sqlite-in-python-clis\u002Frecording-and-querying-cli-run-history","Recording and Querying CLI Run History in SQLite",{"path":2198,"title":2199},"\u002Fcli-runtime-systems-integration\u002Flocal-state-and-sqlite-in-python-clis\u002Fstoring-cli-state-in-sqlite","Storing CLI State in SQLite with a Small Repository Class",{"path":2201,"title":2202},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fbuilding-a-watch-mode-with-watchfiles","Building a Watch Mode with watchfiles in Python",{"path":2204,"title":2205},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fhandling-sigterm-and-graceful-shutdown","Handling SIGTERM and Graceful Shutdown in CLIs",{"path":2207,"title":2208},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fhealth-checks-and-heartbeats-for-long-running-clis","Health Checks and Heartbeats for Long-Running CLIs",{"path":2210,"title":2211},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis","Long-Running and Watch-Mode Python CLIs",{"path":2213,"title":2214},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Freloading-config-on-sighup","Reloading Configuration on SIGHUP in a Python CLI",{"path":2216,"title":2217},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Frunning-a-cli-as-a-systemd-service","Running a Python CLI as a systemd Service",{"path":2219,"title":2220},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Frunning-a-cli-on-a-schedule-with-cron-and-systemd","Running a Python CLI on a Schedule with cron and systemd",{"path":2222,"title":2223},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fsending-cli-logs-to-journald-and-syslog","Sending Python CLI Logs to journald and syslog",{"path":2225,"title":2226},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Favoiding-shell-injection-in-python-clis","Avoiding Shell Injection in Python CLIs",{"path":2228,"title":2229},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fcalling-external-commands-safely-with-subprocess","Calling External Commands Safely with subprocess",{"path":2231,"title":2232},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fhandling-subprocess-timeouts-and-exit-codes","Handling Subprocess Timeouts and Exit Codes",{"path":2234,"title":2235},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis","Running Subprocesses from Python CLIs",{"path":2237,"title":2238},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Flaunching-the-users-editor-from-a-cli","Launching the User’s Editor from a Python CLI",{"path":2240,"title":2241},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fpiping-between-subprocesses-in-python","Piping Between Subprocesses in Python Without a Shell",{"path":2243,"title":2244},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fstreaming-subprocess-output-in-real-time","Streaming Subprocess Output in Real Time",{"path":2246,"title":2247},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fwrapping-git-and-other-tools-from-a-python-cli","Wrapping git and Other Tools from a Python CLI",{"path":2249,"title":2250},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis","Secrets and Credentials in Python CLIs",{"path":2252,"title":2253},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fprompting-for-passwords-securely","Prompting for Passwords Securely in Python CLIs",{"path":2255,"title":2256},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Freading-secrets-from-env-and-files","Reading Secrets from Env Vars and Files in CLIs",{"path":2258,"title":2259},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fredacting-secrets-from-cli-output-and-logs","Redacting Secrets from CLI Output and Logs",{"path":2261,"title":2262},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Frefreshing-expired-tokens-automatically","Refreshing Expired Tokens Automatically in a Python CLI",{"path":2264,"title":2265},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fstoring-tokens-with-keyring","Storing CLI Tokens Securely with keyring",{"path":2267,"title":2268},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fsupporting-multiple-profiles-and-accounts","Supporting Multiple Profiles and Accounts in CLIs",{"path":2270,"title":2271},"\u002Fcli-runtime-systems-integration\u002Fupdate-checks-and-self-updating-clis\u002Fchecking-pypi-for-a-newer-version","Checking PyPI for a Newer Version of Your Python CLI",{"path":2273,"title":2274},"\u002Fcli-runtime-systems-integration\u002Fupdate-checks-and-self-updating-clis","Update Checks, Upgrade Commands and Telemetry for Python CLIs",{"path":2276,"title":2277},"\u002Fcli-runtime-systems-integration\u002Fupdate-checks-and-self-updating-clis\u002Fopt-in-usage-telemetry-for-python-clis","Opt-In Usage Telemetry for Python CLIs Done Responsibly",{"path":2279,"title":2280},"\u002Fcli-runtime-systems-integration\u002Fupdate-checks-and-self-updating-clis\u002Fself-upgrading-a-cli-installed-with-pipx-or-uv","Self-Upgrading a Python CLI Installed with pipx or uv",{"path":2282,"title":2283},"\u002Fcli-runtime-systems-integration\u002Fupdate-checks-and-self-updating-clis\u002Fshowing-non-blocking-update-notices","Showing Non-Blocking Update Notices in a Python CLI",{"path":354,"title":2285},"Python CLI Toolcraft",{"path":2287,"title":2288},"\u002Fmodern-python-cli-frameworks-architecture\u002Falternative-python-cli-frameworks\u002Fbuilding-a-cli-with-cleo","Building a Python CLI with Cleo Command Classes",{"path":2290,"title":2291},"\u002Fmodern-python-cli-frameworks-architecture\u002Falternative-python-cli-frameworks\u002Fbuilding-a-cli-with-cyclopts","Building a Type-Hinted Python CLI with Cyclopts",{"path":2293,"title":2294},"\u002Fmodern-python-cli-frameworks-architecture\u002Falternative-python-cli-frameworks","Beyond Click and Typer: Alternative Python CLI Frameworks",{"path":2296,"title":2297},"\u002Fmodern-python-cli-frameworks-architecture\u002Falternative-python-cli-frameworks\u002Fquick-clis-from-functions-with-python-fire","Quick CLIs from Functions with Python Fire",{"path":2299,"title":2300},"\u002Fmodern-python-cli-frameworks-architecture\u002Falternative-python-cli-frameworks\u002Fusage-string-driven-clis-with-docopt-ng","Usage-String Driven Python CLIs with docopt-ng",{"path":2302,"title":2303},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Favoiding-import-time-side-effects","Avoiding Import-Time Side Effects in a Python CLI",{"path":2305,"title":2306},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fcaching-expensive-work-between-cli-runs","Caching Expensive Work Between Python CLI Runs",{"path":2308,"title":2309},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fguarding-startup-with-import-tests","Guarding CLI Startup with Import Tests",{"path":2311,"title":2312},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading","CLI Startup Performance and Lazy Loading",{"path":2314,"title":2315},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup","Lazy Loading Subcommands for Faster Startup",{"path":2317,"title":2318},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fprofiling-python-cli-startup-time","Profiling Python CLI Startup Time",{"path":2320,"title":2321},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Freducing-cli-dependency-weight","Reducing CLI Dependency Weight",{"path":2323,"title":2324},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-subparsers-for-subcommands","argparse Subparsers for Subcommands",{"path":2326,"title":2327},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-vs-click-vs-typer-comparison","argparse vs Click vs Typer Compared",{"path":2329,"title":2330},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargument-groups-and-help-formatting-in-argparse","Argument Groups and Help Formatting in argparse",{"path":2332,"title":2333},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse","Command-Line Parsing with argparse",{"path":2335,"title":2336},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmigrating-from-argparse-to-typer","Migrating from argparse to Typer",{"path":2338,"title":2339},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmutually-exclusive-options-in-argparse","Mutually Exclusive Options in argparse",{"path":2341,"title":2342},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Freading-arguments-from-files-with-fromfile-prefix-chars","Reading Arguments from Files with argparse’s fromfile_prefix_chars",{"path":2344,"title":2345},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fwriting-custom-argparse-actions","Writing Custom argparse Actions in Python",{"path":2347,"title":2348},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fadding-dry-run-and-confirmation-to-destructive-commands","Adding Dry-Run and Confirmation to Destructive Commands",{"path":2350,"title":2351},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fdesigning-idempotent-commands","Designing Idempotent Commands in a Python CLI",{"path":2353,"title":2354},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Ffollowing-posix-and-gnu-argument-conventions","Following POSIX and GNU Argument Conventions in Python",{"path":2356,"title":2357},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fglobal-options-vs-per-command-options","Global Options vs Per-Command Options in Python CLIs",{"path":2359,"title":2360},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions","Designing CLI Interfaces and Conventions in Python",{"path":2362,"title":2363},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fnaming-commands-and-flags-consistently","Naming Commands and Flags Consistently in Python CLIs",{"path":2365,"title":2366},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fpositional-arguments-vs-options","Positional Arguments vs Options: Designing a CLI Signature",{"path":2368,"title":2369},"\u002Fmodern-python-cli-frameworks-architecture","Python CLI Frameworks and Architecture",{"path":2371,"title":2372},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fdiscovering-plugins-with-entry-points","Discovering Plugins with Entry Points in Python CLIs",{"path":2374,"title":2375},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fhook-based-plugins-with-pluggy","Hook-Based Plugins for Python CLIs with pluggy",{"path":2377,"title":2378},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis","Plugin Architectures for Extensible CLIs",{"path":2380,"title":2381},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fisolating-plugin-failures","Isolating Plugin Failures in an Extensible Python CLI",{"path":2383,"title":2384},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Ftesting-plugins-against-the-host-cli","Testing Plugins Against the Host CLI",{"path":2386,"title":2387},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fversioning-a-plugin-api","Versioning a Plugin API for a Python CLI",{"path":2389,"title":2390},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fwriting-a-plugin-for-an-existing-cli","Writing a Plugin for an Existing CLI",{"path":2392,"title":2393},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fbest-practices-for-python-cli-entry-points","Best practices for Python CLI entry points",{"path":2395,"title":2396},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fdependency-injection-patterns-for-cli-commands","Dependency Injection Patterns for CLI Commands",{"path":2398,"title":2399},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fhow-to-structure-a-large-python-cli-project","Structuring a Large Python CLI Project",{"path":2401,"title":2402},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis","Structuring Multi-Command Python CLIs",{"path":2404,"title":2405},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Foffering-a-python-api-alongside-your-cli","Offering a Python API Alongside Your CLI",{"path":2407,"title":2408},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fregistering-commands-from-modules-automatically","Registering CLI Commands from Modules Automatically",{"path":2410,"title":2411},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-common-options-across-commands","Sharing Common Options Across Python CLI Commands",{"path":2413,"title":2414},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-state-with-click-context-objects","Sharing State with Click Context Objects",{"path":2416,"title":2417},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fend-to-end-testing-an-installed-cli","End-to-End Testing an Installed Python CLI",{"path":2419,"title":2420},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications","Testing Python CLI Applications",{"path":2422,"title":2423},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fmeasuring-cli-test-coverage","Measuring CLI Test Coverage",{"path":2425,"title":2426},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fmocking-filesystem-and-network-in-cli-tests","Mocking the Filesystem and Network in CLI Tests",{"path":2428,"title":2429},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fproperty-based-testing-cli-arguments-with-hypothesis","Property-Based Testing CLI Arguments with Hypothesis",{"path":2431,"title":2432},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fsnapshot-testing-cli-output","Snapshot Testing CLI Output",{"path":2434,"title":2435},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-click-commands-with-clirunner","Testing Click Commands with CliRunner",{"path":2437,"title":2438},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-commands-that-call-subprocesses","Testing Python CLI Commands That Call Subprocesses",{"path":2440,"title":2441},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-interactive-prompts-and-stdin","Testing Interactive Prompts and stdin",{"path":2443,"title":2444},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftranscript-tests-for-cli-commands","Transcript Tests for Python CLI Commands",{"path":2446,"title":2447},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fbuilding-a-cli-with-subcommands-in-click","Building a CLI with subcommands in Click",{"path":2449,"title":2450},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fbuilding-dynamic-commands-in-click","Building Dynamic Commands in Click",{"path":2452,"title":2453},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fchoices-and-enums-in-typer-and-click","Choices and Enums in Typer and Click Options",{"path":2455,"title":2456},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fclick-option-callbacks-and-eager-options","Click Option Callbacks and Eager Options Explained",{"path":2458,"title":2459},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fconverting-a-click-app-to-typer","Converting a Click App to Typer",{"path":2461,"title":2462},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each","Typer vs Click: When to Use Each",{"path":2464,"title":2465},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Frich-markup-and-help-panels-in-typer","Rich Markup and Help Panels in Typer",{"path":2467,"title":2468},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Ftyper-callback-functions-explained","Typer callback functions explained",{"path":2470,"title":2471},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fusing-annotated-options-in-typer","Using Annotated Options in Typer",{"path":2473,"title":2474},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fautomating-releases-from-git-tags","Automating Python CLI Releases from Git Tags",{"path":2476,"title":2477},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fcaching-uv-dependencies-in-ci","Caching uv Dependencies in CI for Python CLIs",{"path":2479,"title":2480},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis","CI\u002FCD Pipelines for Python CLIs",{"path":2482,"title":2483},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fpublishing-a-cli-docker-image-from-ci","Publishing a Python CLI as a Docker Image from CI",{"path":2485,"title":2486},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fpublishing-to-pypi-with-trusted-publishing","Publishing a CLI to PyPI with Trusted Publishing",{"path":2488,"title":2489},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Frunning-cli-tests-on-windows-and-macos-runners","Running Python CLI Tests on Windows and macOS Runners",{"path":2491,"title":2492},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fsmoke-testing-the-built-wheel-in-ci","Smoke-Testing the Built Wheel of a Python CLI in CI",{"path":2494,"title":2495},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Ftesting-a-cli-across-python-versions-with-github-actions","Testing a CLI Across Python Versions in GitHub Actions",{"path":2497,"title":2498},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fbuilding-a-cookiecutter-template-for-typer-clis","Building a Cookiecutter Template for Typer CLIs",{"path":2500,"title":2501},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fcopier-vs-cookiecutter-for-cli-templates","Copier vs Cookiecutter for CLI Templates",{"path":2503,"title":2504},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter","CLI Project Scaffolding with Cookiecutter",{"path":2506,"title":2507},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fpost-generation-hooks-in-cli-templates","Post-Generation Hooks in Python CLI Templates",{"path":2509,"title":2510},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Ftemplate-variables-and-conditional-files","Template Variables and Conditional Files in CLI Templates",{"path":2512,"title":2513},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Ftesting-a-project-template-with-pytest","Testing a CLI Project Template with pytest",{"path":2515,"title":2516},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fupdating-generated-projects-with-copier-update","Updating Generated CLI Projects with copier update",{"path":2518,"title":2519},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbuilding-cross-platform-release-binaries-in-ci","Building Cross-Platform Release Binaries in CI",{"path":2521,"title":2522},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbundling-a-python-cli-with-pyinstaller","Bundling a Python CLI with PyInstaller",{"path":2524,"title":2525},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fcode-signing-and-notarizing-cli-binaries","Code Signing and Notarizing Python CLI Binaries",{"path":2527,"title":2528},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fhomebrew-and-scoop-packaging-for-python-clis","Homebrew and Scoop Packaging for Python CLIs",{"path":2530,"title":2531},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries","Distributing CLIs as Standalone Binaries",{"path":2533,"title":2534},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fnuitka-vs-pyinstaller-for-python-clis","Nuitka vs PyInstaller for Python CLI Binaries",{"path":2536,"title":2537},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Freducing-pyinstaller-binary-size","Reducing the Size of a PyInstaller CLI Binary",{"path":2539,"title":2540},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fshipping-a-cli-as-a-zipapp-with-shiv","Shipping a CLI as a Zipapp with shiv",{"path":2542,"title":2543},"\u002Fproject-setup-dependency-management","Project Setup & Dependency Management",{"path":2545,"title":2546},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Fconfiguring-ruff-for-a-cli-project","Configuring Ruff for a Python CLI Project",{"path":2548,"title":2549},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Fenforcing-import-boundaries-in-a-cli-codebase","Enforcing Import Boundaries in a Python CLI Codebase",{"path":2551,"title":2552},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Ffinding-unused-code-and-dependencies-with-vulture-and-deptry","Finding Unused Code and Dependencies with vulture and deptry",{"path":2554,"title":2555},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code","Linting and Type-Checking Python CLI Code",{"path":2557,"title":2558},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Frunning-pyright-in-strict-mode-on-a-cli","Running Pyright in Strict Mode on a Python CLI",{"path":2560,"title":2561},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Frunning-ruff-and-mypy-in-ci-with-annotations","Running Ruff and mypy in CI with Inline Annotations",{"path":2563,"title":2564},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Ftype-checking-click-and-typer-code-with-mypy","Type-Checking Click and Typer Code with mypy",{"path":2566,"title":2567},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fautomating-changelogs-with-conventional-commits","Automating Changelogs with Conventional Commits",{"path":2569,"title":2570},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fbumping-versions-consistently-across-a-cli-project","Bumping Versions Consistently Across a Python CLI Project",{"path":2572,"title":2573},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fderiving-versions-from-git-tags-with-hatch-vcs","Deriving CLI Versions from Git Tags with hatch-vcs",{"path":2575,"title":2576},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fexposing-version-info-and-build-metadata","Exposing Version Info and Build Metadata",{"path":2578,"title":2579},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs","Managing CLI Versioning & Changelogs",{"path":2581,"title":2582},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fsemantic-versioning-policy-for-cli-tools","A Semantic Versioning Policy for CLI Tools",{"path":2584,"title":2585},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fshipping-pre-releases-and-release-candidates","Shipping Pre-Releases and Release Candidates of a Python CLI",{"path":2587,"title":2588},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbuilding-wheels-and-sdists-for-python-clis","Building Wheels and sdists for Python CLIs",{"path":2590,"title":2591},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbundling-data-files-with-importlib-resources","Bundling Data Files with importlib.resources in CLIs",{"path":2593,"title":2594},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fchoosing-a-build-backend-for-a-python-cli","Choosing a Build Backend for a Python CLI",{"path":2596,"title":2597},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution","Packaging Python CLIs for Distribution",{"path":2599,"title":2600},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Finstalling-and-distributing-clis-with-pipx","Installing and Distributing CLIs with pipx",{"path":2602,"title":2603},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Foptional-dependencies-and-extras-for-clis","Optional Dependencies and Extras for Python CLIs",{"path":2605,"title":2606},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fpublishing-a-python-cli-to-pypi","Publishing a Python CLI to PyPI",{"path":2608,"title":2609},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fwriting-pyproject-toml-metadata-for-a-cli","Writing pyproject.toml Metadata for a Python CLI",{"path":2611,"title":2612},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fdynamic-versioning-with-poetry-plugins","Dynamic Versioning for a Poetry CLI from Git Tags",{"path":2614,"title":2615},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development","Poetry Workflows for CLI Development",{"path":2617,"title":2618},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fmanaging-poetry-lock-files-for-cli-tools","Managing Poetry Lock Files for CLI Tools",{"path":2620,"title":2621},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fmigrating-a-cli-from-poetry-to-uv","Migrating a Python CLI from Poetry to uv",{"path":2623,"title":2624},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-dependency-groups-for-cli-tooling","Poetry Dependency Groups for CLI Tooling",{"path":2626,"title":2627},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-entry-points-and-scripts-for-clis","Poetry Entry Points and Scripts for CLIs",{"path":2629,"title":2630},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpublishing-a-cli-with-poetry","Building and Publishing a Python CLI with Poetry",{"path":2632,"title":2633},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects","Pre-commit Hooks for CLI Projects",{"path":2635,"title":2636},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects\u002Fkeeping-hook-versions-current-with-autoupdate","Keeping pre-commit Hook Versions Current with autoupdate",{"path":2638,"title":2639},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects\u002Frunning-pre-commit-in-ci","Running pre-commit in CI for a Python CLI Repository",{"path":2641,"title":2642},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects\u002Fsetting-up-pre-commit-for-python-cli-repos","Setting up pre-commit for Python CLI repos",{"path":2644,"title":2645},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects\u002Fshipping-your-cli-as-a-pre-commit-hook","Shipping Your Python CLI as a pre-commit Hook",{"path":2647,"title":2648},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects\u002Fspeeding-up-slow-pre-commit-hooks","Speeding Up Slow pre-commit Hooks in a CLI Repository",{"path":2650,"title":2651},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects\u002Fwriting-local-pre-commit-hooks-in-python","Writing Local pre-commit Hooks in Python",{"path":2653,"title":2654},"\u002Fproject-setup-dependency-management\u002Fsecuring-a-python-cli-supply-chain\u002Fauditing-dependencies-with-pip-audit","Auditing a Python CLI’s Dependencies with pip-audit",{"path":2656,"title":2657},"\u002Fproject-setup-dependency-management\u002Fsecuring-a-python-cli-supply-chain\u002Fgenerating-an-sbom-for-a-python-cli","Generating an SBOM for a Python CLI Release",{"path":2659,"title":2660},"\u002Fproject-setup-dependency-management\u002Fsecuring-a-python-cli-supply-chain","Securing the Supply Chain of a Python CLI",{"path":2662,"title":2663},"\u002Fproject-setup-dependency-management\u002Fsecuring-a-python-cli-supply-chain\u002Fpinning-dependencies-with-hashes","Pinning a Python CLI’s Dependencies with Hashes",{"path":2665,"title":2666},"\u002Fproject-setup-dependency-management\u002Fsecuring-a-python-cli-supply-chain\u002Fpublishing-attestations-and-verifying-releases","Publishing Attestations and Verifying Python CLI Releases",{"path":2668,"title":2669},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fbuilding-and-publishing-a-cli-with-uv","Building and Publishing a Python CLI with uv",{"path":2671,"title":2672},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management","uv for Python CLI Dependency Management",{"path":2674,"title":2675},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Flocking-and-syncing-cli-dependencies-with-uv","Locking and Syncing a Python CLI’s Dependencies with uv",{"path":2677,"title":2678},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Frunning-one-off-cli-scripts-with-uv-run","Running One-Off CLI Scripts with uv run and PEP 723",{"path":2680,"title":2681},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fusing-private-package-indexes-with-uv","Using Private Package Indexes with uv for Internal CLIs",{"path":2683,"title":2684},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fuv-init-vs-poetry-init-for-cli-tools","uv init vs poetry init for CLI tools",{"path":2686,"title":2687},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fuv-tool-install-vs-pipx-for-clis","uv tool install vs pipx for CLIs",{"path":2689,"title":2690},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fuv-workspaces-for-multi-package-clis","uv Workspaces for Multi-Package Python CLIs",{"path":2692,"title":2693},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fdebugging-wrong-python-and-wrong-venv-problems","Debugging Wrong-Python and Wrong-Venv Problems in CLIs",{"path":2695,"title":2696},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fexternally-managed-environments-and-pep-668","PEP 668 and Python CLIs: the externally-managed-environment Error",{"path":2698,"title":2699},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices","Python CLI Env Isolation Best Practices",{"path":2701,"title":2702},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fisolating-cli-tools-from-project-dependencies","Isolating CLI Tools from Your Project’s Dependencies",{"path":2704,"title":2705},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fmanaging-virtual-environments-for-cross-platform-clis","Managing Python CLI Virtual Environments",{"path":2707,"title":2708},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fpinning-the-python-version-for-a-cli","Pinning the Python Version for a CLI",{"path":2710,"title":2711},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fsupporting-multiple-python-versions-with-nox","Supporting Multiple Python Versions with nox",1790967539849]