[{"data":1,"prerenderedAt":2652},["ShallowReactive",2],{"page-\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fstoring-app-data-with-platformdirs\u002F":3,"content-directory":2105},{"id":4,"title":5,"body":6,"date":2091,"description":2092,"difficulty":2093,"draft":2094,"extension":2095,"meta":2096,"navigation":160,"path":2097,"seo":2098,"stem":2099,"tags":2100,"updated":2091,"__hash__":2104},"content\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fstoring-app-data-with-platformdirs\u002Findex.md","Storing CLI App Data with platformdirs",{"type":7,"value":8,"toc":2072},"minimark",[9,32,37,57,61,67,71,102,109,112,116,119,662,665,726,729,1369,1381,1385,1388,1439,1443,1450,1923,1933,1937,1951,1955,1964,1967,1974,1989,1993,2004,2008,2015,2023,2034,2038,2068],[10,11,12,13,17,18,21,22,25,26,31],"p",{},"Every CLI that survives a few releases accumulates files of its own: a config file the user edits, a cache of downloaded metadata, a record of the last run, a log for debugging. Where those files go is one of the first things users notice. Drop a ",[14,15,16],"code",{},".mytool"," directory into the home directory root and Linux users sigh; write a cache into the working directory and it ends up committed to someone's repository; hard-code ",[14,19,20],{},"~\u002F.config"," and Windows users get a folder their system does not recognise. This guide uses the ",[14,23,24],{},"platformdirs"," package to put each kind of file in the directory each operating system designates for it, adds environment and flag overrides, and gives users a command to find and clean it all. It belongs to the ",[27,28,30],"a",{"href":29},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002F","filesystem topic",".",[33,34,36],"h2",{"id":35},"prerequisites","Prerequisites",[38,39,40,51,54],"ul",{},[41,42,43,44,46,47,50],"li",{},"Python 3.10+ and ",[14,45,24],{}," 4.x (",[14,48,49],{},"uv add platformdirs",").",[41,52,53],{},"A Typer or Click CLI.",[41,55,56],{},"A clear idea of which files your tool owns. If you are unsure, the decision section below will help.",[33,58,60],{"id":59},"four-kinds-of-file-four-directories","Four kinds of file, four directories",[10,62,63,64,66],{},"Operating systems distinguish between files by what losing them would cost. The XDG base-directory specification on Linux, Apple's guidelines on macOS and Microsoft's known-folders on Windows all draw roughly the same lines, and ",[14,65,24],{}," maps a single API onto each:",[68,69],"inline-diagram",{"name":70},"fs-platform-dirs-matrix",[38,72,73,80,86,96],{},[41,74,75,79],{},[76,77,78],"strong",{},"Config"," — settings the user chooses and may edit by hand. Users back this up and sync it between machines.",[41,81,82,85],{},[76,83,84],{},"Cache"," — anything your tool can rebuild: downloaded indexes, compiled templates, API responses. Deleting it must be harmless, and system cleanup tools may do exactly that.",[41,87,88,91,92,95],{},[76,89,90],{},"State"," — data the tool itself maintains that is not worth backing up but is annoying to lose: command history, \"last checked for updates\" timestamps, a record of which migrations ran. (On macOS and Windows this lands next to the data directory; on Linux it is the separate ",[14,93,94],{},"~\u002F.local\u002Fstate",".)",[41,97,98,101],{},[76,99,100],{},"Logs"," — diagnostic output kept between runs.",[10,103,104,105,108],{},"There is also a ",[76,106,107],{},"data"," directory, for files the user would lose work without but does not edit directly — a local database or downloaded plugins. Many CLIs never need it.",[68,110],{"name":111},"fs-dir-choice",[33,113,115],{"id":114},"the-recipe","The recipe",[10,117,118],{},"Put the directory logic in one module. Everything else in the CLI imports paths from it and never computes a location itself.",[120,121,126],"pre",{"className":122,"code":123,"language":124,"meta":125,"style":125},"language-python shiki shiki-themes github-light github-dark","# src\u002Fmytool\u002Fpaths.py\nfrom __future__ import annotations\n\nimport os\nfrom dataclasses import dataclass\nfrom pathlib import Path\n\nfrom platformdirs import PlatformDirs\n\nAPP = \"mytool\"\n\n\n@dataclass(frozen=True)\nclass AppPaths:\n    config_dir: Path\n    cache_dir: Path\n    state_dir: Path\n    log_dir: Path\n\n    @property\n    def config_file(self) -> Path:\n        return self.config_dir \u002F \"config.toml\"\n\n    def ensure(self) -> None:\n        for d in (self.config_dir, self.cache_dir, self.state_dir, self.log_dir):\n            d.mkdir(parents=True, exist_ok=True)\n\n\ndef _override(var: str) -> Path | None:\n    value = os.environ.get(var)\n    return Path(value).expanduser() if value else None\n\n\ndef resolve_paths(config_dir: Path | None = None) -> AppPaths:\n    \"\"\"Directories for this run: flag > MYTOOL_* env var > platform default.\"\"\"\n    dirs = PlatformDirs(APP, appauthor=False)\n    return AppPaths(\n        config_dir=config_dir or _override(\"MYTOOL_CONFIG_DIR\") or dirs.user_config_path,\n        cache_dir=_override(\"MYTOOL_CACHE_DIR\") or dirs.user_cache_path,\n        state_dir=_override(\"MYTOOL_STATE_DIR\") or dirs.user_state_path,\n        log_dir=_override(\"MYTOOL_LOG_DIR\") or dirs.user_log_path,\n    )\n","python","",[14,127,128,137,155,162,171,184,197,202,215,220,233,238,243,266,278,284,290,296,302,307,316,328,346,351,367,403,428,433,438,464,475,496,501,506,528,534,559,567,595,616,636,656],{"__ignoreMap":125},[129,130,133],"span",{"class":131,"line":132},"line",1,[129,134,136],{"class":135},"sJ8bj","# src\u002Fmytool\u002Fpaths.py\n",[129,138,140,144,148,151],{"class":131,"line":139},2,[129,141,143],{"class":142},"szBVR","from",[129,145,147],{"class":146},"sj4cs"," __future__",[129,149,150],{"class":142}," import",[129,152,154],{"class":153},"sVt8B"," annotations\n",[129,156,158],{"class":131,"line":157},3,[129,159,161],{"emptyLinePlaceholder":160},true,"\n",[129,163,165,168],{"class":131,"line":164},4,[129,166,167],{"class":142},"import",[129,169,170],{"class":153}," os\n",[129,172,174,176,179,181],{"class":131,"line":173},5,[129,175,143],{"class":142},[129,177,178],{"class":153}," dataclasses ",[129,180,167],{"class":142},[129,182,183],{"class":153}," dataclass\n",[129,185,187,189,192,194],{"class":131,"line":186},6,[129,188,143],{"class":142},[129,190,191],{"class":153}," pathlib ",[129,193,167],{"class":142},[129,195,196],{"class":153}," Path\n",[129,198,200],{"class":131,"line":199},7,[129,201,161],{"emptyLinePlaceholder":160},[129,203,205,207,210,212],{"class":131,"line":204},8,[129,206,143],{"class":142},[129,208,209],{"class":153}," platformdirs ",[129,211,167],{"class":142},[129,213,214],{"class":153}," PlatformDirs\n",[129,216,218],{"class":131,"line":217},9,[129,219,161],{"emptyLinePlaceholder":160},[129,221,223,226,229],{"class":131,"line":222},10,[129,224,225],{"class":146},"APP",[129,227,228],{"class":142}," =",[129,230,232],{"class":231},"sZZnC"," \"mytool\"\n",[129,234,236],{"class":131,"line":235},11,[129,237,161],{"emptyLinePlaceholder":160},[129,239,241],{"class":131,"line":240},12,[129,242,161],{"emptyLinePlaceholder":160},[129,244,246,250,253,257,260,263],{"class":131,"line":245},13,[129,247,249],{"class":248},"sScJk","@dataclass",[129,251,252],{"class":153},"(",[129,254,256],{"class":255},"s4XuR","frozen",[129,258,259],{"class":142},"=",[129,261,262],{"class":146},"True",[129,264,265],{"class":153},")\n",[129,267,269,272,275],{"class":131,"line":268},14,[129,270,271],{"class":142},"class",[129,273,274],{"class":248}," AppPaths",[129,276,277],{"class":153},":\n",[129,279,281],{"class":131,"line":280},15,[129,282,283],{"class":153},"    config_dir: Path\n",[129,285,287],{"class":131,"line":286},16,[129,288,289],{"class":153},"    cache_dir: Path\n",[129,291,293],{"class":131,"line":292},17,[129,294,295],{"class":153},"    state_dir: Path\n",[129,297,299],{"class":131,"line":298},18,[129,300,301],{"class":153},"    log_dir: Path\n",[129,303,305],{"class":131,"line":304},19,[129,306,161],{"emptyLinePlaceholder":160},[129,308,310,313],{"class":131,"line":309},20,[129,311,312],{"class":248},"    @",[129,314,315],{"class":146},"property\n",[129,317,319,322,325],{"class":131,"line":318},21,[129,320,321],{"class":142},"    def",[129,323,324],{"class":248}," config_file",[129,326,327],{"class":153},"(self) -> Path:\n",[129,329,331,334,337,340,343],{"class":131,"line":330},22,[129,332,333],{"class":142},"        return",[129,335,336],{"class":146}," self",[129,338,339],{"class":153},".config_dir ",[129,341,342],{"class":142},"\u002F",[129,344,345],{"class":231}," \"config.toml\"\n",[129,347,349],{"class":131,"line":348},23,[129,350,161],{"emptyLinePlaceholder":160},[129,352,354,356,359,362,365],{"class":131,"line":353},24,[129,355,321],{"class":142},[129,357,358],{"class":248}," ensure",[129,360,361],{"class":153},"(self) -> ",[129,363,364],{"class":146},"None",[129,366,277],{"class":153},[129,368,370,373,376,379,382,385,388,390,393,395,398,400],{"class":131,"line":369},25,[129,371,372],{"class":142},"        for",[129,374,375],{"class":153}," d ",[129,377,378],{"class":142},"in",[129,380,381],{"class":153}," (",[129,383,384],{"class":146},"self",[129,386,387],{"class":153},".config_dir, ",[129,389,384],{"class":146},[129,391,392],{"class":153},".cache_dir, ",[129,394,384],{"class":146},[129,396,397],{"class":153},".state_dir, ",[129,399,384],{"class":146},[129,401,402],{"class":153},".log_dir):\n",[129,404,406,409,412,414,416,419,422,424,426],{"class":131,"line":405},26,[129,407,408],{"class":153},"            d.mkdir(",[129,410,411],{"class":255},"parents",[129,413,259],{"class":142},[129,415,262],{"class":146},[129,417,418],{"class":153},", ",[129,420,421],{"class":255},"exist_ok",[129,423,259],{"class":142},[129,425,262],{"class":146},[129,427,265],{"class":153},[129,429,431],{"class":131,"line":430},27,[129,432,161],{"emptyLinePlaceholder":160},[129,434,436],{"class":131,"line":435},28,[129,437,161],{"emptyLinePlaceholder":160},[129,439,441,444,447,450,453,456,459,462],{"class":131,"line":440},29,[129,442,443],{"class":142},"def",[129,445,446],{"class":248}," _override",[129,448,449],{"class":153},"(var: ",[129,451,452],{"class":146},"str",[129,454,455],{"class":153},") -> Path ",[129,457,458],{"class":142},"|",[129,460,461],{"class":146}," None",[129,463,277],{"class":153},[129,465,467,470,472],{"class":131,"line":466},30,[129,468,469],{"class":153},"    value ",[129,471,259],{"class":142},[129,473,474],{"class":153}," os.environ.get(var)\n",[129,476,478,481,484,487,490,493],{"class":131,"line":477},31,[129,479,480],{"class":142},"    return",[129,482,483],{"class":153}," Path(value).expanduser() ",[129,485,486],{"class":142},"if",[129,488,489],{"class":153}," value ",[129,491,492],{"class":142},"else",[129,494,495],{"class":146}," None\n",[129,497,499],{"class":131,"line":498},32,[129,500,161],{"emptyLinePlaceholder":160},[129,502,504],{"class":131,"line":503},33,[129,505,161],{"emptyLinePlaceholder":160},[129,507,509,511,514,517,519,521,523,525],{"class":131,"line":508},34,[129,510,443],{"class":142},[129,512,513],{"class":248}," resolve_paths",[129,515,516],{"class":153},"(config_dir: Path ",[129,518,458],{"class":142},[129,520,461],{"class":146},[129,522,228],{"class":142},[129,524,461],{"class":146},[129,526,527],{"class":153},") -> AppPaths:\n",[129,529,531],{"class":131,"line":530},35,[129,532,533],{"class":231},"    \"\"\"Directories for this run: flag > MYTOOL_* env var > platform default.\"\"\"\n",[129,535,537,540,542,545,547,549,552,554,557],{"class":131,"line":536},36,[129,538,539],{"class":153},"    dirs ",[129,541,259],{"class":142},[129,543,544],{"class":153}," PlatformDirs(",[129,546,225],{"class":146},[129,548,418],{"class":153},[129,550,551],{"class":255},"appauthor",[129,553,259],{"class":142},[129,555,556],{"class":146},"False",[129,558,265],{"class":153},[129,560,562,564],{"class":131,"line":561},37,[129,563,480],{"class":142},[129,565,566],{"class":153}," AppPaths(\n",[129,568,570,573,575,578,581,584,587,590,592],{"class":131,"line":569},38,[129,571,572],{"class":255},"        config_dir",[129,574,259],{"class":142},[129,576,577],{"class":153},"config_dir ",[129,579,580],{"class":142},"or",[129,582,583],{"class":153}," _override(",[129,585,586],{"class":231},"\"MYTOOL_CONFIG_DIR\"",[129,588,589],{"class":153},") ",[129,591,580],{"class":142},[129,593,594],{"class":153}," dirs.user_config_path,\n",[129,596,598,601,603,606,609,611,613],{"class":131,"line":597},39,[129,599,600],{"class":255},"        cache_dir",[129,602,259],{"class":142},[129,604,605],{"class":153},"_override(",[129,607,608],{"class":231},"\"MYTOOL_CACHE_DIR\"",[129,610,589],{"class":153},[129,612,580],{"class":142},[129,614,615],{"class":153}," dirs.user_cache_path,\n",[129,617,619,622,624,626,629,631,633],{"class":131,"line":618},40,[129,620,621],{"class":255},"        state_dir",[129,623,259],{"class":142},[129,625,605],{"class":153},[129,627,628],{"class":231},"\"MYTOOL_STATE_DIR\"",[129,630,589],{"class":153},[129,632,580],{"class":142},[129,634,635],{"class":153}," dirs.user_state_path,\n",[129,637,639,642,644,646,649,651,653],{"class":131,"line":638},41,[129,640,641],{"class":255},"        log_dir",[129,643,259],{"class":142},[129,645,605],{"class":153},[129,647,648],{"class":231},"\"MYTOOL_LOG_DIR\"",[129,650,589],{"class":153},[129,652,580],{"class":142},[129,654,655],{"class":153}," dirs.user_log_path,\n",[129,657,659],{"class":131,"line":658},42,[129,660,661],{"class":153},"    )\n",[10,663,664],{},"A few deliberate choices:",[38,666,667,682,700],{},[41,668,669,674,675,677,678,681],{},[76,670,671,31],{},[14,672,673],{},"appauthor=False"," On Windows, ",[14,676,24],{}," otherwise nests directories under an author name (",[14,679,680],{},"%LOCALAPPDATA%\\Acme\\mytool","). For a developer tool with no company brand, a flat directory is what users expect.",[41,683,684,687,688,691,692,695,696,699],{},[76,685,686],{},"Nothing is created at import time."," ",[14,689,690],{},"ensure()"," runs only when a command is about to write. A ",[14,693,694],{},"--help"," or a read-only command should never create empty directories. (",[14,697,698],{},"PlatformDirs(..., ensure_exists=True)"," exists, but it creates directories whenever a path property is accessed, which is too eager for a CLI.)",[41,701,702,705,706,709,710,713,714,718,719,721,722,725],{},[76,703,704],{},"Overrides are layered."," A ",[14,707,708],{},"--config-dir"," flag beats a ",[14,711,712],{},"MYTOOL_CONFIG_DIR"," environment variable, which beats the platform default — the same precedence the site recommends for every setting in ",[27,715,717],{"href":716},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fconfig-precedence-flags-env-files-defaults\u002F","config precedence: flags, env, files and defaults",". On Linux, ",[14,720,24],{}," already honours ",[14,723,724],{},"XDG_CONFIG_HOME"," and friends, so your variables are an extra, tool-specific layer on top.",[10,727,728],{},"Now wire it into the CLI. The callback resolves paths once and stores them on the context so every command sees the same values:",[120,730,732],{"className":122,"code":731,"language":124,"meta":125,"style":125},"# src\u002Fmytool\u002Fcli.py\nimport shutil\nfrom pathlib import Path\n\nimport typer\n\nfrom mytool.paths import AppPaths, resolve_paths\n\napp = typer.Typer()\ncache_app = typer.Typer(help=\"Manage the local cache.\")\napp.add_typer(cache_app, name=\"cache\")\n\n\ndef _size(path: Path) -> int:\n    return sum(f.stat().st_size for f in path.rglob(\"*\") if f.is_file()) if path.exists() else 0\n\n\n@app.callback()\ndef main(\n    ctx: typer.Context,\n    config_dir: Path = typer.Option(None, \"--config-dir\", envvar=\"MYTOOL_CONFIG_DIR\",\n                                    help=\"Read and write configuration here.\"),\n) -> None:\n    \"\"\"mytool — an example of well-placed files.\"\"\"\n    ctx.obj = resolve_paths(config_dir)\n\n\n@app.command()\ndef paths(ctx: typer.Context) -> None:\n    \"\"\"Show where mytool keeps its files.\"\"\"\n    p: AppPaths = ctx.obj\n    rows = [(\"config\", p.config_dir), (\"cache\", p.cache_dir),\n            (\"state\", p.state_dir), (\"logs\", p.log_dir)]\n    for label, d in rows:\n        extra = f\"  ({_size(d) \u002F 1e6:.1f} MB)\" if label == \"cache\" and d.exists() else \"\"\n        typer.echo(f\"{label:\u003C7} {d}{extra}\")\n\n\n@cache_app.command(\"clear\")\ndef cache_clear(ctx: typer.Context) -> None:\n    \"\"\"Delete everything in the cache directory.\"\"\"\n    p: AppPaths = ctx.obj\n    if not p.cache_dir.exists():\n        typer.echo(\"cache is already empty\", err=True)\n        return\n    count = sum(1 for f in p.cache_dir.rglob(\"*\") if f.is_file())\n    shutil.rmtree(p.cache_dir)\n    typer.echo(f\"removed {count} files\", err=True)\n\n\nif __name__ == \"__main__\":\n    app()\n",[14,733,734,739,746,756,760,767,771,783,787,797,817,832,836,840,855,896,900,904,912,922,927,956,969,978,983,993,997,1001,1008,1022,1027,1037,1058,1075,1088,1144,1183,1187,1191,1203,1216,1221,1229,1241,1260,1266,1300,1306,1337,1342,1347,1363],{"__ignoreMap":125},[129,735,736],{"class":131,"line":132},[129,737,738],{"class":135},"# src\u002Fmytool\u002Fcli.py\n",[129,740,741,743],{"class":131,"line":139},[129,742,167],{"class":142},[129,744,745],{"class":153}," shutil\n",[129,747,748,750,752,754],{"class":131,"line":157},[129,749,143],{"class":142},[129,751,191],{"class":153},[129,753,167],{"class":142},[129,755,196],{"class":153},[129,757,758],{"class":131,"line":164},[129,759,161],{"emptyLinePlaceholder":160},[129,761,762,764],{"class":131,"line":173},[129,763,167],{"class":142},[129,765,766],{"class":153}," typer\n",[129,768,769],{"class":131,"line":186},[129,770,161],{"emptyLinePlaceholder":160},[129,772,773,775,778,780],{"class":131,"line":199},[129,774,143],{"class":142},[129,776,777],{"class":153}," mytool.paths ",[129,779,167],{"class":142},[129,781,782],{"class":153}," AppPaths, resolve_paths\n",[129,784,785],{"class":131,"line":204},[129,786,161],{"emptyLinePlaceholder":160},[129,788,789,792,794],{"class":131,"line":217},[129,790,791],{"class":153},"app ",[129,793,259],{"class":142},[129,795,796],{"class":153}," typer.Typer()\n",[129,798,799,802,804,807,810,812,815],{"class":131,"line":222},[129,800,801],{"class":153},"cache_app ",[129,803,259],{"class":142},[129,805,806],{"class":153}," typer.Typer(",[129,808,809],{"class":255},"help",[129,811,259],{"class":142},[129,813,814],{"class":231},"\"Manage the local cache.\"",[129,816,265],{"class":153},[129,818,819,822,825,827,830],{"class":131,"line":235},[129,820,821],{"class":153},"app.add_typer(cache_app, ",[129,823,824],{"class":255},"name",[129,826,259],{"class":142},[129,828,829],{"class":231},"\"cache\"",[129,831,265],{"class":153},[129,833,834],{"class":131,"line":240},[129,835,161],{"emptyLinePlaceholder":160},[129,837,838],{"class":131,"line":245},[129,839,161],{"emptyLinePlaceholder":160},[129,841,842,844,847,850,853],{"class":131,"line":268},[129,843,443],{"class":142},[129,845,846],{"class":248}," _size",[129,848,849],{"class":153},"(path: Path) -> ",[129,851,852],{"class":146},"int",[129,854,277],{"class":153},[129,856,857,859,862,865,868,871,873,876,879,881,883,886,888,891,893],{"class":131,"line":280},[129,858,480],{"class":142},[129,860,861],{"class":146}," sum",[129,863,864],{"class":153},"(f.stat().st_size ",[129,866,867],{"class":142},"for",[129,869,870],{"class":153}," f ",[129,872,378],{"class":142},[129,874,875],{"class":153}," path.rglob(",[129,877,878],{"class":231},"\"*\"",[129,880,589],{"class":153},[129,882,486],{"class":142},[129,884,885],{"class":153}," f.is_file()) ",[129,887,486],{"class":142},[129,889,890],{"class":153}," path.exists() ",[129,892,492],{"class":142},[129,894,895],{"class":146}," 0\n",[129,897,898],{"class":131,"line":286},[129,899,161],{"emptyLinePlaceholder":160},[129,901,902],{"class":131,"line":292},[129,903,161],{"emptyLinePlaceholder":160},[129,905,906,909],{"class":131,"line":298},[129,907,908],{"class":248},"@app.callback",[129,910,911],{"class":153},"()\n",[129,913,914,916,919],{"class":131,"line":304},[129,915,443],{"class":142},[129,917,918],{"class":248}," main",[129,920,921],{"class":153},"(\n",[129,923,924],{"class":131,"line":309},[129,925,926],{"class":153},"    ctx: typer.Context,\n",[129,928,929,932,934,937,939,941,944,946,949,951,953],{"class":131,"line":318},[129,930,931],{"class":153},"    config_dir: Path ",[129,933,259],{"class":142},[129,935,936],{"class":153}," typer.Option(",[129,938,364],{"class":146},[129,940,418],{"class":153},[129,942,943],{"class":231},"\"--config-dir\"",[129,945,418],{"class":153},[129,947,948],{"class":255},"envvar",[129,950,259],{"class":142},[129,952,586],{"class":231},[129,954,955],{"class":153},",\n",[129,957,958,961,963,966],{"class":131,"line":330},[129,959,960],{"class":255},"                                    help",[129,962,259],{"class":142},[129,964,965],{"class":231},"\"Read and write configuration here.\"",[129,967,968],{"class":153},"),\n",[129,970,971,974,976],{"class":131,"line":348},[129,972,973],{"class":153},") -> ",[129,975,364],{"class":146},[129,977,277],{"class":153},[129,979,980],{"class":131,"line":353},[129,981,982],{"class":231},"    \"\"\"mytool — an example of well-placed files.\"\"\"\n",[129,984,985,988,990],{"class":131,"line":369},[129,986,987],{"class":153},"    ctx.obj ",[129,989,259],{"class":142},[129,991,992],{"class":153}," resolve_paths(config_dir)\n",[129,994,995],{"class":131,"line":405},[129,996,161],{"emptyLinePlaceholder":160},[129,998,999],{"class":131,"line":430},[129,1000,161],{"emptyLinePlaceholder":160},[129,1002,1003,1006],{"class":131,"line":435},[129,1004,1005],{"class":248},"@app.command",[129,1007,911],{"class":153},[129,1009,1010,1012,1015,1018,1020],{"class":131,"line":440},[129,1011,443],{"class":142},[129,1013,1014],{"class":248}," paths",[129,1016,1017],{"class":153},"(ctx: typer.Context) -> ",[129,1019,364],{"class":146},[129,1021,277],{"class":153},[129,1023,1024],{"class":131,"line":466},[129,1025,1026],{"class":231},"    \"\"\"Show where mytool keeps its files.\"\"\"\n",[129,1028,1029,1032,1034],{"class":131,"line":477},[129,1030,1031],{"class":153},"    p: AppPaths ",[129,1033,259],{"class":142},[129,1035,1036],{"class":153}," ctx.obj\n",[129,1038,1039,1042,1044,1047,1050,1053,1055],{"class":131,"line":498},[129,1040,1041],{"class":153},"    rows ",[129,1043,259],{"class":142},[129,1045,1046],{"class":153}," [(",[129,1048,1049],{"class":231},"\"config\"",[129,1051,1052],{"class":153},", p.config_dir), (",[129,1054,829],{"class":231},[129,1056,1057],{"class":153},", p.cache_dir),\n",[129,1059,1060,1063,1066,1069,1072],{"class":131,"line":503},[129,1061,1062],{"class":153},"            (",[129,1064,1065],{"class":231},"\"state\"",[129,1067,1068],{"class":153},", p.state_dir), (",[129,1070,1071],{"class":231},"\"logs\"",[129,1073,1074],{"class":153},", p.log_dir)]\n",[129,1076,1077,1080,1083,1085],{"class":131,"line":508},[129,1078,1079],{"class":142},"    for",[129,1081,1082],{"class":153}," label, d ",[129,1084,378],{"class":142},[129,1086,1087],{"class":153}," rows:\n",[129,1089,1090,1093,1095,1098,1101,1104,1107,1109,1112,1115,1118,1121,1124,1127,1130,1133,1136,1139,1141],{"class":131,"line":530},[129,1091,1092],{"class":153},"        extra ",[129,1094,259],{"class":142},[129,1096,1097],{"class":142}," f",[129,1099,1100],{"class":231},"\"  (",[129,1102,1103],{"class":146},"{",[129,1105,1106],{"class":153},"_size(d) ",[129,1108,342],{"class":142},[129,1110,1111],{"class":146}," 1e6",[129,1113,1114],{"class":142},":.1f",[129,1116,1117],{"class":146},"}",[129,1119,1120],{"class":231}," MB)\"",[129,1122,1123],{"class":142}," if",[129,1125,1126],{"class":153}," label ",[129,1128,1129],{"class":142},"==",[129,1131,1132],{"class":231}," \"cache\"",[129,1134,1135],{"class":142}," and",[129,1137,1138],{"class":153}," d.exists() ",[129,1140,492],{"class":142},[129,1142,1143],{"class":231}," \"\"\n",[129,1145,1146,1149,1152,1155,1157,1160,1163,1165,1168,1171,1174,1177,1179,1181],{"class":131,"line":536},[129,1147,1148],{"class":153},"        typer.echo(",[129,1150,1151],{"class":142},"f",[129,1153,1154],{"class":231},"\"",[129,1156,1103],{"class":146},[129,1158,1159],{"class":153},"label",[129,1161,1162],{"class":142},":\u003C7",[129,1164,1117],{"class":146},[129,1166,1167],{"class":146}," {",[129,1169,1170],{"class":153},"d",[129,1172,1173],{"class":146},"}{",[129,1175,1176],{"class":153},"extra",[129,1178,1117],{"class":146},[129,1180,1154],{"class":231},[129,1182,265],{"class":153},[129,1184,1185],{"class":131,"line":561},[129,1186,161],{"emptyLinePlaceholder":160},[129,1188,1189],{"class":131,"line":569},[129,1190,161],{"emptyLinePlaceholder":160},[129,1192,1193,1196,1198,1201],{"class":131,"line":597},[129,1194,1195],{"class":248},"@cache_app.command",[129,1197,252],{"class":153},[129,1199,1200],{"class":231},"\"clear\"",[129,1202,265],{"class":153},[129,1204,1205,1207,1210,1212,1214],{"class":131,"line":618},[129,1206,443],{"class":142},[129,1208,1209],{"class":248}," cache_clear",[129,1211,1017],{"class":153},[129,1213,364],{"class":146},[129,1215,277],{"class":153},[129,1217,1218],{"class":131,"line":638},[129,1219,1220],{"class":231},"    \"\"\"Delete everything in the cache directory.\"\"\"\n",[129,1222,1223,1225,1227],{"class":131,"line":658},[129,1224,1031],{"class":153},[129,1226,259],{"class":142},[129,1228,1036],{"class":153},[129,1230,1232,1235,1238],{"class":131,"line":1231},43,[129,1233,1234],{"class":142},"    if",[129,1236,1237],{"class":142}," not",[129,1239,1240],{"class":153}," p.cache_dir.exists():\n",[129,1242,1244,1246,1249,1251,1254,1256,1258],{"class":131,"line":1243},44,[129,1245,1148],{"class":153},[129,1247,1248],{"class":231},"\"cache is already empty\"",[129,1250,418],{"class":153},[129,1252,1253],{"class":255},"err",[129,1255,259],{"class":142},[129,1257,262],{"class":146},[129,1259,265],{"class":153},[129,1261,1263],{"class":131,"line":1262},45,[129,1264,1265],{"class":142},"        return\n",[129,1267,1269,1272,1274,1276,1278,1281,1284,1286,1288,1291,1293,1295,1297],{"class":131,"line":1268},46,[129,1270,1271],{"class":153},"    count ",[129,1273,259],{"class":142},[129,1275,861],{"class":146},[129,1277,252],{"class":153},[129,1279,1280],{"class":146},"1",[129,1282,1283],{"class":142}," for",[129,1285,870],{"class":153},[129,1287,378],{"class":142},[129,1289,1290],{"class":153}," p.cache_dir.rglob(",[129,1292,878],{"class":231},[129,1294,589],{"class":153},[129,1296,486],{"class":142},[129,1298,1299],{"class":153}," f.is_file())\n",[129,1301,1303],{"class":131,"line":1302},47,[129,1304,1305],{"class":153},"    shutil.rmtree(p.cache_dir)\n",[129,1307,1309,1312,1314,1317,1319,1322,1324,1327,1329,1331,1333,1335],{"class":131,"line":1308},48,[129,1310,1311],{"class":153},"    typer.echo(",[129,1313,1151],{"class":142},[129,1315,1316],{"class":231},"\"removed ",[129,1318,1103],{"class":146},[129,1320,1321],{"class":153},"count",[129,1323,1117],{"class":146},[129,1325,1326],{"class":231}," files\"",[129,1328,418],{"class":153},[129,1330,1253],{"class":255},[129,1332,259],{"class":142},[129,1334,262],{"class":146},[129,1336,265],{"class":153},[129,1338,1340],{"class":131,"line":1339},49,[129,1341,161],{"emptyLinePlaceholder":160},[129,1343,1345],{"class":131,"line":1344},50,[129,1346,161],{"emptyLinePlaceholder":160},[129,1348,1350,1352,1355,1358,1361],{"class":131,"line":1349},51,[129,1351,486],{"class":142},[129,1353,1354],{"class":146}," __name__",[129,1356,1357],{"class":142}," ==",[129,1359,1360],{"class":231}," \"__main__\"",[129,1362,277],{"class":153},[129,1364,1366],{"class":131,"line":1365},52,[129,1367,1368],{"class":153},"    app()\n",[10,1370,1371,1372,1375,1376,1380],{},"Sharing resolved paths through ",[14,1373,1374],{},"ctx.obj"," is the standard pattern from ",[27,1377,1379],{"href":1378},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-state-with-click-context-objects\u002F","sharing state with Click context objects","; it keeps commands free of path logic and makes them trivial to test.",[33,1382,1384],{"id":1383},"ux-considerations","UX considerations",[68,1386],{"name":1387},"fs-dirs-terminal",[38,1389,1390,1400,1409,1419,1429],{},[41,1391,1392,1399],{},[76,1393,1394,1395,1398],{},"Ship a ",[14,1396,1397],{},"paths"," command."," \"Where does it keep its config?\" is the most common support question for any tool with a config file. One command answers it on every platform, and it doubles as a debugging aid when overrides are in play.",[41,1401,1402,705,1405,1408],{},[76,1403,1404],{},"Make the cache disposable, and say so.",[14,1406,1407],{},"cache clear"," command, plus a sentence in the help text that the cache can be deleted at any time, gives users confidence to reclaim space.",[41,1410,1411,1414,1415,1418],{},[76,1412,1413],{},"Never write to the working directory implicitly."," Output the user asked for (",[14,1416,1417],{},"-o report.csv",") goes where they said. Your tool's own files never go in the project they happen to be standing in.",[41,1420,1421,1424,1425,31],{},[76,1422,1423],{},"Honour a project-level config too, if it helps."," Tools like linters benefit from a config file in the repository as well as a user one. That is a separate discovery mechanism — see ",[27,1426,1428],{"href":1427},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fdiscovering-project-config-files-by-walking-up-directories\u002F","discovering project config files by walking up directories",[41,1430,1431,1434,1435,1438],{},[76,1432,1433],{},"Migrate old locations gently."," If earlier versions used ",[14,1436,1437],{},"~\u002F.mytool",", read from it when the new location is empty, print a one-line notice, and move the files once. Silently ignoring the old directory looks like data loss.",[33,1440,1442],{"id":1441},"testing-the-behaviour","Testing the behaviour",[10,1444,1445,1446,1449],{},"Tests must never touch the real home directory. Point every override at ",[14,1447,1448],{},"tmp_path"," in a fixture and use the CLI as normal:",[120,1451,1453],{"className":122,"code":1452,"language":124,"meta":125,"style":125},"# tests\u002Ftest_paths.py\nimport pytest\nfrom typer.testing import CliRunner\n\nfrom mytool.cli import app\nfrom mytool.paths import resolve_paths\n\nrunner = CliRunner()\n\n\n@pytest.fixture\ndef isolated(tmp_path, monkeypatch):\n    for kind in (\"CONFIG\", \"CACHE\", \"STATE\", \"LOG\"):\n        monkeypatch.setenv(f\"MYTOOL_{kind}_DIR\", str(tmp_path \u002F kind.lower()))\n    return tmp_path\n\n\ndef test_env_overrides(isolated):\n    p = resolve_paths()\n    assert p.config_file == isolated \u002F \"config\" \u002F \"config.toml\"\n    assert p.cache_dir == isolated \u002F \"cache\"\n\n\ndef test_flag_beats_env(isolated, tmp_path):\n    p = resolve_paths(config_dir=tmp_path \u002F \"flag\")\n    assert p.config_dir == tmp_path \u002F \"flag\"\n\n\ndef test_paths_command_creates_nothing(isolated):\n    result = runner.invoke(app, [\"paths\"])\n    assert result.exit_code == 0\n    assert \"config\" in result.output\n    assert not (isolated \u002F \"cache\").exists()\n\n\ndef test_cache_clear(isolated):\n    cache = isolated \u002F \"cache\"\n    (cache \u002F \"sub\").mkdir(parents=True)\n    (cache \u002F \"sub\" \u002F \"a.json\").write_text(\"{}\")\n    result = runner.invoke(app, [\"cache\", \"clear\"])\n    assert result.exit_code == 0\n    assert not cache.exists()\n",[14,1454,1455,1460,1467,1479,1483,1495,1506,1510,1520,1524,1528,1533,1543,1575,1607,1614,1618,1622,1632,1642,1665,1681,1685,1689,1699,1723,1740,1744,1748,1757,1773,1784,1796,1812,1816,1820,1829,1842,1863,1888,1904,1914],{"__ignoreMap":125},[129,1456,1457],{"class":131,"line":132},[129,1458,1459],{"class":135},"# tests\u002Ftest_paths.py\n",[129,1461,1462,1464],{"class":131,"line":139},[129,1463,167],{"class":142},[129,1465,1466],{"class":153}," pytest\n",[129,1468,1469,1471,1474,1476],{"class":131,"line":157},[129,1470,143],{"class":142},[129,1472,1473],{"class":153}," typer.testing ",[129,1475,167],{"class":142},[129,1477,1478],{"class":153}," CliRunner\n",[129,1480,1481],{"class":131,"line":164},[129,1482,161],{"emptyLinePlaceholder":160},[129,1484,1485,1487,1490,1492],{"class":131,"line":173},[129,1486,143],{"class":142},[129,1488,1489],{"class":153}," mytool.cli ",[129,1491,167],{"class":142},[129,1493,1494],{"class":153}," app\n",[129,1496,1497,1499,1501,1503],{"class":131,"line":186},[129,1498,143],{"class":142},[129,1500,777],{"class":153},[129,1502,167],{"class":142},[129,1504,1505],{"class":153}," resolve_paths\n",[129,1507,1508],{"class":131,"line":199},[129,1509,161],{"emptyLinePlaceholder":160},[129,1511,1512,1515,1517],{"class":131,"line":204},[129,1513,1514],{"class":153},"runner ",[129,1516,259],{"class":142},[129,1518,1519],{"class":153}," CliRunner()\n",[129,1521,1522],{"class":131,"line":217},[129,1523,161],{"emptyLinePlaceholder":160},[129,1525,1526],{"class":131,"line":222},[129,1527,161],{"emptyLinePlaceholder":160},[129,1529,1530],{"class":131,"line":235},[129,1531,1532],{"class":248},"@pytest.fixture\n",[129,1534,1535,1537,1540],{"class":131,"line":240},[129,1536,443],{"class":142},[129,1538,1539],{"class":248}," isolated",[129,1541,1542],{"class":153},"(tmp_path, monkeypatch):\n",[129,1544,1545,1547,1550,1552,1554,1557,1559,1562,1564,1567,1569,1572],{"class":131,"line":245},[129,1546,1079],{"class":142},[129,1548,1549],{"class":153}," kind ",[129,1551,378],{"class":142},[129,1553,381],{"class":153},[129,1555,1556],{"class":231},"\"CONFIG\"",[129,1558,418],{"class":153},[129,1560,1561],{"class":231},"\"CACHE\"",[129,1563,418],{"class":153},[129,1565,1566],{"class":231},"\"STATE\"",[129,1568,418],{"class":153},[129,1570,1571],{"class":231},"\"LOG\"",[129,1573,1574],{"class":153},"):\n",[129,1576,1577,1580,1582,1585,1587,1590,1592,1595,1597,1599,1602,1604],{"class":131,"line":268},[129,1578,1579],{"class":153},"        monkeypatch.setenv(",[129,1581,1151],{"class":142},[129,1583,1584],{"class":231},"\"MYTOOL_",[129,1586,1103],{"class":146},[129,1588,1589],{"class":153},"kind",[129,1591,1117],{"class":146},[129,1593,1594],{"class":231},"_DIR\"",[129,1596,418],{"class":153},[129,1598,452],{"class":146},[129,1600,1601],{"class":153},"(tmp_path ",[129,1603,342],{"class":142},[129,1605,1606],{"class":153}," kind.lower()))\n",[129,1608,1609,1611],{"class":131,"line":280},[129,1610,480],{"class":142},[129,1612,1613],{"class":153}," tmp_path\n",[129,1615,1616],{"class":131,"line":286},[129,1617,161],{"emptyLinePlaceholder":160},[129,1619,1620],{"class":131,"line":292},[129,1621,161],{"emptyLinePlaceholder":160},[129,1623,1624,1626,1629],{"class":131,"line":298},[129,1625,443],{"class":142},[129,1627,1628],{"class":248}," test_env_overrides",[129,1630,1631],{"class":153},"(isolated):\n",[129,1633,1634,1637,1639],{"class":131,"line":304},[129,1635,1636],{"class":153},"    p ",[129,1638,259],{"class":142},[129,1640,1641],{"class":153}," resolve_paths()\n",[129,1643,1644,1647,1650,1652,1655,1657,1660,1663],{"class":131,"line":309},[129,1645,1646],{"class":142},"    assert",[129,1648,1649],{"class":153}," p.config_file ",[129,1651,1129],{"class":142},[129,1653,1654],{"class":153}," isolated ",[129,1656,342],{"class":142},[129,1658,1659],{"class":231}," \"config\"",[129,1661,1662],{"class":142}," \u002F",[129,1664,345],{"class":231},[129,1666,1667,1669,1672,1674,1676,1678],{"class":131,"line":318},[129,1668,1646],{"class":142},[129,1670,1671],{"class":153}," p.cache_dir ",[129,1673,1129],{"class":142},[129,1675,1654],{"class":153},[129,1677,342],{"class":142},[129,1679,1680],{"class":231}," \"cache\"\n",[129,1682,1683],{"class":131,"line":330},[129,1684,161],{"emptyLinePlaceholder":160},[129,1686,1687],{"class":131,"line":348},[129,1688,161],{"emptyLinePlaceholder":160},[129,1690,1691,1693,1696],{"class":131,"line":353},[129,1692,443],{"class":142},[129,1694,1695],{"class":248}," test_flag_beats_env",[129,1697,1698],{"class":153},"(isolated, tmp_path):\n",[129,1700,1701,1703,1705,1708,1711,1713,1716,1718,1721],{"class":131,"line":369},[129,1702,1636],{"class":153},[129,1704,259],{"class":142},[129,1706,1707],{"class":153}," resolve_paths(",[129,1709,1710],{"class":255},"config_dir",[129,1712,259],{"class":142},[129,1714,1715],{"class":153},"tmp_path ",[129,1717,342],{"class":142},[129,1719,1720],{"class":231}," \"flag\"",[129,1722,265],{"class":153},[129,1724,1725,1727,1730,1732,1735,1737],{"class":131,"line":405},[129,1726,1646],{"class":142},[129,1728,1729],{"class":153}," p.config_dir ",[129,1731,1129],{"class":142},[129,1733,1734],{"class":153}," tmp_path ",[129,1736,342],{"class":142},[129,1738,1739],{"class":231}," \"flag\"\n",[129,1741,1742],{"class":131,"line":430},[129,1743,161],{"emptyLinePlaceholder":160},[129,1745,1746],{"class":131,"line":435},[129,1747,161],{"emptyLinePlaceholder":160},[129,1749,1750,1752,1755],{"class":131,"line":440},[129,1751,443],{"class":142},[129,1753,1754],{"class":248}," test_paths_command_creates_nothing",[129,1756,1631],{"class":153},[129,1758,1759,1762,1764,1767,1770],{"class":131,"line":466},[129,1760,1761],{"class":153},"    result ",[129,1763,259],{"class":142},[129,1765,1766],{"class":153}," runner.invoke(app, [",[129,1768,1769],{"class":231},"\"paths\"",[129,1771,1772],{"class":153},"])\n",[129,1774,1775,1777,1780,1782],{"class":131,"line":477},[129,1776,1646],{"class":142},[129,1778,1779],{"class":153}," result.exit_code ",[129,1781,1129],{"class":142},[129,1783,895],{"class":146},[129,1785,1786,1788,1790,1793],{"class":131,"line":498},[129,1787,1646],{"class":142},[129,1789,1659],{"class":231},[129,1791,1792],{"class":142}," in",[129,1794,1795],{"class":153}," result.output\n",[129,1797,1798,1800,1802,1805,1807,1809],{"class":131,"line":503},[129,1799,1646],{"class":142},[129,1801,1237],{"class":142},[129,1803,1804],{"class":153}," (isolated ",[129,1806,342],{"class":142},[129,1808,1132],{"class":231},[129,1810,1811],{"class":153},").exists()\n",[129,1813,1814],{"class":131,"line":508},[129,1815,161],{"emptyLinePlaceholder":160},[129,1817,1818],{"class":131,"line":530},[129,1819,161],{"emptyLinePlaceholder":160},[129,1821,1822,1824,1827],{"class":131,"line":536},[129,1823,443],{"class":142},[129,1825,1826],{"class":248}," test_cache_clear",[129,1828,1631],{"class":153},[129,1830,1831,1834,1836,1838,1840],{"class":131,"line":561},[129,1832,1833],{"class":153},"    cache ",[129,1835,259],{"class":142},[129,1837,1654],{"class":153},[129,1839,342],{"class":142},[129,1841,1680],{"class":231},[129,1843,1844,1847,1849,1852,1855,1857,1859,1861],{"class":131,"line":569},[129,1845,1846],{"class":153},"    (cache ",[129,1848,342],{"class":142},[129,1850,1851],{"class":231}," \"sub\"",[129,1853,1854],{"class":153},").mkdir(",[129,1856,411],{"class":255},[129,1858,259],{"class":142},[129,1860,262],{"class":146},[129,1862,265],{"class":153},[129,1864,1865,1867,1869,1871,1873,1876,1879,1881,1884,1886],{"class":131,"line":597},[129,1866,1846],{"class":153},[129,1868,342],{"class":142},[129,1870,1851],{"class":231},[129,1872,1662],{"class":142},[129,1874,1875],{"class":231}," \"a.json\"",[129,1877,1878],{"class":153},").write_text(",[129,1880,1154],{"class":231},[129,1882,1883],{"class":146},"{}",[129,1885,1154],{"class":231},[129,1887,265],{"class":153},[129,1889,1890,1892,1894,1896,1898,1900,1902],{"class":131,"line":618},[129,1891,1761],{"class":153},[129,1893,259],{"class":142},[129,1895,1766],{"class":153},[129,1897,829],{"class":231},[129,1899,418],{"class":153},[129,1901,1200],{"class":231},[129,1903,1772],{"class":153},[129,1905,1906,1908,1910,1912],{"class":131,"line":638},[129,1907,1646],{"class":142},[129,1909,1779],{"class":153},[129,1911,1129],{"class":142},[129,1913,895],{"class":146},[129,1915,1916,1918,1920],{"class":131,"line":658},[129,1917,1646],{"class":142},[129,1919,1237],{"class":142},[129,1921,1922],{"class":153}," cache.exists()\n",[10,1924,1925,1926,1929,1930,1932],{},"The \"creates nothing\" test is worth keeping: it catches the regression where someone adds ",[14,1927,1928],{},"mkdir"," to an import-time path computation and every ",[14,1931,694],{}," starts littering the home directory.",[33,1934,1936],{"id":1935},"conclusion","Conclusion",[10,1938,1939,1940,1942,1943,1945,1946,1950],{},"Put each file where the operating system expects that kind of file — config, cache, state, logs — using ",[14,1941,24],{}," so one line of code is right on Linux, macOS and Windows. Resolve directories in one module, layer flag and environment overrides on top, create directories only when writing, and give users a ",[14,1944,1397],{}," command and a way to clear the cache. Combined with ",[27,1947,1949],{"href":1948},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fwriting-files-atomically-in-python-clis\u002F","atomic writes"," for the files that matter, your tool's footprint on a user's machine becomes predictable and easy to manage.",[33,1952,1954],{"id":1953},"frequently-asked-questions","Frequently asked questions",[1956,1957,1959,1960,1963],"h3",{"id":1958},"isnt-mytoolrc-simpler","Isn't ",[14,1961,1962],{},"~\u002F.mytoolrc"," simpler?",[10,1965,1966],{},"It is simpler for you and worse for users. A home directory full of dot-files is hard to manage, and nothing distinguishes config worth backing up from cache worth deleting. If you already ship a dot-file, keep reading it as a legacy location while writing to the platform directory.",[1956,1968,1970,1971,1973],{"id":1969},"should-macos-use-config-instead-of-application-support","Should macOS use ",[14,1972,20],{}," instead of Application Support?",[10,1975,1976,1977,1979,1980,1982,1983,1985,1986,1988],{},"Many developer tools do, because their users expect Linux-style paths and share dotfiles across systems. ",[14,1978,24],{}," follows Apple's convention. If your audience strongly prefers ",[14,1981,20],{},", honour ",[14,1984,724],{}," explicitly on macOS as an opt-in, and document it in your ",[14,1987,1397],{}," output.",[1956,1990,1992],{"id":1991},"where-should-credentials-go","Where should credentials go?",[10,1994,1995,1996,1999,2000,31],{},"Not in any of these directories as plain text if you can avoid it. Use the system keychain via ",[14,1997,1998],{},"keyring",", and keep only non-secret metadata (which account is active) in state. See ",[27,2001,2003],{"href":2002},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fstoring-tokens-with-keyring\u002F","storing tokens with keyring",[1956,2005,2007],{"id":2006},"how-should-the-tool-behave-in-ci-or-a-read-only-container","How should the tool behave in CI or a read-only container?",[10,2009,2010,2011,2014],{},"Assume the home directory may be missing, read-only or thrown away after every job. Treat a failure to create the cache directory as a warning, not an error — run without a cache and say so once on stderr. Let operators redirect every directory with the ",[14,2012,2013],{},"MYTOOL_*_DIR"," variables so a CI job can point the cache at a directory its runner persists between builds, which is often the single biggest speed-up available for tools that download metadata. And never require a config file to exist: defaults plus flags and environment variables should be enough to run anywhere.",[1956,2016,2018,2019,2022],{"id":2017},"what-about-per-project-caches-like-pytest_cache","What about per-project caches, like ",[14,2020,2021],{},".pytest_cache","?",[10,2024,2025,2026,2029,2030,2033],{},"A cache tied to one project and invalidated with it can reasonably live in that project, as pytest and mypy do — but create it only when the user runs your tool there, add a ",[14,2027,2028],{},".gitignore"," inside it containing ",[14,2031,2032],{},"*",", and document it.",[33,2035,2037],{"id":2036},"related","Related",[38,2039,2040,2046,2052,2057,2062],{},[41,2041,2042,2043],{},"Up: ",[27,2044,2045],{"href":29},"Filesystem paths and atomic writes",[41,2047,2048],{},[27,2049,2051],{"href":2050},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fcross-platform-paths-with-pathlib\u002F","Cross-platform paths with pathlib",[41,2053,2054],{},[27,2055,2056],{"href":1948},"Writing files atomically in Python CLIs",[41,2058,2059],{},[27,2060,2061],{"href":716},"Config precedence: flags, env, files and defaults",[41,2063,2064],{},[27,2065,2067],{"href":2066},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fcaching-expensive-work-between-cli-runs\u002F","Caching expensive work between CLI runs",[2069,2070,2071],"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":125,"searchDepth":139,"depth":139,"links":2073},[2074,2075,2076,2077,2078,2079,2080,2090],{"id":35,"depth":139,"text":36},{"id":59,"depth":139,"text":60},{"id":114,"depth":139,"text":115},{"id":1383,"depth":139,"text":1384},{"id":1441,"depth":139,"text":1442},{"id":1935,"depth":139,"text":1936},{"id":1953,"depth":139,"text":1954,"children":2081},[2082,2084,2086,2087,2088],{"id":1958,"depth":157,"text":2083},"Isn't ~\u002F.mytoolrc simpler?",{"id":1969,"depth":157,"text":2085},"Should macOS use ~\u002F.config instead of Application Support?",{"id":1991,"depth":157,"text":1992},{"id":2006,"depth":157,"text":2007},{"id":2017,"depth":157,"text":2089},"What about per-project caches, like .pytest_cache?",{"id":2036,"depth":139,"text":2037},"2026-09-18","Put a Python CLI’s config, cache, state and logs in the right per-user directories on Linux, macOS and Windows with platformdirs, overrides and a paths command.","beginner",false,"md",{},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fstoring-app-data-with-platformdirs",{"title":5,"description":2092},"cli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fstoring-app-data-with-platformdirs\u002Findex",[24,2101,2102,2103],"xdg","configuration","filesystem","ekJRKJf-r-JJwMWXmvyiWd_jabXxC_1-ZD5ye5kDn24",[2106,2109,2112,2115,2118,2121,2124,2127,2130,2133,2136,2139,2142,2145,2148,2151,2154,2157,2160,2163,2166,2169,2172,2175,2178,2181,2184,2187,2190,2193,2196,2199,2202,2205,2208,2211,2214,2217,2220,2223,2226,2229,2232,2235,2238,2241,2244,2247,2250,2253,2256,2259,2262,2265,2268,2271,2274,2277,2280,2283,2286,2289,2292,2295,2298,2301,2304,2307,2310,2313,2316,2319,2320,2323,2326,2329,2332,2335,2338,2341,2344,2347,2350,2353,2356,2359,2362,2365,2368,2371,2374,2377,2379,2382,2385,2388,2391,2394,2397,2400,2403,2406,2409,2412,2415,2418,2421,2424,2427,2430,2433,2436,2439,2442,2445,2448,2451,2454,2457,2460,2463,2466,2469,2472,2475,2478,2481,2484,2487,2490,2493,2496,2499,2502,2505,2508,2511,2514,2517,2520,2523,2526,2529,2532,2535,2538,2541,2544,2547,2550,2553,2556,2559,2562,2565,2568,2571,2574,2577,2580,2583,2586,2589,2592,2595,2598,2601,2604,2607,2610,2613,2616,2619,2622,2625,2628,2631,2634,2637,2640,2643,2646,2649],{"path":2107,"title":2108},"\u002Fabout","About Python CLI Toolcraft",{"path":2110,"title":2111},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies","Advanced Argument Validation Strategies",{"path":2113,"title":2114},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fparsing-nested-json-arguments-in-python-clis","Parsing Nested JSON Args in Python CLIs",{"path":2116,"title":2117},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-dependent-and-conflicting-options","Validating Dependent and Conflicting CLI Options",{"path":2119,"title":2120},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-file-and-directory-paths-in-clis","Validating File and Directory Paths in CLIs",{"path":2122,"title":2123},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fwriting-custom-click-parameter-types","Writing Custom Click Parameter Types",{"path":2125,"title":2126},"\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":2128,"title":2129},"\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":2131,"title":2132},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual","Building Terminal UIs with Textual for Python CLIs",{"path":2134,"title":2135},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Ftesting-textual-apps-with-pilot","Testing Textual Apps with Pilot",{"path":2137,"title":2138},"\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":2140,"title":2141},"\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":2143,"title":2144},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation","CLI Help Output and Documentation",{"path":2146,"title":2147},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fversioning-and-deprecating-cli-flags","Versioning and Deprecating CLI Flags",{"path":2149,"title":2150},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fwriting-help-text-users-actually-read","Writing Help Text Users Actually Read",{"path":2152,"title":2153},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fadapting-output-to-terminal-width","Adapting Python CLI Output to Terminal Width",{"path":2155,"title":2156},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fdetecting-ci-environments-and-non-interactive-shells","Detecting CI Environments and Non-Interactive Shells",{"path":2158,"title":2159},"\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":2161,"title":2162},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility","Cross-Platform Terminal Compatibility for Python CLIs",{"path":2164,"title":2165},"\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":2167,"title":2168},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fchoosing-exit-codes-for-cli-tools","Choosing Exit Codes for CLI Tools",{"path":2170,"title":2171},"\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":2173,"title":2174},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Ffriendly-error-messages-and-tracebacks","Friendly Error Messages and Tracebacks",{"path":2176,"title":2177},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fhandling-keyboard-interrupt-cleanly","Handling Keyboard Interrupt Cleanly",{"path":2179,"title":2180},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes","Error Handling and Exit Codes for CLIs",{"path":2182,"title":2183},"\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":2185,"title":2186},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fconfig-precedence-flags-env-files-defaults","Config Precedence: Flags, Env, Files, Defaults",{"path":2188,"title":2189},"\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":2191,"title":2192},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars","Handling Config Files and Env Vars in CLIs",{"path":2194,"title":2195},"\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":2197,"title":2198},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Freading-toml-config-with-tomllib","Reading TOML Config with tomllib in Python CLIs",{"path":2200,"title":2201},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Ftyped-settings-with-pydantic-settings","Typed Settings with pydantic-settings in Python CLIs",{"path":2203,"title":2204},"\u002Fadvanced-input-parsing-user-experience","Advanced Input Parsing for Python CLIs",{"path":2206,"title":2207},"\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":2209,"title":2210},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Fbuilding-interactive-prompts-and-menus","Building Interactive Prompts and Menus in Python CLIs",{"path":2212,"title":2213},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich","Interactive Terminal UI with Rich",{"path":2215,"title":2216},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Flive-dashboards-with-rich-live","Live Dashboards with Rich Live in Python CLIs",{"path":2218,"title":2219},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Frendering-tables-and-json-with-rich","Rendering Tables and JSON with Rich",{"path":2221,"title":2222},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Ftheming-rich-output-consistently","Theming Rich Output Consistently in Python CLIs",{"path":2224,"title":2225},"\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":2227,"title":2228},"\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":2230,"title":2231},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis","Shell Completion for Python CLIs",{"path":2233,"title":2234},"\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":2236,"title":2237},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Ftesting-shell-completion-in-python-clis","Testing Shell Completion in Python CLIs",{"path":2239,"title":2240},"\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":2242,"title":2243},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-verbose-and-quiet-logging-flags","Adding Verbose and Quiet Logging Flags",{"path":2245,"title":2246},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps","Structured Logging for CLI Apps",{"path":2248,"title":2249},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fstructured-json-logging-in-python-clis","Structured JSON Logging in Python CLIs",{"path":2251,"title":2252},"\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":2254,"title":2255},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fdetecting-tty-and-adapting-output","Detecting a TTY and Adapting Output",{"path":2257,"title":2258},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Femitting-json-output-for-scripting","Emitting JSON Output for Scripting",{"path":2260,"title":2261},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fhandling-broken-pipe-and-sigpipe","Handling Broken Pipe and SIGPIPE",{"path":2263,"title":2264},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes","Working with stdin, stdout and Pipes",{"path":2266,"title":2267},"\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":2269,"title":2270},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Freading-piped-input-in-python-clis","Reading Piped Input in Python CLIs",{"path":2272,"title":2273},"\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":2275,"title":2276},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fdownloading-files-with-progress-in-python","Downloading Files with Progress in Python CLIs",{"path":2278,"title":2279},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis","Calling HTTP APIs from Python CLIs",{"path":2281,"title":2282},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Foauth-device-flow-login-for-clis","OAuth Device Flow Login for Python CLIs",{"path":2284,"title":2285},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fpaginating-api-results-in-a-cli","Paginating API Results in a Python CLI",{"path":2287,"title":2288},"\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":2290,"title":2291},"\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":2293,"title":2294},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis","Concurrency and Async in Python CLIs",{"path":2296,"title":2297},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fmultiprocessing-for-cpu-bound-cli-tasks","Multiprocessing for CPU-Bound CLI Tasks",{"path":2299,"title":2300},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fparallelising-cli-work-with-thread-pools","Parallelising CLI Work with Thread Pools",{"path":2302,"title":2303},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Frate-limiting-concurrent-requests-in-clis","Rate-Limiting Concurrent Requests in Python CLIs",{"path":2305,"title":2306},"\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":2308,"title":2309},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fcross-platform-paths-with-pathlib","Cross-Platform Paths with pathlib in CLIs",{"path":2311,"title":2312},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Ffile-locking-for-concurrent-cli-runs","File Locking for Concurrent CLI Runs in Python",{"path":2314,"title":2315},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes","Filesystem Paths and Atomic Writes for CLIs",{"path":2317,"title":2318},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fsafe-temporary-files-and-directories","Safe Temporary Files and Directories in CLIs",{"path":2097,"title":5},{"path":2321,"title":2322},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fwriting-files-atomically-in-python-clis","Writing Files Atomically in Python CLIs",{"path":2324,"title":2325},"\u002Fcli-runtime-systems-integration","CLI Runtime & Systems Integration for Python",{"path":2327,"title":2328},"\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":2330,"title":2331},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fhandling-sigterm-and-graceful-shutdown","Handling SIGTERM and Graceful Shutdown in CLIs",{"path":2333,"title":2334},"\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":2336,"title":2337},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis","Long-Running and Watch-Mode Python CLIs",{"path":2339,"title":2340},"\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":2342,"title":2343},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Favoiding-shell-injection-in-python-clis","Avoiding Shell Injection in Python CLIs",{"path":2345,"title":2346},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fcalling-external-commands-safely-with-subprocess","Calling External Commands Safely with subprocess",{"path":2348,"title":2349},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fhandling-subprocess-timeouts-and-exit-codes","Handling Subprocess Timeouts and Exit Codes",{"path":2351,"title":2352},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis","Running Subprocesses from Python CLIs",{"path":2354,"title":2355},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fstreaming-subprocess-output-in-real-time","Streaming Subprocess Output in Real Time",{"path":2357,"title":2358},"\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":2360,"title":2361},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis","Secrets and Credentials in Python CLIs",{"path":2363,"title":2364},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fprompting-for-passwords-securely","Prompting for Passwords Securely in Python CLIs",{"path":2366,"title":2367},"\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":2369,"title":2370},"\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":2372,"title":2373},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fstoring-tokens-with-keyring","Storing CLI Tokens Securely with keyring",{"path":2375,"title":2376},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fsupporting-multiple-profiles-and-accounts","Supporting Multiple Profiles and Accounts in CLIs",{"path":342,"title":2378},"Python CLI Toolcraft",{"path":2380,"title":2381},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fcaching-expensive-work-between-cli-runs","Caching Expensive Work Between Python CLI Runs",{"path":2383,"title":2384},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading","CLI Startup Performance and Lazy Loading",{"path":2386,"title":2387},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup","Lazy Loading Subcommands for Faster Startup",{"path":2389,"title":2390},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fprofiling-python-cli-startup-time","Profiling Python CLI Startup Time",{"path":2392,"title":2393},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Freducing-cli-dependency-weight","Reducing CLI Dependency Weight",{"path":2395,"title":2396},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-subparsers-for-subcommands","argparse Subparsers for Subcommands",{"path":2398,"title":2399},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-vs-click-vs-typer-comparison","argparse vs Click vs Typer Compared",{"path":2401,"title":2402},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse","Command-Line Parsing with argparse",{"path":2404,"title":2405},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmigrating-from-argparse-to-typer","Migrating from argparse to Typer",{"path":2407,"title":2408},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmutually-exclusive-options-in-argparse","Mutually Exclusive Options in argparse",{"path":2410,"title":2411},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fwriting-custom-argparse-actions","Writing Custom argparse Actions in Python",{"path":2413,"title":2414},"\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":2416,"title":2417},"\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":2419,"title":2420},"\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":2422,"title":2423},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions","Designing CLI Interfaces and Conventions in Python",{"path":2425,"title":2426},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fnaming-commands-and-flags-consistently","Naming Commands and Flags Consistently in Python CLIs",{"path":2428,"title":2429},"\u002Fmodern-python-cli-frameworks-architecture","Python CLI Frameworks and Architecture",{"path":2431,"title":2432},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fdiscovering-plugins-with-entry-points","Discovering Plugins with Entry Points in Python CLIs",{"path":2434,"title":2435},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fhook-based-plugins-with-pluggy","Hook-Based Plugins for Python CLIs with pluggy",{"path":2437,"title":2438},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis","Plugin Architectures for Extensible CLIs",{"path":2440,"title":2441},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fversioning-a-plugin-api","Versioning a Plugin API for a Python CLI",{"path":2443,"title":2444},"\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":2446,"title":2447},"\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":2449,"title":2450},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fdependency-injection-patterns-for-cli-commands","Dependency Injection Patterns for CLI Commands",{"path":2452,"title":2453},"\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":2455,"title":2456},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis","Structuring Multi-Command Python CLIs",{"path":2458,"title":2459},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-common-options-across-commands","Sharing Common Options Across Python CLI Commands",{"path":2461,"title":2462},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-state-with-click-context-objects","Sharing State with Click Context Objects",{"path":2464,"title":2465},"\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":2467,"title":2468},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications","Testing Python CLI Applications",{"path":2470,"title":2471},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fmeasuring-cli-test-coverage","Measuring CLI Test Coverage",{"path":2473,"title":2474},"\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":2476,"title":2477},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fproperty-based-testing-cli-arguments-with-hypothesis","Property-Based Testing CLI Arguments with Hypothesis",{"path":2479,"title":2480},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fsnapshot-testing-cli-output","Snapshot Testing CLI Output",{"path":2482,"title":2483},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-click-commands-with-clirunner","Testing Click Commands with CliRunner",{"path":2485,"title":2486},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-interactive-prompts-and-stdin","Testing Interactive Prompts and stdin",{"path":2488,"title":2489},"\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":2491,"title":2492},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fbuilding-dynamic-commands-in-click","Building Dynamic Commands in Click",{"path":2494,"title":2495},"\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":2497,"title":2498},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each","Typer vs Click: When to Use Each",{"path":2500,"title":2501},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Ftyper-callback-functions-explained","Typer callback functions explained",{"path":2503,"title":2504},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fusing-annotated-options-in-typer","Using Annotated Options in Typer",{"path":2506,"title":2507},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fautomating-releases-from-git-tags","Automating Python CLI Releases from Git Tags",{"path":2509,"title":2510},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fcaching-uv-dependencies-in-ci","Caching uv Dependencies in CI for Python CLIs",{"path":2512,"title":2513},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis","CI\u002FCD Pipelines for Python CLIs",{"path":2515,"title":2516},"\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":2518,"title":2519},"\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":2521,"title":2522},"\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":2524,"title":2525},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fbuilding-a-cookiecutter-template-for-typer-clis","Building a Cookiecutter Template for Typer CLIs",{"path":2527,"title":2528},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fcopier-vs-cookiecutter-for-cli-templates","Copier vs Cookiecutter for CLI Templates",{"path":2530,"title":2531},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter","CLI Project Scaffolding with Cookiecutter",{"path":2533,"title":2534},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fpost-generation-hooks-in-cli-templates","Post-Generation Hooks in Python CLI Templates",{"path":2536,"title":2537},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbuilding-cross-platform-release-binaries-in-ci","Building Cross-Platform Release Binaries in CI",{"path":2539,"title":2540},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbundling-a-python-cli-with-pyinstaller","Bundling a Python CLI with PyInstaller",{"path":2542,"title":2543},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fhomebrew-and-scoop-packaging-for-python-clis","Homebrew and Scoop Packaging for Python CLIs",{"path":2545,"title":2546},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries","Distributing CLIs as Standalone Binaries",{"path":2548,"title":2549},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fnuitka-vs-pyinstaller-for-python-clis","Nuitka vs PyInstaller for Python CLI Binaries",{"path":2551,"title":2552},"\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":2554,"title":2555},"\u002Fproject-setup-dependency-management","Project Setup & Dependency Management",{"path":2557,"title":2558},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Fconfiguring-ruff-for-a-cli-project","Configuring Ruff for a Python CLI Project",{"path":2560,"title":2561},"\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":2563,"title":2564},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code","Linting and Type-Checking Python CLI Code",{"path":2566,"title":2567},"\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":2569,"title":2570},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fautomating-changelogs-with-conventional-commits","Automating Changelogs with Conventional Commits",{"path":2572,"title":2573},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fderiving-versions-from-git-tags-with-hatch-vcs","Deriving CLI Versions from Git Tags with hatch-vcs",{"path":2575,"title":2576},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fexposing-version-info-and-build-metadata","Exposing Version Info and Build Metadata",{"path":2578,"title":2579},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs","Managing CLI Versioning & Changelogs",{"path":2581,"title":2582},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fsemantic-versioning-policy-for-cli-tools","A Semantic Versioning Policy for CLI Tools",{"path":2584,"title":2585},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbuilding-wheels-and-sdists-for-python-clis","Building Wheels and sdists for Python CLIs",{"path":2587,"title":2588},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbundling-data-files-with-importlib-resources","Bundling Data Files with importlib.resources in CLIs",{"path":2590,"title":2591},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution","Packaging Python CLIs for Distribution",{"path":2593,"title":2594},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Finstalling-and-distributing-clis-with-pipx","Installing and Distributing CLIs with pipx",{"path":2596,"title":2597},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fpublishing-a-python-cli-to-pypi","Publishing a Python CLI to PyPI",{"path":2599,"title":2600},"\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":2602,"title":2603},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development","Poetry Workflows for CLI Development",{"path":2605,"title":2606},"\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":2608,"title":2609},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-dependency-groups-for-cli-tooling","Poetry Dependency Groups for CLI Tooling",{"path":2611,"title":2612},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-entry-points-and-scripts-for-clis","Poetry Entry Points and Scripts for CLIs",{"path":2614,"title":2615},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects","Pre-commit Hooks for CLI Projects",{"path":2617,"title":2618},"\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":2620,"title":2621},"\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":2623,"title":2624},"\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":2626,"title":2627},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management","uv for Python CLI Dependency Management",{"path":2629,"title":2630},"\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":2632,"title":2633},"\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":2635,"title":2636},"\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":2638,"title":2639},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fuv-workspaces-for-multi-package-clis","uv Workspaces for Multi-Package Python CLIs",{"path":2641,"title":2642},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices","Python CLI Env Isolation Best Practices",{"path":2644,"title":2645},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fmanaging-virtual-environments-for-cross-platform-clis","Managing Python CLI Virtual Environments",{"path":2647,"title":2648},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fpinning-the-python-version-for-a-cli","Pinning the Python Version for a CLI",{"path":2650,"title":2651},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fsupporting-multiple-python-versions-with-nox","Supporting Multiple Python Versions with nox",1789736905049]