[{"data":1,"prerenderedAt":3230},["ShallowReactive",2],{"page-\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fcaching-expensive-work-between-cli-runs\u002F":3,"content-directory":2683},{"id":4,"title":5,"body":6,"date":2668,"description":2669,"difficulty":2670,"draft":2671,"extension":2672,"meta":2673,"navigation":135,"path":2674,"seo":2675,"stem":2676,"tags":2677,"updated":2668,"__hash__":2682},"content\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fcaching-expensive-work-between-cli-runs\u002Findex.md","Caching Expensive Work Between Python CLI Runs",{"type":7,"value":8,"toc":2649},"minimark",[9,19,24,49,53,57,73,77,80,87,90,94,1193,1196,1794,1799,1812,1818,1824,1835,1841,1858,1862,1905,1909,1912,2537,2544,2548,2554,2558,2570,2579,2583,2590,2594,2597,2601,2612,2616,2645],[10,11,12,13,18],"p",{},"A CLI process starts from nothing every time. Whatever it computed on the last run — a parsed project index, a resolved dependency graph, a list of repositories fetched from an API, compiled templates — is gone, and the next invocation does it all again. For a command people run dozens of times an hour, or that shell completion calls on every Tab press, that repeated work is the difference between a tool that feels instant and one that feels sluggish. Caching results on disk between runs fixes it, but a cache that returns a wrong answer is worse than no cache at all. This guide builds a small, safe on-disk cache for a Python CLI: keys that capture everything the result depends on, time-to-live for remote data, atomic writes, an escape hatch for users, and tests that prove invalidation works. It belongs to the ",[14,15,17],"a",{"href":16},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002F","CLI startup performance and lazy loading topic",".",[20,21,23],"h2",{"id":22},"prerequisites","Prerequisites",[25,26,27,41],"ul",{},[28,29,30,31,35,36,40],"li",{},"Python 3.10+, and ",[32,33,34],"code",{},"platformdirs"," for the cache location (see ",[14,37,39],{"href":38},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fstoring-app-data-with-platformdirs\u002F","storing app data with platformdirs",").",[28,42,43,44,48],{},"A measurement showing the work is actually slow. ",[14,45,47],{"href":46},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fprofiling-python-cli-startup-time\u002F","Profiling Python CLI startup time"," shows how to find where time goes; if imports dominate, lazy loading helps more than caching.",[20,50,52],{"id":51},"is-it-worth-caching","Is it worth caching?",[54,55],"inline-diagram",{"name":56},"ch-decision",[10,58,59,60,64,65,68,69,72],{},"Caching pays when the work is ",[61,62,63],"strong",{},"slow"," (hundreds of milliseconds or more), ",[61,66,67],{},"repeated with the same inputs"," (the same project, the same API query), and ",[61,70,71],{},"safe to recompute"," if the cache turns out to be wrong. It is a poor fit for work that is fast already, whose inputs change on every run, or whose correctness is critical and hard to validate. For a CLI, the classic candidates are: indexing or parsing a project tree, fetching slowly changing remote data (a list of teams, regions, available versions), expensive computations whose inputs are files, and anything shell completion needs.",[20,74,76],{"id":75},"the-shape-of-a-trustworthy-cache","The shape of a trustworthy cache",[54,78],{"name":79},"ch-flow",[10,81,82,83,86],{},"The one rule that makes a cache trustworthy: ",[61,84,85],{},"everything that can change the answer must be part of the key",". For work derived from files, that means the files' contents (or, more cheaply, their paths, sizes and modification times). For every cache, it also means the version of your tool — otherwise an upgrade that changes the computation returns results computed by the old code. For remote data, where you cannot see the inputs, a time-to-live bounds staleness instead.",[54,88],{"name":89},"ch-invalidation",[20,91,93],{"id":92},"the-recipe","The recipe",[95,96,101],"pre",{"className":97,"code":98,"language":99,"meta":100,"style":100},"language-python shiki shiki-themes github-light github-dark","# src\u002Fmytool\u002Fcache.py\nfrom __future__ import annotations\n\nimport hashlib\nimport json\nimport os\nimport tempfile\nimport time\nfrom collections.abc import Callable\nfrom importlib.metadata import PackageNotFoundError, version\nfrom pathlib import Path\nfrom typing import Any\n\nfrom platformdirs import user_cache_path\n\ntry:\n    TOOL_VERSION = version(\"mytool\")\nexcept PackageNotFoundError:\n    TOOL_VERSION = \"dev\"\n\nFORMAT = 1          # bump when the cache entry layout changes\n\n\nclass DiskCache:\n    def __init__(self, directory: Path | None = None, enabled: bool = True,\n                 clock: Callable[[], float] = time.time) -> None:\n        self.dir = directory or user_cache_path(\"mytool\", appauthor=False) \u002F \"results\"\n        self.enabled = enabled and os.environ.get(\"MYTOOL_NO_CACHE\") != \"1\"\n        self.clock = clock\n\n    @staticmethod\n    def key(namespace: str, **parts: Any) -> str:\n        payload = json.dumps({\"ns\": namespace, \"v\": TOOL_VERSION, \"fmt\": FORMAT, **parts},\n                             sort_keys=True, default=str)\n        return hashlib.sha256(payload.encode()).hexdigest()\n\n    def get(self, key: str, max_age: float | None = None) -> Any | None:\n        if not self.enabled:\n            return None\n        path = self.dir \u002F f\"{key}.json\"\n        try:\n            entry = json.loads(path.read_text(encoding=\"utf-8\"))\n        except (FileNotFoundError, json.JSONDecodeError, UnicodeDecodeError):\n            return None                                   # missing or corrupt: a miss, never an error\n        if max_age is not None and self.clock() - entry[\"created\"] > max_age:\n            return None\n        return entry[\"value\"]\n\n    def set(self, key: str, value: Any) -> None:\n        if not self.enabled:\n            return\n        self.dir.mkdir(parents=True, exist_ok=True)\n        data = json.dumps({\"created\": self.clock(), \"value\": value})\n        fd, tmp = tempfile.mkstemp(dir=self.dir, suffix=\".tmp\")\n        with os.fdopen(fd, \"w\", encoding=\"utf-8\") as fh:\n            fh.write(data)\n        os.replace(tmp, self.dir \u002F f\"{key}.json\")          # readers never see half an entry\n\n    def clear(self) -> int:\n        removed = 0\n        for p in self.dir.glob(\"*.json\"):\n            p.unlink(missing_ok=True)\n            removed += 1\n        return removed\n\n\ndef files_fingerprint(paths: list[Path]) -> list[tuple[str, int, int]]:\n    \"\"\"Cheap change detection: path, size and mtime in nanoseconds for each file.\"\"\"\n    fp = []\n    for p in sorted(paths):\n        st = p.stat()\n        fp.append((str(p), st.st_size, st.st_mtime_ns))\n    return fp\n","python","",[32,102,103,112,130,137,146,154,162,170,178,191,204,217,230,235,248,253,262,281,290,300,305,319,324,329,341,377,400,443,473,486,491,500,526,568,590,599,604,640,655,664,696,704,726,747,757,797,804,817,822,841,852,858,884,909,940,968,974,1005,1010,1026,1037,1059,1074,1086,1094,1099,1104,1129,1135,1146,1162,1173,1184],{"__ignoreMap":100},[104,105,108],"span",{"class":106,"line":107},"line",1,[104,109,111],{"class":110},"sJ8bj","# src\u002Fmytool\u002Fcache.py\n",[104,113,115,119,123,126],{"class":106,"line":114},2,[104,116,118],{"class":117},"szBVR","from",[104,120,122],{"class":121},"sj4cs"," __future__",[104,124,125],{"class":117}," import",[104,127,129],{"class":128},"sVt8B"," annotations\n",[104,131,133],{"class":106,"line":132},3,[104,134,136],{"emptyLinePlaceholder":135},true,"\n",[104,138,140,143],{"class":106,"line":139},4,[104,141,142],{"class":117},"import",[104,144,145],{"class":128}," hashlib\n",[104,147,149,151],{"class":106,"line":148},5,[104,150,142],{"class":117},[104,152,153],{"class":128}," json\n",[104,155,157,159],{"class":106,"line":156},6,[104,158,142],{"class":117},[104,160,161],{"class":128}," os\n",[104,163,165,167],{"class":106,"line":164},7,[104,166,142],{"class":117},[104,168,169],{"class":128}," tempfile\n",[104,171,173,175],{"class":106,"line":172},8,[104,174,142],{"class":117},[104,176,177],{"class":128}," time\n",[104,179,181,183,186,188],{"class":106,"line":180},9,[104,182,118],{"class":117},[104,184,185],{"class":128}," collections.abc ",[104,187,142],{"class":117},[104,189,190],{"class":128}," Callable\n",[104,192,194,196,199,201],{"class":106,"line":193},10,[104,195,118],{"class":117},[104,197,198],{"class":128}," importlib.metadata ",[104,200,142],{"class":117},[104,202,203],{"class":128}," PackageNotFoundError, version\n",[104,205,207,209,212,214],{"class":106,"line":206},11,[104,208,118],{"class":117},[104,210,211],{"class":128}," pathlib ",[104,213,142],{"class":117},[104,215,216],{"class":128}," Path\n",[104,218,220,222,225,227],{"class":106,"line":219},12,[104,221,118],{"class":117},[104,223,224],{"class":128}," typing ",[104,226,142],{"class":117},[104,228,229],{"class":128}," Any\n",[104,231,233],{"class":106,"line":232},13,[104,234,136],{"emptyLinePlaceholder":135},[104,236,238,240,243,245],{"class":106,"line":237},14,[104,239,118],{"class":117},[104,241,242],{"class":128}," platformdirs ",[104,244,142],{"class":117},[104,246,247],{"class":128}," user_cache_path\n",[104,249,251],{"class":106,"line":250},15,[104,252,136],{"emptyLinePlaceholder":135},[104,254,256,259],{"class":106,"line":255},16,[104,257,258],{"class":117},"try",[104,260,261],{"class":128},":\n",[104,263,265,268,271,274,278],{"class":106,"line":264},17,[104,266,267],{"class":121},"    TOOL_VERSION",[104,269,270],{"class":117}," =",[104,272,273],{"class":128}," version(",[104,275,277],{"class":276},"sZZnC","\"mytool\"",[104,279,280],{"class":128},")\n",[104,282,284,287],{"class":106,"line":283},18,[104,285,286],{"class":117},"except",[104,288,289],{"class":128}," PackageNotFoundError:\n",[104,291,293,295,297],{"class":106,"line":292},19,[104,294,267],{"class":121},[104,296,270],{"class":117},[104,298,299],{"class":276}," \"dev\"\n",[104,301,303],{"class":106,"line":302},20,[104,304,136],{"emptyLinePlaceholder":135},[104,306,308,311,313,316],{"class":106,"line":307},21,[104,309,310],{"class":121},"FORMAT",[104,312,270],{"class":117},[104,314,315],{"class":121}," 1",[104,317,318],{"class":110},"          # bump when the cache entry layout changes\n",[104,320,322],{"class":106,"line":321},22,[104,323,136],{"emptyLinePlaceholder":135},[104,325,327],{"class":106,"line":326},23,[104,328,136],{"emptyLinePlaceholder":135},[104,330,332,335,339],{"class":106,"line":331},24,[104,333,334],{"class":117},"class",[104,336,338],{"class":337},"sScJk"," DiskCache",[104,340,261],{"class":128},[104,342,344,347,350,353,356,359,361,363,366,369,371,374],{"class":106,"line":343},25,[104,345,346],{"class":117},"    def",[104,348,349],{"class":121}," __init__",[104,351,352],{"class":128},"(self, directory: Path ",[104,354,355],{"class":117},"|",[104,357,358],{"class":121}," None",[104,360,270],{"class":117},[104,362,358],{"class":121},[104,364,365],{"class":128},", enabled: ",[104,367,368],{"class":121},"bool",[104,370,270],{"class":117},[104,372,373],{"class":121}," True",[104,375,376],{"class":128},",\n",[104,378,380,383,386,389,392,395,398],{"class":106,"line":379},26,[104,381,382],{"class":128},"                 clock: Callable[[], ",[104,384,385],{"class":121},"float",[104,387,388],{"class":128},"] ",[104,390,391],{"class":117},"=",[104,393,394],{"class":128}," time.time) -> ",[104,396,397],{"class":121},"None",[104,399,261],{"class":128},[104,401,403,406,409,411,414,417,420,422,425,429,431,434,437,440],{"class":106,"line":402},27,[104,404,405],{"class":121},"        self",[104,407,408],{"class":128},".dir ",[104,410,391],{"class":117},[104,412,413],{"class":128}," directory ",[104,415,416],{"class":117},"or",[104,418,419],{"class":128}," user_cache_path(",[104,421,277],{"class":276},[104,423,424],{"class":128},", ",[104,426,428],{"class":427},"s4XuR","appauthor",[104,430,391],{"class":117},[104,432,433],{"class":121},"False",[104,435,436],{"class":128},") ",[104,438,439],{"class":117},"\u002F",[104,441,442],{"class":276}," \"results\"\n",[104,444,446,448,451,453,456,459,462,465,467,470],{"class":106,"line":445},28,[104,447,405],{"class":121},[104,449,450],{"class":128},".enabled ",[104,452,391],{"class":117},[104,454,455],{"class":128}," enabled ",[104,457,458],{"class":117},"and",[104,460,461],{"class":128}," os.environ.get(",[104,463,464],{"class":276},"\"MYTOOL_NO_CACHE\"",[104,466,436],{"class":128},[104,468,469],{"class":117},"!=",[104,471,472],{"class":276}," \"1\"\n",[104,474,476,478,481,483],{"class":106,"line":475},29,[104,477,405],{"class":121},[104,479,480],{"class":128},".clock ",[104,482,391],{"class":117},[104,484,485],{"class":128}," clock\n",[104,487,489],{"class":106,"line":488},30,[104,490,136],{"emptyLinePlaceholder":135},[104,492,494,497],{"class":106,"line":493},31,[104,495,496],{"class":337},"    @",[104,498,499],{"class":121},"staticmethod\n",[104,501,503,505,508,511,514,516,519,522,524],{"class":106,"line":502},32,[104,504,346],{"class":117},[104,506,507],{"class":337}," key",[104,509,510],{"class":128},"(namespace: ",[104,512,513],{"class":121},"str",[104,515,424],{"class":128},[104,517,518],{"class":117},"**",[104,520,521],{"class":128},"parts: Any) -> ",[104,523,513],{"class":121},[104,525,261],{"class":128},[104,527,529,532,534,537,540,543,546,549,552,554,557,559,561,563,565],{"class":106,"line":528},33,[104,530,531],{"class":128},"        payload ",[104,533,391],{"class":117},[104,535,536],{"class":128}," json.dumps({",[104,538,539],{"class":276},"\"ns\"",[104,541,542],{"class":128},": namespace, ",[104,544,545],{"class":276},"\"v\"",[104,547,548],{"class":128},": ",[104,550,551],{"class":121},"TOOL_VERSION",[104,553,424],{"class":128},[104,555,556],{"class":276},"\"fmt\"",[104,558,548],{"class":128},[104,560,310],{"class":121},[104,562,424],{"class":128},[104,564,518],{"class":117},[104,566,567],{"class":128},"parts},\n",[104,569,571,574,576,579,581,584,586,588],{"class":106,"line":570},34,[104,572,573],{"class":427},"                             sort_keys",[104,575,391],{"class":117},[104,577,578],{"class":121},"True",[104,580,424],{"class":128},[104,582,583],{"class":427},"default",[104,585,391],{"class":117},[104,587,513],{"class":121},[104,589,280],{"class":128},[104,591,593,596],{"class":106,"line":592},35,[104,594,595],{"class":117},"        return",[104,597,598],{"class":128}," hashlib.sha256(payload.encode()).hexdigest()\n",[104,600,602],{"class":106,"line":601},36,[104,603,136],{"emptyLinePlaceholder":135},[104,605,607,609,612,615,617,620,622,625,627,629,631,634,636,638],{"class":106,"line":606},37,[104,608,346],{"class":117},[104,610,611],{"class":337}," get",[104,613,614],{"class":128},"(self, key: ",[104,616,513],{"class":121},[104,618,619],{"class":128},", max_age: ",[104,621,385],{"class":121},[104,623,624],{"class":117}," |",[104,626,358],{"class":121},[104,628,270],{"class":117},[104,630,358],{"class":121},[104,632,633],{"class":128},") -> Any ",[104,635,355],{"class":117},[104,637,358],{"class":121},[104,639,261],{"class":128},[104,641,643,646,649,652],{"class":106,"line":642},38,[104,644,645],{"class":117},"        if",[104,647,648],{"class":117}," not",[104,650,651],{"class":121}," self",[104,653,654],{"class":128},".enabled:\n",[104,656,658,661],{"class":106,"line":657},39,[104,659,660],{"class":117},"            return",[104,662,663],{"class":121}," None\n",[104,665,667,670,672,674,676,678,681,684,687,690,693],{"class":106,"line":666},40,[104,668,669],{"class":128},"        path ",[104,671,391],{"class":117},[104,673,651],{"class":121},[104,675,408],{"class":128},[104,677,439],{"class":117},[104,679,680],{"class":117}," f",[104,682,683],{"class":276},"\"",[104,685,686],{"class":121},"{",[104,688,689],{"class":128},"key",[104,691,692],{"class":121},"}",[104,694,695],{"class":276},".json\"\n",[104,697,699,702],{"class":106,"line":698},41,[104,700,701],{"class":117},"        try",[104,703,261],{"class":128},[104,705,707,710,712,715,718,720,723],{"class":106,"line":706},42,[104,708,709],{"class":128},"            entry ",[104,711,391],{"class":117},[104,713,714],{"class":128}," json.loads(path.read_text(",[104,716,717],{"class":427},"encoding",[104,719,391],{"class":117},[104,721,722],{"class":276},"\"utf-8\"",[104,724,725],{"class":128},"))\n",[104,727,729,732,735,738,741,744],{"class":106,"line":728},43,[104,730,731],{"class":117},"        except",[104,733,734],{"class":128}," (",[104,736,737],{"class":121},"FileNotFoundError",[104,739,740],{"class":128},", json.JSONDecodeError, ",[104,742,743],{"class":121},"UnicodeDecodeError",[104,745,746],{"class":128},"):\n",[104,748,750,752,754],{"class":106,"line":749},44,[104,751,660],{"class":117},[104,753,358],{"class":121},[104,755,756],{"class":110},"                                   # missing or corrupt: a miss, never an error\n",[104,758,760,762,765,768,770,772,775,777,780,783,786,789,791,794],{"class":106,"line":759},45,[104,761,645],{"class":117},[104,763,764],{"class":128}," max_age ",[104,766,767],{"class":117},"is",[104,769,648],{"class":117},[104,771,358],{"class":121},[104,773,774],{"class":117}," and",[104,776,651],{"class":121},[104,778,779],{"class":128},".clock() ",[104,781,782],{"class":117},"-",[104,784,785],{"class":128}," entry[",[104,787,788],{"class":276},"\"created\"",[104,790,388],{"class":128},[104,792,793],{"class":117},">",[104,795,796],{"class":128}," max_age:\n",[104,798,800,802],{"class":106,"line":799},46,[104,801,660],{"class":117},[104,803,663],{"class":121},[104,805,807,809,811,814],{"class":106,"line":806},47,[104,808,595],{"class":117},[104,810,785],{"class":128},[104,812,813],{"class":276},"\"value\"",[104,815,816],{"class":128},"]\n",[104,818,820],{"class":106,"line":819},48,[104,821,136],{"emptyLinePlaceholder":135},[104,823,825,827,830,832,834,837,839],{"class":106,"line":824},49,[104,826,346],{"class":117},[104,828,829],{"class":121}," set",[104,831,614],{"class":128},[104,833,513],{"class":121},[104,835,836],{"class":128},", value: Any) -> ",[104,838,397],{"class":121},[104,840,261],{"class":128},[104,842,844,846,848,850],{"class":106,"line":843},50,[104,845,645],{"class":117},[104,847,648],{"class":117},[104,849,651],{"class":121},[104,851,654],{"class":128},[104,853,855],{"class":106,"line":854},51,[104,856,857],{"class":117},"            return\n",[104,859,861,863,866,869,871,873,875,878,880,882],{"class":106,"line":860},52,[104,862,405],{"class":121},[104,864,865],{"class":128},".dir.mkdir(",[104,867,868],{"class":427},"parents",[104,870,391],{"class":117},[104,872,578],{"class":121},[104,874,424],{"class":128},[104,876,877],{"class":427},"exist_ok",[104,879,391],{"class":117},[104,881,578],{"class":121},[104,883,280],{"class":128},[104,885,887,890,892,894,896,898,901,904,906],{"class":106,"line":886},53,[104,888,889],{"class":128},"        data ",[104,891,391],{"class":117},[104,893,536],{"class":128},[104,895,788],{"class":276},[104,897,548],{"class":128},[104,899,900],{"class":121},"self",[104,902,903],{"class":128},".clock(), ",[104,905,813],{"class":276},[104,907,908],{"class":128},": value})\n",[104,910,912,915,917,920,923,925,927,930,933,935,938],{"class":106,"line":911},54,[104,913,914],{"class":128},"        fd, tmp ",[104,916,391],{"class":117},[104,918,919],{"class":128}," tempfile.mkstemp(",[104,921,922],{"class":427},"dir",[104,924,391],{"class":117},[104,926,900],{"class":121},[104,928,929],{"class":128},".dir, ",[104,931,932],{"class":427},"suffix",[104,934,391],{"class":117},[104,936,937],{"class":276},"\".tmp\"",[104,939,280],{"class":128},[104,941,943,946,949,952,954,956,958,960,962,965],{"class":106,"line":942},55,[104,944,945],{"class":117},"        with",[104,947,948],{"class":128}," os.fdopen(fd, ",[104,950,951],{"class":276},"\"w\"",[104,953,424],{"class":128},[104,955,717],{"class":427},[104,957,391],{"class":117},[104,959,722],{"class":276},[104,961,436],{"class":128},[104,963,964],{"class":117},"as",[104,966,967],{"class":128}," fh:\n",[104,969,971],{"class":106,"line":970},56,[104,972,973],{"class":128},"            fh.write(data)\n",[104,975,977,980,982,984,986,988,990,992,994,996,999,1002],{"class":106,"line":976},57,[104,978,979],{"class":128},"        os.replace(tmp, ",[104,981,900],{"class":121},[104,983,408],{"class":128},[104,985,439],{"class":117},[104,987,680],{"class":117},[104,989,683],{"class":276},[104,991,686],{"class":121},[104,993,689],{"class":128},[104,995,692],{"class":121},[104,997,998],{"class":276},".json\"",[104,1000,1001],{"class":128},")          ",[104,1003,1004],{"class":110},"# readers never see half an entry\n",[104,1006,1008],{"class":106,"line":1007},58,[104,1009,136],{"emptyLinePlaceholder":135},[104,1011,1013,1015,1018,1021,1024],{"class":106,"line":1012},59,[104,1014,346],{"class":117},[104,1016,1017],{"class":337}," clear",[104,1019,1020],{"class":128},"(self) -> ",[104,1022,1023],{"class":121},"int",[104,1025,261],{"class":128},[104,1027,1029,1032,1034],{"class":106,"line":1028},60,[104,1030,1031],{"class":128},"        removed ",[104,1033,391],{"class":117},[104,1035,1036],{"class":121}," 0\n",[104,1038,1040,1043,1046,1049,1051,1054,1057],{"class":106,"line":1039},61,[104,1041,1042],{"class":117},"        for",[104,1044,1045],{"class":128}," p ",[104,1047,1048],{"class":117},"in",[104,1050,651],{"class":121},[104,1052,1053],{"class":128},".dir.glob(",[104,1055,1056],{"class":276},"\"*.json\"",[104,1058,746],{"class":128},[104,1060,1062,1065,1068,1070,1072],{"class":106,"line":1061},62,[104,1063,1064],{"class":128},"            p.unlink(",[104,1066,1067],{"class":427},"missing_ok",[104,1069,391],{"class":117},[104,1071,578],{"class":121},[104,1073,280],{"class":128},[104,1075,1077,1080,1083],{"class":106,"line":1076},63,[104,1078,1079],{"class":128},"            removed ",[104,1081,1082],{"class":117},"+=",[104,1084,1085],{"class":121}," 1\n",[104,1087,1089,1091],{"class":106,"line":1088},64,[104,1090,595],{"class":117},[104,1092,1093],{"class":128}," removed\n",[104,1095,1097],{"class":106,"line":1096},65,[104,1098,136],{"emptyLinePlaceholder":135},[104,1100,1102],{"class":106,"line":1101},66,[104,1103,136],{"emptyLinePlaceholder":135},[104,1105,1107,1110,1113,1116,1118,1120,1122,1124,1126],{"class":106,"line":1106},67,[104,1108,1109],{"class":117},"def",[104,1111,1112],{"class":337}," files_fingerprint",[104,1114,1115],{"class":128},"(paths: list[Path]) -> list[tuple[",[104,1117,513],{"class":121},[104,1119,424],{"class":128},[104,1121,1023],{"class":121},[104,1123,424],{"class":128},[104,1125,1023],{"class":121},[104,1127,1128],{"class":128},"]]:\n",[104,1130,1132],{"class":106,"line":1131},68,[104,1133,1134],{"class":276},"    \"\"\"Cheap change detection: path, size and mtime in nanoseconds for each file.\"\"\"\n",[104,1136,1138,1141,1143],{"class":106,"line":1137},69,[104,1139,1140],{"class":128},"    fp ",[104,1142,391],{"class":117},[104,1144,1145],{"class":128}," []\n",[104,1147,1149,1152,1154,1156,1159],{"class":106,"line":1148},70,[104,1150,1151],{"class":117},"    for",[104,1153,1045],{"class":128},[104,1155,1048],{"class":117},[104,1157,1158],{"class":121}," sorted",[104,1160,1161],{"class":128},"(paths):\n",[104,1163,1165,1168,1170],{"class":106,"line":1164},71,[104,1166,1167],{"class":128},"        st ",[104,1169,391],{"class":117},[104,1171,1172],{"class":128}," p.stat()\n",[104,1174,1176,1179,1181],{"class":106,"line":1175},72,[104,1177,1178],{"class":128},"        fp.append((",[104,1180,513],{"class":121},[104,1182,1183],{"class":128},"(p), st.st_size, st.st_mtime_ns))\n",[104,1185,1187,1190],{"class":106,"line":1186},73,[104,1188,1189],{"class":117},"    return",[104,1191,1192],{"class":128}," fp\n",[10,1194,1195],{},"Using it in a command that indexes a documentation tree:",[95,1197,1199],{"className":97,"code":1198,"language":99,"meta":100,"style":100},"# src\u002Fmytool\u002Fcli.py\nfrom pathlib import Path\nfrom typing import Annotated\n\nimport typer\n\nfrom mytool.cache import DiskCache, files_fingerprint\n\napp = typer.Typer()\n\n\ndef build_index(files: list[Path]) -> dict[str, list[str]]:\n    \"\"\"The slow part: parse every file and collect headings.\"\"\"\n    index: dict[str, list[str]] = {}\n    for f in files:\n        index[str(f)] = [line.lstrip(\"# \").strip() for line in f.read_text(encoding=\"utf-8\").splitlines()\n                         if line.startswith(\"#\")]\n    return index\n\n\n@app.callback()\ndef main() -> None:\n    \"\"\"Docs tools.\"\"\"\n\n\n@app.command()\ndef headings(\n    root: Annotated[Path, typer.Argument(exists=True, file_okay=False)] = Path(\"docs\"),\n    no_cache: Annotated[bool, typer.Option(\"--no-cache\", help=\"Ignore and do not update the cache.\")] = False,\n) -> None:\n    \"\"\"Print every heading in the docs tree.\"\"\"\n    cache = DiskCache(enabled=not no_cache)\n    files = sorted(root.rglob(\"*.md\"))\n    key = DiskCache.key(\"headings\", root=str(root.resolve()), files=files_fingerprint(files))\n    index = cache.get(key)\n    if index is None:\n        index = build_index(files)\n        cache.set(key, index)\n    for path, hs in index.items():\n        for h in hs:\n            typer.echo(f\"{path}: {h}\")\n\n\n@app.command(\"clear-cache\")\ndef clear_cache() -> None:\n    \"\"\"Delete cached results.\"\"\"\n    typer.echo(f\"removed {DiskCache().clear()} cached entries\", err=True)\n\n\nif __name__ == \"__main__\":\n    app()\n",[32,1200,1201,1206,1216,1227,1231,1238,1242,1254,1258,1268,1272,1276,1295,1300,1319,1331,1372,1386,1393,1397,1401,1409,1423,1428,1432,1436,1443,1453,1488,1520,1529,1534,1553,1570,1603,1613,1627,1637,1642,1654,1666,1696,1700,1704,1716,1729,1734,1765,1769,1773,1789],{"__ignoreMap":100},[104,1202,1203],{"class":106,"line":107},[104,1204,1205],{"class":110},"# src\u002Fmytool\u002Fcli.py\n",[104,1207,1208,1210,1212,1214],{"class":106,"line":114},[104,1209,118],{"class":117},[104,1211,211],{"class":128},[104,1213,142],{"class":117},[104,1215,216],{"class":128},[104,1217,1218,1220,1222,1224],{"class":106,"line":132},[104,1219,118],{"class":117},[104,1221,224],{"class":128},[104,1223,142],{"class":117},[104,1225,1226],{"class":128}," Annotated\n",[104,1228,1229],{"class":106,"line":139},[104,1230,136],{"emptyLinePlaceholder":135},[104,1232,1233,1235],{"class":106,"line":148},[104,1234,142],{"class":117},[104,1236,1237],{"class":128}," typer\n",[104,1239,1240],{"class":106,"line":156},[104,1241,136],{"emptyLinePlaceholder":135},[104,1243,1244,1246,1249,1251],{"class":106,"line":164},[104,1245,118],{"class":117},[104,1247,1248],{"class":128}," mytool.cache ",[104,1250,142],{"class":117},[104,1252,1253],{"class":128}," DiskCache, files_fingerprint\n",[104,1255,1256],{"class":106,"line":172},[104,1257,136],{"emptyLinePlaceholder":135},[104,1259,1260,1263,1265],{"class":106,"line":180},[104,1261,1262],{"class":128},"app ",[104,1264,391],{"class":117},[104,1266,1267],{"class":128}," typer.Typer()\n",[104,1269,1270],{"class":106,"line":193},[104,1271,136],{"emptyLinePlaceholder":135},[104,1273,1274],{"class":106,"line":206},[104,1275,136],{"emptyLinePlaceholder":135},[104,1277,1278,1280,1283,1286,1288,1291,1293],{"class":106,"line":219},[104,1279,1109],{"class":117},[104,1281,1282],{"class":337}," build_index",[104,1284,1285],{"class":128},"(files: list[Path]) -> dict[",[104,1287,513],{"class":121},[104,1289,1290],{"class":128},", list[",[104,1292,513],{"class":121},[104,1294,1128],{"class":128},[104,1296,1297],{"class":106,"line":232},[104,1298,1299],{"class":276},"    \"\"\"The slow part: parse every file and collect headings.\"\"\"\n",[104,1301,1302,1305,1307,1309,1311,1314,1316],{"class":106,"line":237},[104,1303,1304],{"class":128},"    index: dict[",[104,1306,513],{"class":121},[104,1308,1290],{"class":128},[104,1310,513],{"class":121},[104,1312,1313],{"class":128},"]] ",[104,1315,391],{"class":117},[104,1317,1318],{"class":128}," {}\n",[104,1320,1321,1323,1326,1328],{"class":106,"line":250},[104,1322,1151],{"class":117},[104,1324,1325],{"class":128}," f ",[104,1327,1048],{"class":117},[104,1329,1330],{"class":128}," files:\n",[104,1332,1333,1336,1338,1341,1343,1346,1349,1352,1355,1358,1360,1363,1365,1367,1369],{"class":106,"line":255},[104,1334,1335],{"class":128},"        index[",[104,1337,513],{"class":121},[104,1339,1340],{"class":128},"(f)] ",[104,1342,391],{"class":117},[104,1344,1345],{"class":128}," [line.lstrip(",[104,1347,1348],{"class":276},"\"# \"",[104,1350,1351],{"class":128},").strip() ",[104,1353,1354],{"class":117},"for",[104,1356,1357],{"class":128}," line ",[104,1359,1048],{"class":117},[104,1361,1362],{"class":128}," f.read_text(",[104,1364,717],{"class":427},[104,1366,391],{"class":117},[104,1368,722],{"class":276},[104,1370,1371],{"class":128},").splitlines()\n",[104,1373,1374,1377,1380,1383],{"class":106,"line":264},[104,1375,1376],{"class":117},"                         if",[104,1378,1379],{"class":128}," line.startswith(",[104,1381,1382],{"class":276},"\"#\"",[104,1384,1385],{"class":128},")]\n",[104,1387,1388,1390],{"class":106,"line":283},[104,1389,1189],{"class":117},[104,1391,1392],{"class":128}," index\n",[104,1394,1395],{"class":106,"line":292},[104,1396,136],{"emptyLinePlaceholder":135},[104,1398,1399],{"class":106,"line":302},[104,1400,136],{"emptyLinePlaceholder":135},[104,1402,1403,1406],{"class":106,"line":307},[104,1404,1405],{"class":337},"@app.callback",[104,1407,1408],{"class":128},"()\n",[104,1410,1411,1413,1416,1419,1421],{"class":106,"line":321},[104,1412,1109],{"class":117},[104,1414,1415],{"class":337}," main",[104,1417,1418],{"class":128},"() -> ",[104,1420,397],{"class":121},[104,1422,261],{"class":128},[104,1424,1425],{"class":106,"line":326},[104,1426,1427],{"class":276},"    \"\"\"Docs tools.\"\"\"\n",[104,1429,1430],{"class":106,"line":331},[104,1431,136],{"emptyLinePlaceholder":135},[104,1433,1434],{"class":106,"line":343},[104,1435,136],{"emptyLinePlaceholder":135},[104,1437,1438,1441],{"class":106,"line":379},[104,1439,1440],{"class":337},"@app.command",[104,1442,1408],{"class":128},[104,1444,1445,1447,1450],{"class":106,"line":402},[104,1446,1109],{"class":117},[104,1448,1449],{"class":337}," headings",[104,1451,1452],{"class":128},"(\n",[104,1454,1455,1458,1461,1463,1465,1467,1470,1472,1474,1477,1479,1482,1485],{"class":106,"line":445},[104,1456,1457],{"class":128},"    root: Annotated[Path, typer.Argument(",[104,1459,1460],{"class":427},"exists",[104,1462,391],{"class":117},[104,1464,578],{"class":121},[104,1466,424],{"class":128},[104,1468,1469],{"class":427},"file_okay",[104,1471,391],{"class":117},[104,1473,433],{"class":121},[104,1475,1476],{"class":128},")] ",[104,1478,391],{"class":117},[104,1480,1481],{"class":128}," Path(",[104,1483,1484],{"class":276},"\"docs\"",[104,1486,1487],{"class":128},"),\n",[104,1489,1490,1493,1495,1498,1501,1503,1506,1508,1511,1513,1515,1518],{"class":106,"line":475},[104,1491,1492],{"class":128},"    no_cache: Annotated[",[104,1494,368],{"class":121},[104,1496,1497],{"class":128},", typer.Option(",[104,1499,1500],{"class":276},"\"--no-cache\"",[104,1502,424],{"class":128},[104,1504,1505],{"class":427},"help",[104,1507,391],{"class":117},[104,1509,1510],{"class":276},"\"Ignore and do not update the cache.\"",[104,1512,1476],{"class":128},[104,1514,391],{"class":117},[104,1516,1517],{"class":121}," False",[104,1519,376],{"class":128},[104,1521,1522,1525,1527],{"class":106,"line":488},[104,1523,1524],{"class":128},") -> ",[104,1526,397],{"class":121},[104,1528,261],{"class":128},[104,1530,1531],{"class":106,"line":493},[104,1532,1533],{"class":276},"    \"\"\"Print every heading in the docs tree.\"\"\"\n",[104,1535,1536,1539,1541,1544,1547,1550],{"class":106,"line":502},[104,1537,1538],{"class":128},"    cache ",[104,1540,391],{"class":117},[104,1542,1543],{"class":128}," DiskCache(",[104,1545,1546],{"class":427},"enabled",[104,1548,1549],{"class":117},"=not",[104,1551,1552],{"class":128}," no_cache)\n",[104,1554,1555,1558,1560,1562,1565,1568],{"class":106,"line":528},[104,1556,1557],{"class":128},"    files ",[104,1559,391],{"class":117},[104,1561,1158],{"class":121},[104,1563,1564],{"class":128},"(root.rglob(",[104,1566,1567],{"class":276},"\"*.md\"",[104,1569,725],{"class":128},[104,1571,1572,1575,1577,1580,1583,1585,1588,1590,1592,1595,1598,1600],{"class":106,"line":570},[104,1573,1574],{"class":128},"    key ",[104,1576,391],{"class":117},[104,1578,1579],{"class":128}," DiskCache.key(",[104,1581,1582],{"class":276},"\"headings\"",[104,1584,424],{"class":128},[104,1586,1587],{"class":427},"root",[104,1589,391],{"class":117},[104,1591,513],{"class":121},[104,1593,1594],{"class":128},"(root.resolve()), ",[104,1596,1597],{"class":427},"files",[104,1599,391],{"class":117},[104,1601,1602],{"class":128},"files_fingerprint(files))\n",[104,1604,1605,1608,1610],{"class":106,"line":592},[104,1606,1607],{"class":128},"    index ",[104,1609,391],{"class":117},[104,1611,1612],{"class":128}," cache.get(key)\n",[104,1614,1615,1618,1621,1623,1625],{"class":106,"line":601},[104,1616,1617],{"class":117},"    if",[104,1619,1620],{"class":128}," index ",[104,1622,767],{"class":117},[104,1624,358],{"class":121},[104,1626,261],{"class":128},[104,1628,1629,1632,1634],{"class":106,"line":606},[104,1630,1631],{"class":128},"        index ",[104,1633,391],{"class":117},[104,1635,1636],{"class":128}," build_index(files)\n",[104,1638,1639],{"class":106,"line":642},[104,1640,1641],{"class":128},"        cache.set(key, index)\n",[104,1643,1644,1646,1649,1651],{"class":106,"line":657},[104,1645,1151],{"class":117},[104,1647,1648],{"class":128}," path, hs ",[104,1650,1048],{"class":117},[104,1652,1653],{"class":128}," index.items():\n",[104,1655,1656,1658,1661,1663],{"class":106,"line":666},[104,1657,1042],{"class":117},[104,1659,1660],{"class":128}," h ",[104,1662,1048],{"class":117},[104,1664,1665],{"class":128}," hs:\n",[104,1667,1668,1671,1674,1676,1678,1681,1683,1685,1687,1690,1692,1694],{"class":106,"line":698},[104,1669,1670],{"class":128},"            typer.echo(",[104,1672,1673],{"class":117},"f",[104,1675,683],{"class":276},[104,1677,686],{"class":121},[104,1679,1680],{"class":128},"path",[104,1682,692],{"class":121},[104,1684,548],{"class":276},[104,1686,686],{"class":121},[104,1688,1689],{"class":128},"h",[104,1691,692],{"class":121},[104,1693,683],{"class":276},[104,1695,280],{"class":128},[104,1697,1698],{"class":106,"line":706},[104,1699,136],{"emptyLinePlaceholder":135},[104,1701,1702],{"class":106,"line":728},[104,1703,136],{"emptyLinePlaceholder":135},[104,1705,1706,1708,1711,1714],{"class":106,"line":749},[104,1707,1440],{"class":337},[104,1709,1710],{"class":128},"(",[104,1712,1713],{"class":276},"\"clear-cache\"",[104,1715,280],{"class":128},[104,1717,1718,1720,1723,1725,1727],{"class":106,"line":759},[104,1719,1109],{"class":117},[104,1721,1722],{"class":337}," clear_cache",[104,1724,1418],{"class":128},[104,1726,397],{"class":121},[104,1728,261],{"class":128},[104,1730,1731],{"class":106,"line":799},[104,1732,1733],{"class":276},"    \"\"\"Delete cached results.\"\"\"\n",[104,1735,1736,1739,1741,1744,1746,1749,1751,1754,1756,1759,1761,1763],{"class":106,"line":806},[104,1737,1738],{"class":128},"    typer.echo(",[104,1740,1673],{"class":117},[104,1742,1743],{"class":276},"\"removed ",[104,1745,686],{"class":121},[104,1747,1748],{"class":128},"DiskCache().clear()",[104,1750,692],{"class":121},[104,1752,1753],{"class":276}," cached entries\"",[104,1755,424],{"class":128},[104,1757,1758],{"class":427},"err",[104,1760,391],{"class":117},[104,1762,578],{"class":121},[104,1764,280],{"class":128},[104,1766,1767],{"class":106,"line":819},[104,1768,136],{"emptyLinePlaceholder":135},[104,1770,1771],{"class":106,"line":824},[104,1772,136],{"emptyLinePlaceholder":135},[104,1774,1775,1778,1781,1784,1787],{"class":106,"line":843},[104,1776,1777],{"class":117},"if",[104,1779,1780],{"class":121}," __name__",[104,1782,1783],{"class":117}," ==",[104,1785,1786],{"class":276}," \"__main__\"",[104,1788,261],{"class":128},[104,1790,1791],{"class":106,"line":854},[104,1792,1793],{"class":128},"    app()\n",[1795,1796,1798],"h3",{"id":1797},"the-decisions-that-make-it-safe","The decisions that make it safe",[10,1800,1801,1804,1805,1808,1809,1811],{},[61,1802,1803],{},"The key includes the tool version and a format number."," Upgrading ",[32,1806,1807],{},"mytool"," changes the key, so results computed by old code are never returned by new code. ",[32,1810,310],{}," covers changes to the entry layout itself.",[10,1813,1814,1817],{},[61,1815,1816],{},"File fingerprints use size and nanosecond mtime."," Hashing every file's contents would be exact but may cost as much as the work being cached; size plus modification time detects virtually all real edits cheaply. For inputs where that is not good enough — files that are rewritten with identical timestamps by some tools — hash the contents instead.",[10,1819,1820,1823],{},[61,1821,1822],{},"Corrupt or missing entries are misses."," A truncated file, a JSON error or a Unicode error means \"recompute\", never a crash. The cache must never be the reason a command fails.",[10,1825,1826,1829,1830,1834],{},[61,1827,1828],{},"Writes are atomic."," The entry is written to a temporary file and renamed into place, the pattern from ",[14,1831,1833],{"href":1832},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fwriting-files-atomically-in-python-clis\u002F","writing files atomically in Python CLIs",", so two concurrent runs cannot read half an entry.",[10,1836,1837,1840],{},[61,1838,1839],{},"JSON, not pickle."," JSON cannot execute code when loaded and survives Python upgrades. Pickle is faster for complex objects but turns a writable cache directory into a code-execution risk and breaks across versions.",[10,1842,1843,1846,1847,1850,1851,548,1854,1857],{},[61,1844,1845],{},"Remote data gets a TTL."," For results you cannot fingerprint — an API listing — pass ",[32,1848,1849],{},"max_age"," to ",[32,1852,1853],{},"get",[32,1855,1856],{},"cache.get(key, max_age=600)"," accepts entries up to ten minutes old. Choose the TTL by how stale an answer users can tolerate.",[20,1859,1861],{"id":1860},"ux-considerations","UX considerations",[25,1863,1864,1873,1879,1889,1899],{},[28,1865,1866,1872],{},[61,1867,1868,1869],{},"Always offer ",[32,1870,1871],{},"--no-cache"," (and an environment variable for scripts). When a user suspects a stale result, bypassing the cache must be one flag away.",[28,1874,1875,1878],{},[61,1876,1877],{},"Offer a way to clear it",", and mention in help that the cache is safe to delete. Keep it in the platform cache directory so system tools and users recognise it as disposable.",[28,1880,1881,1884,1885,1888],{},[61,1882,1883],{},"Keep it invisible when it works."," Do not announce cache hits in normal output; print them only with ",[32,1886,1887],{},"-v",", where they help explain timing.",[28,1890,1891,1894,1895,1898],{},[61,1892,1893],{},"Refresh remote data explicitly."," A ",[32,1896,1897],{},"--refresh"," flag that ignores the TTL and rewrites the entry is friendlier than making users clear the whole cache.",[28,1900,1901,1904],{},[61,1902,1903],{},"Mind shell completion."," Completion callbacks benefit most from caching, because they run on every Tab press, but they must stay fast even on a miss — fall back to no suggestions rather than blocking on a slow computation.",[20,1906,1908],{"id":1907},"testing-the-behaviour","Testing the behaviour",[10,1910,1911],{},"The properties to test are hits, invalidation by input change, invalidation by version, TTL expiry and resilience to corruption. An injectable clock and a temporary cache directory make each one deterministic:",[95,1913,1915],{"className":97,"code":1914,"language":99,"meta":100,"style":100},"# tests\u002Ftest_cache.py\nfrom pathlib import Path\n\nfrom mytool import cache as cache_mod\nfrom mytool.cache import DiskCache, files_fingerprint\n\n\ndef test_hit_and_miss(tmp_path):\n    c = DiskCache(tmp_path)\n    k = DiskCache.key(\"t\", x=1)\n    assert c.get(k) is None\n    c.set(k, {\"answer\": 42})\n    assert c.get(k) == {\"answer\": 42}\n\n\ndef test_file_change_changes_the_key(tmp_path):\n    f = tmp_path \u002F \"a.md\"\n    f.write_text(\"# One\\n\")\n    k1 = DiskCache.key(\"idx\", files=files_fingerprint([f]))\n    f.write_text(\"# One\\n# Two\\n\")\n    k2 = DiskCache.key(\"idx\", files=files_fingerprint([f]))\n    assert k1 != k2\n\n\ndef test_tool_version_is_part_of_the_key(monkeypatch):\n    k1 = DiskCache.key(\"t\", x=1)\n    monkeypatch.setattr(cache_mod, \"TOOL_VERSION\", \"99.0\")\n    assert DiskCache.key(\"t\", x=1) != k1\n\n\ndef test_ttl_expiry(tmp_path):\n    now = [1000.0]\n    c = DiskCache(tmp_path, clock=lambda: now[0])\n    c.set(\"k\", \"v\")\n    now[0] += 599\n    assert c.get(\"k\", max_age=600) == \"v\"\n    now[0] += 2\n    assert c.get(\"k\", max_age=600) is None\n\n\ndef test_corrupt_entry_is_a_miss(tmp_path):\n    c = DiskCache(tmp_path)\n    (tmp_path \u002F \"k.json\").write_text(\"{not json\")\n    assert c.get(\"k\") is None\n\n\ndef test_disabled_by_env(tmp_path, monkeypatch):\n    monkeypatch.setenv(\"MYTOOL_NO_CACHE\", \"1\")\n    c = DiskCache(tmp_path)\n    c.set(\"k\", \"v\")\n    assert c.get(\"k\") is None and not list(Path(tmp_path).glob(\"*.json\"))\n",[32,1916,1917,1922,1932,1936,1953,1963,1967,1971,1981,1991,2015,2027,2043,2064,2068,2072,2081,2096,2111,2132,2149,2168,2180,2184,2188,2198,2218,2233,2256,2260,2264,2273,2288,2312,2326,2340,2365,2378,2400,2404,2408,2417,2425,2443,2457,2461,2465,2475,2489,2497,2509],{"__ignoreMap":100},[104,1918,1919],{"class":106,"line":107},[104,1920,1921],{"class":110},"# tests\u002Ftest_cache.py\n",[104,1923,1924,1926,1928,1930],{"class":106,"line":114},[104,1925,118],{"class":117},[104,1927,211],{"class":128},[104,1929,142],{"class":117},[104,1931,216],{"class":128},[104,1933,1934],{"class":106,"line":132},[104,1935,136],{"emptyLinePlaceholder":135},[104,1937,1938,1940,1943,1945,1948,1950],{"class":106,"line":139},[104,1939,118],{"class":117},[104,1941,1942],{"class":128}," mytool ",[104,1944,142],{"class":117},[104,1946,1947],{"class":128}," cache ",[104,1949,964],{"class":117},[104,1951,1952],{"class":128}," cache_mod\n",[104,1954,1955,1957,1959,1961],{"class":106,"line":148},[104,1956,118],{"class":117},[104,1958,1248],{"class":128},[104,1960,142],{"class":117},[104,1962,1253],{"class":128},[104,1964,1965],{"class":106,"line":156},[104,1966,136],{"emptyLinePlaceholder":135},[104,1968,1969],{"class":106,"line":164},[104,1970,136],{"emptyLinePlaceholder":135},[104,1972,1973,1975,1978],{"class":106,"line":172},[104,1974,1109],{"class":117},[104,1976,1977],{"class":337}," test_hit_and_miss",[104,1979,1980],{"class":128},"(tmp_path):\n",[104,1982,1983,1986,1988],{"class":106,"line":180},[104,1984,1985],{"class":128},"    c ",[104,1987,391],{"class":117},[104,1989,1990],{"class":128}," DiskCache(tmp_path)\n",[104,1992,1993,1996,1998,2000,2003,2005,2008,2010,2013],{"class":106,"line":193},[104,1994,1995],{"class":128},"    k ",[104,1997,391],{"class":117},[104,1999,1579],{"class":128},[104,2001,2002],{"class":276},"\"t\"",[104,2004,424],{"class":128},[104,2006,2007],{"class":427},"x",[104,2009,391],{"class":117},[104,2011,2012],{"class":121},"1",[104,2014,280],{"class":128},[104,2016,2017,2020,2023,2025],{"class":106,"line":206},[104,2018,2019],{"class":117},"    assert",[104,2021,2022],{"class":128}," c.get(k) ",[104,2024,767],{"class":117},[104,2026,663],{"class":121},[104,2028,2029,2032,2035,2037,2040],{"class":106,"line":219},[104,2030,2031],{"class":128},"    c.set(k, {",[104,2033,2034],{"class":276},"\"answer\"",[104,2036,548],{"class":128},[104,2038,2039],{"class":121},"42",[104,2041,2042],{"class":128},"})\n",[104,2044,2045,2047,2049,2052,2055,2057,2059,2061],{"class":106,"line":232},[104,2046,2019],{"class":117},[104,2048,2022],{"class":128},[104,2050,2051],{"class":117},"==",[104,2053,2054],{"class":128}," {",[104,2056,2034],{"class":276},[104,2058,548],{"class":128},[104,2060,2039],{"class":121},[104,2062,2063],{"class":128},"}\n",[104,2065,2066],{"class":106,"line":237},[104,2067,136],{"emptyLinePlaceholder":135},[104,2069,2070],{"class":106,"line":250},[104,2071,136],{"emptyLinePlaceholder":135},[104,2073,2074,2076,2079],{"class":106,"line":255},[104,2075,1109],{"class":117},[104,2077,2078],{"class":337}," test_file_change_changes_the_key",[104,2080,1980],{"class":128},[104,2082,2083,2086,2088,2091,2093],{"class":106,"line":264},[104,2084,2085],{"class":128},"    f ",[104,2087,391],{"class":117},[104,2089,2090],{"class":128}," tmp_path ",[104,2092,439],{"class":117},[104,2094,2095],{"class":276}," \"a.md\"\n",[104,2097,2098,2101,2104,2107,2109],{"class":106,"line":283},[104,2099,2100],{"class":128},"    f.write_text(",[104,2102,2103],{"class":276},"\"# One",[104,2105,2106],{"class":121},"\\n",[104,2108,683],{"class":276},[104,2110,280],{"class":128},[104,2112,2113,2116,2118,2120,2123,2125,2127,2129],{"class":106,"line":292},[104,2114,2115],{"class":128},"    k1 ",[104,2117,391],{"class":117},[104,2119,1579],{"class":128},[104,2121,2122],{"class":276},"\"idx\"",[104,2124,424],{"class":128},[104,2126,1597],{"class":427},[104,2128,391],{"class":117},[104,2130,2131],{"class":128},"files_fingerprint([f]))\n",[104,2133,2134,2136,2138,2140,2143,2145,2147],{"class":106,"line":302},[104,2135,2100],{"class":128},[104,2137,2103],{"class":276},[104,2139,2106],{"class":121},[104,2141,2142],{"class":276},"# Two",[104,2144,2106],{"class":121},[104,2146,683],{"class":276},[104,2148,280],{"class":128},[104,2150,2151,2154,2156,2158,2160,2162,2164,2166],{"class":106,"line":307},[104,2152,2153],{"class":128},"    k2 ",[104,2155,391],{"class":117},[104,2157,1579],{"class":128},[104,2159,2122],{"class":276},[104,2161,424],{"class":128},[104,2163,1597],{"class":427},[104,2165,391],{"class":117},[104,2167,2131],{"class":128},[104,2169,2170,2172,2175,2177],{"class":106,"line":321},[104,2171,2019],{"class":117},[104,2173,2174],{"class":128}," k1 ",[104,2176,469],{"class":117},[104,2178,2179],{"class":128}," k2\n",[104,2181,2182],{"class":106,"line":326},[104,2183,136],{"emptyLinePlaceholder":135},[104,2185,2186],{"class":106,"line":331},[104,2187,136],{"emptyLinePlaceholder":135},[104,2189,2190,2192,2195],{"class":106,"line":343},[104,2191,1109],{"class":117},[104,2193,2194],{"class":337}," test_tool_version_is_part_of_the_key",[104,2196,2197],{"class":128},"(monkeypatch):\n",[104,2199,2200,2202,2204,2206,2208,2210,2212,2214,2216],{"class":106,"line":379},[104,2201,2115],{"class":128},[104,2203,391],{"class":117},[104,2205,1579],{"class":128},[104,2207,2002],{"class":276},[104,2209,424],{"class":128},[104,2211,2007],{"class":427},[104,2213,391],{"class":117},[104,2215,2012],{"class":121},[104,2217,280],{"class":128},[104,2219,2220,2223,2226,2228,2231],{"class":106,"line":402},[104,2221,2222],{"class":128},"    monkeypatch.setattr(cache_mod, ",[104,2224,2225],{"class":276},"\"TOOL_VERSION\"",[104,2227,424],{"class":128},[104,2229,2230],{"class":276},"\"99.0\"",[104,2232,280],{"class":128},[104,2234,2235,2237,2239,2241,2243,2245,2247,2249,2251,2253],{"class":106,"line":445},[104,2236,2019],{"class":117},[104,2238,1579],{"class":128},[104,2240,2002],{"class":276},[104,2242,424],{"class":128},[104,2244,2007],{"class":427},[104,2246,391],{"class":117},[104,2248,2012],{"class":121},[104,2250,436],{"class":128},[104,2252,469],{"class":117},[104,2254,2255],{"class":128}," k1\n",[104,2257,2258],{"class":106,"line":475},[104,2259,136],{"emptyLinePlaceholder":135},[104,2261,2262],{"class":106,"line":488},[104,2263,136],{"emptyLinePlaceholder":135},[104,2265,2266,2268,2271],{"class":106,"line":493},[104,2267,1109],{"class":117},[104,2269,2270],{"class":337}," test_ttl_expiry",[104,2272,1980],{"class":128},[104,2274,2275,2278,2280,2283,2286],{"class":106,"line":502},[104,2276,2277],{"class":128},"    now ",[104,2279,391],{"class":117},[104,2281,2282],{"class":128}," [",[104,2284,2285],{"class":121},"1000.0",[104,2287,816],{"class":128},[104,2289,2290,2292,2294,2297,2300,2303,2306,2309],{"class":106,"line":528},[104,2291,1985],{"class":128},[104,2293,391],{"class":117},[104,2295,2296],{"class":128}," DiskCache(tmp_path, ",[104,2298,2299],{"class":427},"clock",[104,2301,2302],{"class":117},"=lambda",[104,2304,2305],{"class":128},": now[",[104,2307,2308],{"class":121},"0",[104,2310,2311],{"class":128},"])\n",[104,2313,2314,2317,2320,2322,2324],{"class":106,"line":570},[104,2315,2316],{"class":128},"    c.set(",[104,2318,2319],{"class":276},"\"k\"",[104,2321,424],{"class":128},[104,2323,545],{"class":276},[104,2325,280],{"class":128},[104,2327,2328,2331,2333,2335,2337],{"class":106,"line":592},[104,2329,2330],{"class":128},"    now[",[104,2332,2308],{"class":121},[104,2334,388],{"class":128},[104,2336,1082],{"class":117},[104,2338,2339],{"class":121}," 599\n",[104,2341,2342,2344,2347,2349,2351,2353,2355,2358,2360,2362],{"class":106,"line":601},[104,2343,2019],{"class":117},[104,2345,2346],{"class":128}," c.get(",[104,2348,2319],{"class":276},[104,2350,424],{"class":128},[104,2352,1849],{"class":427},[104,2354,391],{"class":117},[104,2356,2357],{"class":121},"600",[104,2359,436],{"class":128},[104,2361,2051],{"class":117},[104,2363,2364],{"class":276}," \"v\"\n",[104,2366,2367,2369,2371,2373,2375],{"class":106,"line":606},[104,2368,2330],{"class":128},[104,2370,2308],{"class":121},[104,2372,388],{"class":128},[104,2374,1082],{"class":117},[104,2376,2377],{"class":121}," 2\n",[104,2379,2380,2382,2384,2386,2388,2390,2392,2394,2396,2398],{"class":106,"line":642},[104,2381,2019],{"class":117},[104,2383,2346],{"class":128},[104,2385,2319],{"class":276},[104,2387,424],{"class":128},[104,2389,1849],{"class":427},[104,2391,391],{"class":117},[104,2393,2357],{"class":121},[104,2395,436],{"class":128},[104,2397,767],{"class":117},[104,2399,663],{"class":121},[104,2401,2402],{"class":106,"line":657},[104,2403,136],{"emptyLinePlaceholder":135},[104,2405,2406],{"class":106,"line":666},[104,2407,136],{"emptyLinePlaceholder":135},[104,2409,2410,2412,2415],{"class":106,"line":698},[104,2411,1109],{"class":117},[104,2413,2414],{"class":337}," test_corrupt_entry_is_a_miss",[104,2416,1980],{"class":128},[104,2418,2419,2421,2423],{"class":106,"line":706},[104,2420,1985],{"class":128},[104,2422,391],{"class":117},[104,2424,1990],{"class":128},[104,2426,2427,2430,2432,2435,2438,2441],{"class":106,"line":728},[104,2428,2429],{"class":128},"    (tmp_path ",[104,2431,439],{"class":117},[104,2433,2434],{"class":276}," \"k.json\"",[104,2436,2437],{"class":128},").write_text(",[104,2439,2440],{"class":276},"\"{not json\"",[104,2442,280],{"class":128},[104,2444,2445,2447,2449,2451,2453,2455],{"class":106,"line":749},[104,2446,2019],{"class":117},[104,2448,2346],{"class":128},[104,2450,2319],{"class":276},[104,2452,436],{"class":128},[104,2454,767],{"class":117},[104,2456,663],{"class":121},[104,2458,2459],{"class":106,"line":759},[104,2460,136],{"emptyLinePlaceholder":135},[104,2462,2463],{"class":106,"line":799},[104,2464,136],{"emptyLinePlaceholder":135},[104,2466,2467,2469,2472],{"class":106,"line":806},[104,2468,1109],{"class":117},[104,2470,2471],{"class":337}," test_disabled_by_env",[104,2473,2474],{"class":128},"(tmp_path, monkeypatch):\n",[104,2476,2477,2480,2482,2484,2487],{"class":106,"line":819},[104,2478,2479],{"class":128},"    monkeypatch.setenv(",[104,2481,464],{"class":276},[104,2483,424],{"class":128},[104,2485,2486],{"class":276},"\"1\"",[104,2488,280],{"class":128},[104,2490,2491,2493,2495],{"class":106,"line":824},[104,2492,1985],{"class":128},[104,2494,391],{"class":117},[104,2496,1990],{"class":128},[104,2498,2499,2501,2503,2505,2507],{"class":106,"line":843},[104,2500,2316],{"class":128},[104,2502,2319],{"class":276},[104,2504,424],{"class":128},[104,2506,545],{"class":276},[104,2508,280],{"class":128},[104,2510,2511,2513,2515,2517,2519,2521,2523,2525,2527,2530,2533,2535],{"class":106,"line":854},[104,2512,2019],{"class":117},[104,2514,2346],{"class":128},[104,2516,2319],{"class":276},[104,2518,436],{"class":128},[104,2520,767],{"class":117},[104,2522,358],{"class":121},[104,2524,774],{"class":117},[104,2526,648],{"class":117},[104,2528,2529],{"class":121}," list",[104,2531,2532],{"class":128},"(Path(tmp_path).glob(",[104,2534,1056],{"class":276},[104,2536,725],{"class":128},[10,2538,2539,2540,2543],{},"A command-level test can additionally patch ",[32,2541,2542],{},"build_index"," with a counter and assert it runs once across two invocations with unchanged files, and twice after a file changes — the behaviour users actually experience.",[20,2545,2547],{"id":2546},"conclusion","Conclusion",[10,2549,2550,2551,2553],{},"An on-disk cache can make a repeated CLI command feel instant, provided it can be trusted. Put everything that affects the result into the key — input fingerprints, the tool version, a format number — bound remote data with a TTL, treat corruption as a miss, write atomically, store JSON rather than pickle, keep entries in the platform cache directory, and give users ",[32,2552,1871],{}," and a way to clear it. Test hits, every form of invalidation and corruption with an injected clock, and the cache becomes a pure speed-up with no new ways to be wrong.",[20,2555,2557],{"id":2556},"frequently-asked-questions","Frequently asked questions",[1795,2559,2561,2562,2565,2566,2569],{"id":2560},"should-i-use-diskcache-or-joblibmemory-instead","Should I use ",[32,2563,2564],{},"diskcache"," or ",[32,2567,2568],{},"joblib.Memory"," instead?",[10,2571,2572,2573,2575,2576,2578],{},"They are solid libraries: ",[32,2574,2564],{}," offers a fast SQLite-backed cache with eviction; ",[32,2577,2568],{}," memoises functions on disk, popular in data work. Either is reasonable when caching is central to the tool. For a few cached computations, the small class above avoids a dependency and keeps the key rules explicit.",[1795,2580,2582],{"id":2581},"how-big-should-the-cache-be-allowed-to-grow","How big should the cache be allowed to grow?",[10,2584,2585,2586,2589],{},"Set a limit that matches the data — prune entries older than N days, or the oldest beyond a total size — on write, or in the ",[32,2587,2588],{},"clear-cache"," command. Caches in the platform cache directory may also be cleared by the system, which is another reason entries must be disposable.",[1795,2591,2593],{"id":2592},"can-the-cache-be-shared-between-users-or-machines","Can the cache be shared between users or machines?",[10,2595,2596],{},"Not safely in this form: fingerprints include absolute paths and modification times, and a shared writable cache is a trust problem. Shared caches need content hashes as keys and a trusted storage service.",[1795,2598,2600],{"id":2599},"what-about-caching-in-memory-within-one-run","What about caching in memory within one run?",[10,2602,2603,2606,2607,2611],{},[32,2604,2605],{},"functools.cache"," on pure functions is the right tool for repeated work inside a single invocation. The on-disk cache is for work repeated ",[2608,2609,2610],"em",{},"across"," invocations; they combine well.",[20,2613,2615],{"id":2614},"related","Related",[25,2617,2618,2624,2628,2634,2639],{},[28,2619,2620,2621],{},"Up: ",[14,2622,2623],{"href":16},"CLI startup performance and lazy loading",[28,2625,2626],{},[14,2627,47],{"href":46},[28,2629,2630],{},[14,2631,2633],{"href":2632},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup\u002F","Lazy-loading subcommands for faster startup",[28,2635,2636],{},[14,2637,2638],{"href":38},"Storing app data with platformdirs",[28,2640,2641],{},[14,2642,2644],{"href":2643},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Fdynamic-completion-values-from-apis-and-files\u002F","Dynamic completion values from APIs and files",[2646,2647,2648],"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 .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}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":100,"searchDepth":114,"depth":114,"links":2650},[2651,2652,2653,2654,2657,2658,2659,2660,2667],{"id":22,"depth":114,"text":23},{"id":51,"depth":114,"text":52},{"id":75,"depth":114,"text":76},{"id":92,"depth":114,"text":93,"children":2655},[2656],{"id":1797,"depth":132,"text":1798},{"id":1860,"depth":114,"text":1861},{"id":1907,"depth":114,"text":1908},{"id":2546,"depth":114,"text":2547},{"id":2556,"depth":114,"text":2557,"children":2661},[2662,2664,2665,2666],{"id":2560,"depth":132,"text":2663},"Should I use diskcache or joblib.Memory instead?",{"id":2581,"depth":132,"text":2582},{"id":2592,"depth":132,"text":2593},{"id":2599,"depth":132,"text":2600},{"id":2614,"depth":114,"text":2615},"2026-09-18","Make repeated CLI runs fast with an on-disk cache: content-hash keys, tool version in the key, TTLs for remote data, atomic writes, --no-cache and tests.","intermediate",false,"md",{},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fcaching-expensive-work-between-cli-runs",{"title":5,"description":2669},"modern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fcaching-expensive-work-between-cli-runs\u002Findex",[2678,2679,2680,2681],"performance","caching","startup","filesystem","NdpucfxwdbbnfsbXr4IOQLkQhD7HbknOs5JRem1zbOs",[2684,2687,2690,2693,2696,2699,2702,2705,2708,2711,2714,2717,2720,2723,2726,2729,2732,2735,2738,2741,2744,2747,2750,2753,2756,2759,2762,2765,2768,2771,2774,2777,2780,2783,2786,2789,2792,2795,2798,2801,2804,2807,2810,2813,2816,2819,2822,2825,2828,2831,2834,2837,2840,2843,2846,2849,2852,2855,2858,2861,2864,2867,2870,2873,2876,2879,2882,2885,2888,2891,2894,2897,2900,2903,2906,2909,2912,2915,2918,2921,2924,2927,2930,2933,2936,2939,2942,2945,2948,2951,2954,2957,2959,2960,2963,2966,2969,2972,2975,2978,2981,2984,2987,2990,2993,2996,2999,3002,3005,3008,3011,3014,3017,3020,3023,3026,3029,3032,3035,3038,3041,3044,3047,3050,3053,3056,3059,3062,3065,3068,3071,3074,3077,3080,3083,3086,3089,3092,3095,3098,3101,3104,3107,3110,3113,3116,3119,3122,3125,3128,3131,3134,3137,3140,3143,3146,3149,3152,3155,3158,3161,3164,3167,3170,3173,3176,3179,3182,3185,3188,3191,3194,3197,3200,3203,3206,3209,3212,3215,3218,3221,3224,3227],{"path":2685,"title":2686},"\u002Fabout","About Python CLI Toolcraft",{"path":2688,"title":2689},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies","Advanced Argument Validation Strategies",{"path":2691,"title":2692},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fparsing-nested-json-arguments-in-python-clis","Parsing Nested JSON Args in Python CLIs",{"path":2694,"title":2695},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-dependent-and-conflicting-options","Validating Dependent and Conflicting CLI Options",{"path":2697,"title":2698},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-file-and-directory-paths-in-clis","Validating File and Directory Paths in CLIs",{"path":2700,"title":2701},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fwriting-custom-click-parameter-types","Writing Custom Click Parameter Types",{"path":2703,"title":2704},"\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":2706,"title":2707},"\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":2709,"title":2710},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual","Building Terminal UIs with Textual for Python CLIs",{"path":2712,"title":2713},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Ftesting-textual-apps-with-pilot","Testing Textual Apps with Pilot",{"path":2715,"title":2716},"\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":2718,"title":2719},"\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":2721,"title":2722},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation","CLI Help Output and Documentation",{"path":2724,"title":2725},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fversioning-and-deprecating-cli-flags","Versioning and Deprecating CLI Flags",{"path":2727,"title":2728},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fwriting-help-text-users-actually-read","Writing Help Text Users Actually Read",{"path":2730,"title":2731},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fadapting-output-to-terminal-width","Adapting Python CLI Output to Terminal Width",{"path":2733,"title":2734},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fdetecting-ci-environments-and-non-interactive-shells","Detecting CI Environments and Non-Interactive Shells",{"path":2736,"title":2737},"\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":2739,"title":2740},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility","Cross-Platform Terminal Compatibility for Python CLIs",{"path":2742,"title":2743},"\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":2745,"title":2746},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fchoosing-exit-codes-for-cli-tools","Choosing Exit Codes for CLI Tools",{"path":2748,"title":2749},"\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":2751,"title":2752},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Ffriendly-error-messages-and-tracebacks","Friendly Error Messages and Tracebacks",{"path":2754,"title":2755},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fhandling-keyboard-interrupt-cleanly","Handling Keyboard Interrupt Cleanly",{"path":2757,"title":2758},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes","Error Handling and Exit Codes for CLIs",{"path":2760,"title":2761},"\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":2763,"title":2764},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fconfig-precedence-flags-env-files-defaults","Config Precedence: Flags, Env, Files, Defaults",{"path":2766,"title":2767},"\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":2769,"title":2770},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars","Handling Config Files and Env Vars in CLIs",{"path":2772,"title":2773},"\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":2775,"title":2776},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Freading-toml-config-with-tomllib","Reading TOML Config with tomllib in Python CLIs",{"path":2778,"title":2779},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Ftyped-settings-with-pydantic-settings","Typed Settings with pydantic-settings in Python CLIs",{"path":2781,"title":2782},"\u002Fadvanced-input-parsing-user-experience","Advanced Input Parsing for Python CLIs",{"path":2784,"title":2785},"\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":2787,"title":2788},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Fbuilding-interactive-prompts-and-menus","Building Interactive Prompts and Menus in Python CLIs",{"path":2790,"title":2791},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich","Interactive Terminal UI with Rich",{"path":2793,"title":2794},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Flive-dashboards-with-rich-live","Live Dashboards with Rich Live in Python CLIs",{"path":2796,"title":2797},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Frendering-tables-and-json-with-rich","Rendering Tables and JSON with Rich",{"path":2799,"title":2800},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Ftheming-rich-output-consistently","Theming Rich Output Consistently in Python CLIs",{"path":2802,"title":2803},"\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":2805,"title":2806},"\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":2808,"title":2809},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis","Shell Completion for Python CLIs",{"path":2811,"title":2812},"\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":2814,"title":2815},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Ftesting-shell-completion-in-python-clis","Testing Shell Completion in Python CLIs",{"path":2817,"title":2818},"\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":2820,"title":2821},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-verbose-and-quiet-logging-flags","Adding Verbose and Quiet Logging Flags",{"path":2823,"title":2824},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps","Structured Logging for CLI Apps",{"path":2826,"title":2827},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fstructured-json-logging-in-python-clis","Structured JSON Logging in Python CLIs",{"path":2829,"title":2830},"\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":2832,"title":2833},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fdetecting-tty-and-adapting-output","Detecting a TTY and Adapting Output",{"path":2835,"title":2836},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Femitting-json-output-for-scripting","Emitting JSON Output for Scripting",{"path":2838,"title":2839},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fhandling-broken-pipe-and-sigpipe","Handling Broken Pipe and SIGPIPE",{"path":2841,"title":2842},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes","Working with stdin, stdout and Pipes",{"path":2844,"title":2845},"\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":2847,"title":2848},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Freading-piped-input-in-python-clis","Reading Piped Input in Python CLIs",{"path":2850,"title":2851},"\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":2853,"title":2854},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fdownloading-files-with-progress-in-python","Downloading Files with Progress in Python CLIs",{"path":2856,"title":2857},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis","Calling HTTP APIs from Python CLIs",{"path":2859,"title":2860},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Foauth-device-flow-login-for-clis","OAuth Device Flow Login for Python CLIs",{"path":2862,"title":2863},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fpaginating-api-results-in-a-cli","Paginating API Results in a Python CLI",{"path":2865,"title":2866},"\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":2868,"title":2869},"\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":2871,"title":2872},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis","Concurrency and Async in Python CLIs",{"path":2874,"title":2875},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fmultiprocessing-for-cpu-bound-cli-tasks","Multiprocessing for CPU-Bound CLI Tasks",{"path":2877,"title":2878},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fparallelising-cli-work-with-thread-pools","Parallelising CLI Work with Thread Pools",{"path":2880,"title":2881},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Frate-limiting-concurrent-requests-in-clis","Rate-Limiting Concurrent Requests in Python CLIs",{"path":2883,"title":2884},"\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":2886,"title":2887},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fcross-platform-paths-with-pathlib","Cross-Platform Paths with pathlib in CLIs",{"path":2889,"title":2890},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Ffile-locking-for-concurrent-cli-runs","File Locking for Concurrent CLI Runs in Python",{"path":2892,"title":2893},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes","Filesystem Paths and Atomic Writes for CLIs",{"path":2895,"title":2896},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fsafe-temporary-files-and-directories","Safe Temporary Files and Directories in CLIs",{"path":2898,"title":2899},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fstoring-app-data-with-platformdirs","Storing CLI App Data with platformdirs",{"path":2901,"title":2902},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fwriting-files-atomically-in-python-clis","Writing Files Atomically in Python CLIs",{"path":2904,"title":2905},"\u002Fcli-runtime-systems-integration","CLI Runtime & Systems Integration for Python",{"path":2907,"title":2908},"\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":2910,"title":2911},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fhandling-sigterm-and-graceful-shutdown","Handling SIGTERM and Graceful Shutdown in CLIs",{"path":2913,"title":2914},"\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":2916,"title":2917},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis","Long-Running and Watch-Mode Python CLIs",{"path":2919,"title":2920},"\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":2922,"title":2923},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Favoiding-shell-injection-in-python-clis","Avoiding Shell Injection in Python CLIs",{"path":2925,"title":2926},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fcalling-external-commands-safely-with-subprocess","Calling External Commands Safely with subprocess",{"path":2928,"title":2929},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fhandling-subprocess-timeouts-and-exit-codes","Handling Subprocess Timeouts and Exit Codes",{"path":2931,"title":2932},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis","Running Subprocesses from Python CLIs",{"path":2934,"title":2935},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fstreaming-subprocess-output-in-real-time","Streaming Subprocess Output in Real Time",{"path":2937,"title":2938},"\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":2940,"title":2941},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis","Secrets and Credentials in Python CLIs",{"path":2943,"title":2944},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fprompting-for-passwords-securely","Prompting for Passwords Securely in Python CLIs",{"path":2946,"title":2947},"\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":2949,"title":2950},"\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":2952,"title":2953},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fstoring-tokens-with-keyring","Storing CLI Tokens Securely with keyring",{"path":2955,"title":2956},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fsupporting-multiple-profiles-and-accounts","Supporting Multiple Profiles and Accounts in CLIs",{"path":439,"title":2958},"Python CLI Toolcraft",{"path":2674,"title":5},{"path":2961,"title":2962},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading","CLI Startup Performance and Lazy Loading",{"path":2964,"title":2965},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup","Lazy Loading Subcommands for Faster Startup",{"path":2967,"title":2968},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fprofiling-python-cli-startup-time","Profiling Python CLI Startup Time",{"path":2970,"title":2971},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Freducing-cli-dependency-weight","Reducing CLI Dependency Weight",{"path":2973,"title":2974},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-subparsers-for-subcommands","argparse Subparsers for Subcommands",{"path":2976,"title":2977},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-vs-click-vs-typer-comparison","argparse vs Click vs Typer Compared",{"path":2979,"title":2980},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse","Command-Line Parsing with argparse",{"path":2982,"title":2983},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmigrating-from-argparse-to-typer","Migrating from argparse to Typer",{"path":2985,"title":2986},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmutually-exclusive-options-in-argparse","Mutually Exclusive Options in argparse",{"path":2988,"title":2989},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fwriting-custom-argparse-actions","Writing Custom argparse Actions in Python",{"path":2991,"title":2992},"\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":2994,"title":2995},"\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":2997,"title":2998},"\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":3000,"title":3001},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions","Designing CLI Interfaces and Conventions in Python",{"path":3003,"title":3004},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fnaming-commands-and-flags-consistently","Naming Commands and Flags Consistently in Python CLIs",{"path":3006,"title":3007},"\u002Fmodern-python-cli-frameworks-architecture","Python CLI Frameworks and Architecture",{"path":3009,"title":3010},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fdiscovering-plugins-with-entry-points","Discovering Plugins with Entry Points in Python CLIs",{"path":3012,"title":3013},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fhook-based-plugins-with-pluggy","Hook-Based Plugins for Python CLIs with pluggy",{"path":3015,"title":3016},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis","Plugin Architectures for Extensible CLIs",{"path":3018,"title":3019},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fversioning-a-plugin-api","Versioning a Plugin API for a Python CLI",{"path":3021,"title":3022},"\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":3024,"title":3025},"\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":3027,"title":3028},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fdependency-injection-patterns-for-cli-commands","Dependency Injection Patterns for CLI Commands",{"path":3030,"title":3031},"\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":3033,"title":3034},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis","Structuring Multi-Command Python CLIs",{"path":3036,"title":3037},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-common-options-across-commands","Sharing Common Options Across Python CLI Commands",{"path":3039,"title":3040},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-state-with-click-context-objects","Sharing State with Click Context Objects",{"path":3042,"title":3043},"\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":3045,"title":3046},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications","Testing Python CLI Applications",{"path":3048,"title":3049},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fmeasuring-cli-test-coverage","Measuring CLI Test Coverage",{"path":3051,"title":3052},"\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":3054,"title":3055},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fproperty-based-testing-cli-arguments-with-hypothesis","Property-Based Testing CLI Arguments with Hypothesis",{"path":3057,"title":3058},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fsnapshot-testing-cli-output","Snapshot Testing CLI Output",{"path":3060,"title":3061},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-click-commands-with-clirunner","Testing Click Commands with CliRunner",{"path":3063,"title":3064},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-interactive-prompts-and-stdin","Testing Interactive Prompts and stdin",{"path":3066,"title":3067},"\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":3069,"title":3070},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fbuilding-dynamic-commands-in-click","Building Dynamic Commands in Click",{"path":3072,"title":3073},"\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":3075,"title":3076},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each","Typer vs Click: When to Use Each",{"path":3078,"title":3079},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Ftyper-callback-functions-explained","Typer callback functions explained",{"path":3081,"title":3082},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fusing-annotated-options-in-typer","Using Annotated Options in Typer",{"path":3084,"title":3085},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fautomating-releases-from-git-tags","Automating Python CLI Releases from Git Tags",{"path":3087,"title":3088},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fcaching-uv-dependencies-in-ci","Caching uv Dependencies in CI for Python CLIs",{"path":3090,"title":3091},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis","CI\u002FCD Pipelines for Python CLIs",{"path":3093,"title":3094},"\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":3096,"title":3097},"\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":3099,"title":3100},"\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":3102,"title":3103},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fbuilding-a-cookiecutter-template-for-typer-clis","Building a Cookiecutter Template for Typer CLIs",{"path":3105,"title":3106},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fcopier-vs-cookiecutter-for-cli-templates","Copier vs Cookiecutter for CLI Templates",{"path":3108,"title":3109},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter","CLI Project Scaffolding with Cookiecutter",{"path":3111,"title":3112},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fpost-generation-hooks-in-cli-templates","Post-Generation Hooks in Python CLI Templates",{"path":3114,"title":3115},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbuilding-cross-platform-release-binaries-in-ci","Building Cross-Platform Release Binaries in CI",{"path":3117,"title":3118},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbundling-a-python-cli-with-pyinstaller","Bundling a Python CLI with PyInstaller",{"path":3120,"title":3121},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fhomebrew-and-scoop-packaging-for-python-clis","Homebrew and Scoop Packaging for Python CLIs",{"path":3123,"title":3124},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries","Distributing CLIs as Standalone Binaries",{"path":3126,"title":3127},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fnuitka-vs-pyinstaller-for-python-clis","Nuitka vs PyInstaller for Python CLI Binaries",{"path":3129,"title":3130},"\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":3132,"title":3133},"\u002Fproject-setup-dependency-management","Project Setup & Dependency Management",{"path":3135,"title":3136},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Fconfiguring-ruff-for-a-cli-project","Configuring Ruff for a Python CLI Project",{"path":3138,"title":3139},"\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":3141,"title":3142},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code","Linting and Type-Checking Python CLI Code",{"path":3144,"title":3145},"\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":3147,"title":3148},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fautomating-changelogs-with-conventional-commits","Automating Changelogs with Conventional Commits",{"path":3150,"title":3151},"\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":3153,"title":3154},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fexposing-version-info-and-build-metadata","Exposing Version Info and Build Metadata",{"path":3156,"title":3157},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs","Managing CLI Versioning & Changelogs",{"path":3159,"title":3160},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fsemantic-versioning-policy-for-cli-tools","A Semantic Versioning Policy for CLI Tools",{"path":3162,"title":3163},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbuilding-wheels-and-sdists-for-python-clis","Building Wheels and sdists for Python CLIs",{"path":3165,"title":3166},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbundling-data-files-with-importlib-resources","Bundling Data Files with importlib.resources in CLIs",{"path":3168,"title":3169},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution","Packaging Python CLIs for Distribution",{"path":3171,"title":3172},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Finstalling-and-distributing-clis-with-pipx","Installing and Distributing CLIs with pipx",{"path":3174,"title":3175},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fpublishing-a-python-cli-to-pypi","Publishing a Python CLI to PyPI",{"path":3177,"title":3178},"\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":3180,"title":3181},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development","Poetry Workflows for CLI Development",{"path":3183,"title":3184},"\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":3186,"title":3187},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-dependency-groups-for-cli-tooling","Poetry Dependency Groups for CLI Tooling",{"path":3189,"title":3190},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-entry-points-and-scripts-for-clis","Poetry Entry Points and Scripts for CLIs",{"path":3192,"title":3193},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects","Pre-commit Hooks for CLI Projects",{"path":3195,"title":3196},"\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":3198,"title":3199},"\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":3201,"title":3202},"\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":3204,"title":3205},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management","uv for Python CLI Dependency Management",{"path":3207,"title":3208},"\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":3210,"title":3211},"\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":3213,"title":3214},"\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":3216,"title":3217},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fuv-workspaces-for-multi-package-clis","uv Workspaces for Multi-Package Python CLIs",{"path":3219,"title":3220},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices","Python CLI Env Isolation Best Practices",{"path":3222,"title":3223},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fmanaging-virtual-environments-for-cross-platform-clis","Managing Python CLI Virtual Environments",{"path":3225,"title":3226},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fpinning-the-python-version-for-a-cli","Pinning the Python Version for a CLI",{"path":3228,"title":3229},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fsupporting-multiple-python-versions-with-nox","Supporting Multiple Python Versions with nox",1789736905051]