[{"data":1,"prerenderedAt":2976},["ShallowReactive",2],{"page-\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-trace-ids-and-context-to-cli-logs\u002F":3,"content-directory":2428},{"id":4,"title":5,"body":6,"date":2415,"description":2416,"difficulty":2417,"draft":2418,"extension":2419,"meta":2420,"navigation":169,"path":2421,"seo":2422,"stem":2423,"tags":2424,"updated":2415,"__hash__":2427},"content\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-trace-ids-and-context-to-cli-logs\u002Findex.md","Adding Trace IDs and Context to Python CLI Logs",{"type":7,"value":8,"toc":2394},"minimark",[9,28,33,55,59,63,83,87,90,109,113,128,859,862,1510,1517,1520,1525,1545,1551,1573,1583,1587,1593,1702,1716,1720,1764,1768,1771,2255,2266,2270,2282,2286,2298,2301,2305,2308,2312,2334,2338,2350,2354,2357,2361,2390],[10,11,12,13,17,18,21,22,27],"p",{},"A user reports that \"the sync failed last night\". The log file has four thousand lines from a dozen runs, two of them overlapping because a cron job and a person ran the tool at the same time. Which lines belong to the failed run? Which item was being processed when it failed? Which release of the tool was it? And what did the server see at that moment? Every one of those questions is answered by the same technique: attach a small set of context fields — a run ID, the command, the version, and the current item — to every log record, and send the run ID to the services the CLI talks to. This guide builds that with nothing but the standard library's ",[14,15,16],"code",{},"contextvars"," and ",[14,19,20],{},"logging",", shows how to carry the context into worker threads, and tests it. It belongs to the ",[23,24,26],"a",{"href":25},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002F","structured logging for CLI apps topic",".",[29,30,32],"h2",{"id":31},"prerequisites","Prerequisites",[34,35,36,48],"ul",{},[37,38,39,40,42,43,47],"li",{},"Python 3.10+ and a Typer or Click CLI that already logs through ",[14,41,20],{},"; see ",[23,44,46],{"href":45},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fstructured-json-logging-in-python-clis\u002F","structured JSON logging in Python CLIs"," for the basic setup.",[37,49,50,51,54],{},"Optionally, an HTTP client such as ",[14,52,53],{},"httpx"," if the CLI calls APIs.",[29,56,58],{"id":57},"one-id-from-the-command-to-the-server","One ID from the command to the server",[60,61],"inline-diagram",{"name":62},"tr-flow",[10,64,65,66,70,71,74,75,78,79,82],{},"The design has four parts. At startup the CLI generates a ",[67,68,69],"strong",{},"run ID"," — a short random string, unique per invocation. It stores the ID in a ",[67,72,73],{},"context variable",", together with other fields that stay constant for the run. A ",[67,76,77],{},"logging filter"," copies those fields onto every record, so formatters can print them without any call site mentioning them. And the HTTP client sends the run ID as a ",[67,80,81],{},"request header",", so the server's logs for the same operation can be found by searching for the ID the user quotes in their bug report.",[29,84,86],{"id":85},"which-fields-are-worth-adding","Which fields are worth adding",[60,88],{"name":89},"tr-fields",[10,91,92,93,96,97,100,101,104,105,108],{},"Keep the set small and stable. ",[14,94,95],{},"run_id"," groups the lines of one invocation. ",[14,98,99],{},"command"," says what the user was doing, ",[14,102,103],{},"version"," says which release did it — invaluable once several versions are in the wild. Target fields such as the profile or environment say where the command was pointed. And a per-unit field such as ",[14,106,107],{},"item"," says which file, record or host was being processed when something went wrong. Everything else belongs in the message itself.",[29,110,112],{"id":111},"the-recipe","The recipe",[10,114,115,116,119,120,123,124,127],{},"The context lives in one module. A ",[14,117,118],{},"ContextVar"," holds a dictionary of fields; ",[14,121,122],{},"bind()"," adds fields for the rest of the run, ",[14,125,126],{},"bound()"," adds them for a block, and a filter and two formatters put them on the output:",[129,130,135],"pre",{"className":131,"code":132,"language":133,"meta":134,"style":134},"language-python shiki shiki-themes github-light github-dark","# src\u002Fmytool\u002Fcontext.py\nfrom __future__ import annotations\n\nimport contextvars\nimport json\nimport logging\nimport uuid\nfrom collections.abc import Iterator\nfrom contextlib import contextmanager\nfrom typing import Any\n\n_fields: contextvars.ContextVar[dict[str, Any]] = contextvars.ContextVar(\"log_fields\", default={})\n\n\ndef new_run_id() -> str:\n    return uuid.uuid4().hex[:12]\n\n\ndef bind(**fields: Any) -> None:\n    \"\"\"Add fields to every log record for the rest of this context.\"\"\"\n    _fields.set({**_fields.get(), **fields})\n\n\n@contextmanager\ndef bound(**fields: Any) -> Iterator[None]:\n    \"\"\"Add fields for the duration of a block, e.g. one item of work.\"\"\"\n    token = _fields.set({**_fields.get(), **fields})\n    try:\n        yield\n    finally:\n        _fields.reset(token)\n\n\ndef current() -> dict[str, Any]:\n    return dict(_fields.get())\n\n\nclass ContextFilter(logging.Filter):\n    \"\"\"Copy the bound fields onto each record as attributes.\"\"\"\n\n    def filter(self, record: logging.LogRecord) -> bool:\n        record.ctx = current()\n        return True\n\n\nclass JsonFormatter(logging.Formatter):\n    def format(self, record: logging.LogRecord) -> str:\n        event = {\"level\": record.levelname.lower(), \"msg\": record.getMessage(),\n                 \"logger\": record.name, **getattr(record, \"ctx\", {})}\n        if record.exc_info:\n            event[\"exc\"] = self.formatException(record.exc_info)\n        return json.dumps(event, default=str)\n\n\nclass TextFormatter(logging.Formatter):\n    def format(self, record: logging.LogRecord) -> str:\n        ctx = \" \".join(f\"{k}={v}\" for k, v in getattr(record, \"ctx\", {}).items())\n        return f\"{record.levelname:\u003C7} {record.getMessage()}  {ctx}\".rstrip()\n","python","",[14,136,137,146,164,171,180,188,196,204,217,230,243,248,282,287,292,310,325,330,335,357,363,379,384,389,395,415,421,440,448,454,462,468,473,478,494,505,510,515,536,542,547,564,575,584,589,594,613,627,650,673,682,702,719,724,729,747,760,819],{"__ignoreMap":134},[138,139,142],"span",{"class":140,"line":141},"line",1,[138,143,145],{"class":144},"sJ8bj","# src\u002Fmytool\u002Fcontext.py\n",[138,147,149,153,157,160],{"class":140,"line":148},2,[138,150,152],{"class":151},"szBVR","from",[138,154,156],{"class":155},"sj4cs"," __future__",[138,158,159],{"class":151}," import",[138,161,163],{"class":162},"sVt8B"," annotations\n",[138,165,167],{"class":140,"line":166},3,[138,168,170],{"emptyLinePlaceholder":169},true,"\n",[138,172,174,177],{"class":140,"line":173},4,[138,175,176],{"class":151},"import",[138,178,179],{"class":162}," contextvars\n",[138,181,183,185],{"class":140,"line":182},5,[138,184,176],{"class":151},[138,186,187],{"class":162}," json\n",[138,189,191,193],{"class":140,"line":190},6,[138,192,176],{"class":151},[138,194,195],{"class":162}," logging\n",[138,197,199,201],{"class":140,"line":198},7,[138,200,176],{"class":151},[138,202,203],{"class":162}," uuid\n",[138,205,207,209,212,214],{"class":140,"line":206},8,[138,208,152],{"class":151},[138,210,211],{"class":162}," collections.abc ",[138,213,176],{"class":151},[138,215,216],{"class":162}," Iterator\n",[138,218,220,222,225,227],{"class":140,"line":219},9,[138,221,152],{"class":151},[138,223,224],{"class":162}," contextlib ",[138,226,176],{"class":151},[138,228,229],{"class":162}," contextmanager\n",[138,231,233,235,238,240],{"class":140,"line":232},10,[138,234,152],{"class":151},[138,236,237],{"class":162}," typing ",[138,239,176],{"class":151},[138,241,242],{"class":162}," Any\n",[138,244,246],{"class":140,"line":245},11,[138,247,170],{"emptyLinePlaceholder":169},[138,249,251,254,257,260,263,266,270,273,277,279],{"class":140,"line":250},12,[138,252,253],{"class":162},"_fields: contextvars.ContextVar[dict[",[138,255,256],{"class":155},"str",[138,258,259],{"class":162},", Any]] ",[138,261,262],{"class":151},"=",[138,264,265],{"class":162}," contextvars.ContextVar(",[138,267,269],{"class":268},"sZZnC","\"log_fields\"",[138,271,272],{"class":162},", ",[138,274,276],{"class":275},"s4XuR","default",[138,278,262],{"class":151},[138,280,281],{"class":162},"{})\n",[138,283,285],{"class":140,"line":284},13,[138,286,170],{"emptyLinePlaceholder":169},[138,288,290],{"class":140,"line":289},14,[138,291,170],{"emptyLinePlaceholder":169},[138,293,295,298,302,305,307],{"class":140,"line":294},15,[138,296,297],{"class":151},"def",[138,299,301],{"class":300},"sScJk"," new_run_id",[138,303,304],{"class":162},"() -> ",[138,306,256],{"class":155},[138,308,309],{"class":162},":\n",[138,311,313,316,319,322],{"class":140,"line":312},16,[138,314,315],{"class":151},"    return",[138,317,318],{"class":162}," uuid.uuid4().hex[:",[138,320,321],{"class":155},"12",[138,323,324],{"class":162},"]\n",[138,326,328],{"class":140,"line":327},17,[138,329,170],{"emptyLinePlaceholder":169},[138,331,333],{"class":140,"line":332},18,[138,334,170],{"emptyLinePlaceholder":169},[138,336,338,340,343,346,349,352,355],{"class":140,"line":337},19,[138,339,297],{"class":151},[138,341,342],{"class":300}," bind",[138,344,345],{"class":162},"(",[138,347,348],{"class":151},"**",[138,350,351],{"class":162},"fields: Any) -> ",[138,353,354],{"class":155},"None",[138,356,309],{"class":162},[138,358,360],{"class":140,"line":359},20,[138,361,362],{"class":268},"    \"\"\"Add fields to every log record for the rest of this context.\"\"\"\n",[138,364,366,369,371,374,376],{"class":140,"line":365},21,[138,367,368],{"class":162},"    _fields.set({",[138,370,348],{"class":151},[138,372,373],{"class":162},"_fields.get(), ",[138,375,348],{"class":151},[138,377,378],{"class":162},"fields})\n",[138,380,382],{"class":140,"line":381},22,[138,383,170],{"emptyLinePlaceholder":169},[138,385,387],{"class":140,"line":386},23,[138,388,170],{"emptyLinePlaceholder":169},[138,390,392],{"class":140,"line":391},24,[138,393,394],{"class":300},"@contextmanager\n",[138,396,398,400,403,405,407,410,412],{"class":140,"line":397},25,[138,399,297],{"class":151},[138,401,402],{"class":300}," bound",[138,404,345],{"class":162},[138,406,348],{"class":151},[138,408,409],{"class":162},"fields: Any) -> Iterator[",[138,411,354],{"class":155},[138,413,414],{"class":162},"]:\n",[138,416,418],{"class":140,"line":417},26,[138,419,420],{"class":268},"    \"\"\"Add fields for the duration of a block, e.g. one item of work.\"\"\"\n",[138,422,424,427,429,432,434,436,438],{"class":140,"line":423},27,[138,425,426],{"class":162},"    token ",[138,428,262],{"class":151},[138,430,431],{"class":162}," _fields.set({",[138,433,348],{"class":151},[138,435,373],{"class":162},[138,437,348],{"class":151},[138,439,378],{"class":162},[138,441,443,446],{"class":140,"line":442},28,[138,444,445],{"class":151},"    try",[138,447,309],{"class":162},[138,449,451],{"class":140,"line":450},29,[138,452,453],{"class":151},"        yield\n",[138,455,457,460],{"class":140,"line":456},30,[138,458,459],{"class":151},"    finally",[138,461,309],{"class":162},[138,463,465],{"class":140,"line":464},31,[138,466,467],{"class":162},"        _fields.reset(token)\n",[138,469,471],{"class":140,"line":470},32,[138,472,170],{"emptyLinePlaceholder":169},[138,474,476],{"class":140,"line":475},33,[138,477,170],{"emptyLinePlaceholder":169},[138,479,481,483,486,489,491],{"class":140,"line":480},34,[138,482,297],{"class":151},[138,484,485],{"class":300}," current",[138,487,488],{"class":162},"() -> dict[",[138,490,256],{"class":155},[138,492,493],{"class":162},", Any]:\n",[138,495,497,499,502],{"class":140,"line":496},35,[138,498,315],{"class":151},[138,500,501],{"class":155}," dict",[138,503,504],{"class":162},"(_fields.get())\n",[138,506,508],{"class":140,"line":507},36,[138,509,170],{"emptyLinePlaceholder":169},[138,511,513],{"class":140,"line":512},37,[138,514,170],{"emptyLinePlaceholder":169},[138,516,518,521,524,526,528,530,533],{"class":140,"line":517},38,[138,519,520],{"class":151},"class",[138,522,523],{"class":300}," ContextFilter",[138,525,345],{"class":162},[138,527,20],{"class":300},[138,529,27],{"class":162},[138,531,532],{"class":300},"Filter",[138,534,535],{"class":162},"):\n",[138,537,539],{"class":140,"line":538},39,[138,540,541],{"class":268},"    \"\"\"Copy the bound fields onto each record as attributes.\"\"\"\n",[138,543,545],{"class":140,"line":544},40,[138,546,170],{"emptyLinePlaceholder":169},[138,548,550,553,556,559,562],{"class":140,"line":549},41,[138,551,552],{"class":151},"    def",[138,554,555],{"class":155}," filter",[138,557,558],{"class":162},"(self, record: logging.LogRecord) -> ",[138,560,561],{"class":155},"bool",[138,563,309],{"class":162},[138,565,567,570,572],{"class":140,"line":566},42,[138,568,569],{"class":162},"        record.ctx ",[138,571,262],{"class":151},[138,573,574],{"class":162}," current()\n",[138,576,578,581],{"class":140,"line":577},43,[138,579,580],{"class":151},"        return",[138,582,583],{"class":155}," True\n",[138,585,587],{"class":140,"line":586},44,[138,588,170],{"emptyLinePlaceholder":169},[138,590,592],{"class":140,"line":591},45,[138,593,170],{"emptyLinePlaceholder":169},[138,595,597,599,602,604,606,608,611],{"class":140,"line":596},46,[138,598,520],{"class":151},[138,600,601],{"class":300}," JsonFormatter",[138,603,345],{"class":162},[138,605,20],{"class":300},[138,607,27],{"class":162},[138,609,610],{"class":300},"Formatter",[138,612,535],{"class":162},[138,614,616,618,621,623,625],{"class":140,"line":615},47,[138,617,552],{"class":151},[138,619,620],{"class":155}," format",[138,622,558],{"class":162},[138,624,256],{"class":155},[138,626,309],{"class":162},[138,628,630,633,635,638,641,644,647],{"class":140,"line":629},48,[138,631,632],{"class":162},"        event ",[138,634,262],{"class":151},[138,636,637],{"class":162}," {",[138,639,640],{"class":268},"\"level\"",[138,642,643],{"class":162},": record.levelname.lower(), ",[138,645,646],{"class":268},"\"msg\"",[138,648,649],{"class":162},": record.getMessage(),\n",[138,651,653,656,659,661,664,667,670],{"class":140,"line":652},49,[138,654,655],{"class":268},"                 \"logger\"",[138,657,658],{"class":162},": record.name, ",[138,660,348],{"class":151},[138,662,663],{"class":155},"getattr",[138,665,666],{"class":162},"(record, ",[138,668,669],{"class":268},"\"ctx\"",[138,671,672],{"class":162},", {})}\n",[138,674,676,679],{"class":140,"line":675},50,[138,677,678],{"class":151},"        if",[138,680,681],{"class":162}," record.exc_info:\n",[138,683,685,688,691,694,696,699],{"class":140,"line":684},51,[138,686,687],{"class":162},"            event[",[138,689,690],{"class":268},"\"exc\"",[138,692,693],{"class":162},"] ",[138,695,262],{"class":151},[138,697,698],{"class":155}," self",[138,700,701],{"class":162},".formatException(record.exc_info)\n",[138,703,705,707,710,712,714,716],{"class":140,"line":704},52,[138,706,580],{"class":151},[138,708,709],{"class":162}," json.dumps(event, ",[138,711,276],{"class":275},[138,713,262],{"class":151},[138,715,256],{"class":155},[138,717,718],{"class":162},")\n",[138,720,722],{"class":140,"line":721},53,[138,723,170],{"emptyLinePlaceholder":169},[138,725,727],{"class":140,"line":726},54,[138,728,170],{"emptyLinePlaceholder":169},[138,730,732,734,737,739,741,743,745],{"class":140,"line":731},55,[138,733,520],{"class":151},[138,735,736],{"class":300}," TextFormatter",[138,738,345],{"class":162},[138,740,20],{"class":300},[138,742,27],{"class":162},[138,744,610],{"class":300},[138,746,535],{"class":162},[138,748,750,752,754,756,758],{"class":140,"line":749},56,[138,751,552],{"class":151},[138,753,620],{"class":155},[138,755,558],{"class":162},[138,757,256],{"class":155},[138,759,309],{"class":162},[138,761,763,766,768,771,774,777,780,783,786,789,791,793,796,798,800,803,806,809,812,814,816],{"class":140,"line":762},57,[138,764,765],{"class":162},"        ctx ",[138,767,262],{"class":151},[138,769,770],{"class":268}," \" \"",[138,772,773],{"class":162},".join(",[138,775,776],{"class":151},"f",[138,778,779],{"class":268},"\"",[138,781,782],{"class":155},"{",[138,784,785],{"class":162},"k",[138,787,788],{"class":155},"}",[138,790,262],{"class":268},[138,792,782],{"class":155},[138,794,795],{"class":162},"v",[138,797,788],{"class":155},[138,799,779],{"class":268},[138,801,802],{"class":151}," for",[138,804,805],{"class":162}," k, v ",[138,807,808],{"class":151},"in",[138,810,811],{"class":155}," getattr",[138,813,666],{"class":162},[138,815,669],{"class":268},[138,817,818],{"class":162},", {}).items())\n",[138,820,822,824,827,829,831,834,837,839,841,844,846,849,852,854,856],{"class":140,"line":821},58,[138,823,580],{"class":151},[138,825,826],{"class":151}," f",[138,828,779],{"class":268},[138,830,782],{"class":155},[138,832,833],{"class":162},"record.levelname",[138,835,836],{"class":151},":\u003C7",[138,838,788],{"class":155},[138,840,637],{"class":155},[138,842,843],{"class":162},"record.getMessage()",[138,845,788],{"class":155},[138,847,848],{"class":155},"  {",[138,850,851],{"class":162},"ctx",[138,853,788],{"class":155},[138,855,779],{"class":268},[138,857,858],{"class":162},".rstrip()\n",[10,860,861],{},"The CLI binds the run-level fields once, in the callback that runs before every command, and binds the item inside the unit of work:",[129,863,865],{"className":131,"code":864,"language":133,"meta":134,"style":134},"# src\u002Fmytool\u002Fcli.py\nfrom __future__ import annotations\n\nimport logging\nimport sys\nfrom concurrent.futures import ThreadPoolExecutor\nfrom contextvars import copy_context\nfrom importlib.metadata import PackageNotFoundError, version\n\nimport typer\n\nfrom mytool.context import ContextFilter, JsonFormatter, TextFormatter, bind, bound, current, new_run_id\n\napp = typer.Typer()\nlog = logging.getLogger(\"mytool\")\n\ntry:\n    VERSION = version(\"mytool\")\nexcept PackageNotFoundError:\n    VERSION = \"dev\"\n\n\ndef setup_logging(json_logs: bool) -> None:\n    handler = logging.StreamHandler(sys.stderr)\n    handler.addFilter(ContextFilter())\n    handler.setFormatter(JsonFormatter() if json_logs else TextFormatter())\n    root = logging.getLogger()\n    root.handlers[:] = [handler]\n    root.setLevel(logging.INFO)\n\n\ndef upload(name: str) -> None:\n    with bound(item=name):\n        if name.startswith(\"b\"):\n            log.error(\"upload failed\")\n        else:\n            log.info(\"uploaded\")\n\n\n@app.callback()\ndef main(ctx: typer.Context, json_logs: bool = typer.Option(False, \"--json-logs\")) -> None:\n    \"\"\"Sync tool with correlated logs.\"\"\"\n    setup_logging(json_logs)\n    bind(run_id=new_run_id(), version=VERSION, command=ctx.invoked_subcommand)\n\n\n@app.command()\ndef sync(items: list[str]) -> None:\n    \"\"\"Upload ITEMS in parallel.\"\"\"\n    log.info(\"sync started\")\n    with ThreadPoolExecutor(max_workers=4) as pool:\n        # Threads do not inherit context variables: run each task in a copy of ours.\n        futures = [pool.submit(copy_context().run, upload, item) for item in items]\n        for f in futures:\n            f.result()\n    log.info(\"sync finished\")\n    typer.echo(f\"run {current()['run_id']} done\", err=True)\n\n\ndef request_headers() -> dict[str, str]:\n    \"\"\"Send the run ID to APIs so their logs can be joined with ours.\"\"\"\n    return {\"X-Request-ID\": current().get(\"run_id\", \"\")}\n",[14,866,867,872,882,886,892,899,911,923,935,939,946,950,962,966,976,991,995,1002,1017,1025,1034,1038,1042,1061,1071,1076,1093,1103,1113,1123,1127,1131,1149,1164,1176,1186,1193,1203,1207,1211,1219,1251,1256,1261,1289,1293,1297,1304,1323,1328,1338,1362,1367,1388,1401,1406,1415,1453,1457,1462,1480,1486],{"__ignoreMap":134},[138,868,869],{"class":140,"line":141},[138,870,871],{"class":144},"# src\u002Fmytool\u002Fcli.py\n",[138,873,874,876,878,880],{"class":140,"line":148},[138,875,152],{"class":151},[138,877,156],{"class":155},[138,879,159],{"class":151},[138,881,163],{"class":162},[138,883,884],{"class":140,"line":166},[138,885,170],{"emptyLinePlaceholder":169},[138,887,888,890],{"class":140,"line":173},[138,889,176],{"class":151},[138,891,195],{"class":162},[138,893,894,896],{"class":140,"line":182},[138,895,176],{"class":151},[138,897,898],{"class":162}," sys\n",[138,900,901,903,906,908],{"class":140,"line":190},[138,902,152],{"class":151},[138,904,905],{"class":162}," concurrent.futures ",[138,907,176],{"class":151},[138,909,910],{"class":162}," ThreadPoolExecutor\n",[138,912,913,915,918,920],{"class":140,"line":198},[138,914,152],{"class":151},[138,916,917],{"class":162}," contextvars ",[138,919,176],{"class":151},[138,921,922],{"class":162}," copy_context\n",[138,924,925,927,930,932],{"class":140,"line":206},[138,926,152],{"class":151},[138,928,929],{"class":162}," importlib.metadata ",[138,931,176],{"class":151},[138,933,934],{"class":162}," PackageNotFoundError, version\n",[138,936,937],{"class":140,"line":219},[138,938,170],{"emptyLinePlaceholder":169},[138,940,941,943],{"class":140,"line":232},[138,942,176],{"class":151},[138,944,945],{"class":162}," typer\n",[138,947,948],{"class":140,"line":245},[138,949,170],{"emptyLinePlaceholder":169},[138,951,952,954,957,959],{"class":140,"line":250},[138,953,152],{"class":151},[138,955,956],{"class":162}," mytool.context ",[138,958,176],{"class":151},[138,960,961],{"class":162}," ContextFilter, JsonFormatter, TextFormatter, bind, bound, current, new_run_id\n",[138,963,964],{"class":140,"line":284},[138,965,170],{"emptyLinePlaceholder":169},[138,967,968,971,973],{"class":140,"line":289},[138,969,970],{"class":162},"app ",[138,972,262],{"class":151},[138,974,975],{"class":162}," typer.Typer()\n",[138,977,978,981,983,986,989],{"class":140,"line":294},[138,979,980],{"class":162},"log ",[138,982,262],{"class":151},[138,984,985],{"class":162}," logging.getLogger(",[138,987,988],{"class":268},"\"mytool\"",[138,990,718],{"class":162},[138,992,993],{"class":140,"line":312},[138,994,170],{"emptyLinePlaceholder":169},[138,996,997,1000],{"class":140,"line":327},[138,998,999],{"class":151},"try",[138,1001,309],{"class":162},[138,1003,1004,1007,1010,1013,1015],{"class":140,"line":332},[138,1005,1006],{"class":155},"    VERSION",[138,1008,1009],{"class":151}," =",[138,1011,1012],{"class":162}," version(",[138,1014,988],{"class":268},[138,1016,718],{"class":162},[138,1018,1019,1022],{"class":140,"line":337},[138,1020,1021],{"class":151},"except",[138,1023,1024],{"class":162}," PackageNotFoundError:\n",[138,1026,1027,1029,1031],{"class":140,"line":359},[138,1028,1006],{"class":155},[138,1030,1009],{"class":151},[138,1032,1033],{"class":268}," \"dev\"\n",[138,1035,1036],{"class":140,"line":365},[138,1037,170],{"emptyLinePlaceholder":169},[138,1039,1040],{"class":140,"line":381},[138,1041,170],{"emptyLinePlaceholder":169},[138,1043,1044,1046,1049,1052,1054,1057,1059],{"class":140,"line":386},[138,1045,297],{"class":151},[138,1047,1048],{"class":300}," setup_logging",[138,1050,1051],{"class":162},"(json_logs: ",[138,1053,561],{"class":155},[138,1055,1056],{"class":162},") -> ",[138,1058,354],{"class":155},[138,1060,309],{"class":162},[138,1062,1063,1066,1068],{"class":140,"line":391},[138,1064,1065],{"class":162},"    handler ",[138,1067,262],{"class":151},[138,1069,1070],{"class":162}," logging.StreamHandler(sys.stderr)\n",[138,1072,1073],{"class":140,"line":397},[138,1074,1075],{"class":162},"    handler.addFilter(ContextFilter())\n",[138,1077,1078,1081,1084,1087,1090],{"class":140,"line":417},[138,1079,1080],{"class":162},"    handler.setFormatter(JsonFormatter() ",[138,1082,1083],{"class":151},"if",[138,1085,1086],{"class":162}," json_logs ",[138,1088,1089],{"class":151},"else",[138,1091,1092],{"class":162}," TextFormatter())\n",[138,1094,1095,1098,1100],{"class":140,"line":423},[138,1096,1097],{"class":162},"    root ",[138,1099,262],{"class":151},[138,1101,1102],{"class":162}," logging.getLogger()\n",[138,1104,1105,1108,1110],{"class":140,"line":442},[138,1106,1107],{"class":162},"    root.handlers[:] ",[138,1109,262],{"class":151},[138,1111,1112],{"class":162}," [handler]\n",[138,1114,1115,1118,1121],{"class":140,"line":450},[138,1116,1117],{"class":162},"    root.setLevel(logging.",[138,1119,1120],{"class":155},"INFO",[138,1122,718],{"class":162},[138,1124,1125],{"class":140,"line":456},[138,1126,170],{"emptyLinePlaceholder":169},[138,1128,1129],{"class":140,"line":464},[138,1130,170],{"emptyLinePlaceholder":169},[138,1132,1133,1135,1138,1141,1143,1145,1147],{"class":140,"line":470},[138,1134,297],{"class":151},[138,1136,1137],{"class":300}," upload",[138,1139,1140],{"class":162},"(name: ",[138,1142,256],{"class":155},[138,1144,1056],{"class":162},[138,1146,354],{"class":155},[138,1148,309],{"class":162},[138,1150,1151,1154,1157,1159,1161],{"class":140,"line":475},[138,1152,1153],{"class":151},"    with",[138,1155,1156],{"class":162}," bound(",[138,1158,107],{"class":275},[138,1160,262],{"class":151},[138,1162,1163],{"class":162},"name):\n",[138,1165,1166,1168,1171,1174],{"class":140,"line":480},[138,1167,678],{"class":151},[138,1169,1170],{"class":162}," name.startswith(",[138,1172,1173],{"class":268},"\"b\"",[138,1175,535],{"class":162},[138,1177,1178,1181,1184],{"class":140,"line":496},[138,1179,1180],{"class":162},"            log.error(",[138,1182,1183],{"class":268},"\"upload failed\"",[138,1185,718],{"class":162},[138,1187,1188,1191],{"class":140,"line":507},[138,1189,1190],{"class":151},"        else",[138,1192,309],{"class":162},[138,1194,1195,1198,1201],{"class":140,"line":512},[138,1196,1197],{"class":162},"            log.info(",[138,1199,1200],{"class":268},"\"uploaded\"",[138,1202,718],{"class":162},[138,1204,1205],{"class":140,"line":517},[138,1206,170],{"emptyLinePlaceholder":169},[138,1208,1209],{"class":140,"line":538},[138,1210,170],{"emptyLinePlaceholder":169},[138,1212,1213,1216],{"class":140,"line":544},[138,1214,1215],{"class":300},"@app.callback",[138,1217,1218],{"class":162},"()\n",[138,1220,1221,1223,1226,1229,1231,1233,1236,1239,1241,1244,1247,1249],{"class":140,"line":549},[138,1222,297],{"class":151},[138,1224,1225],{"class":300}," main",[138,1227,1228],{"class":162},"(ctx: typer.Context, json_logs: ",[138,1230,561],{"class":155},[138,1232,1009],{"class":151},[138,1234,1235],{"class":162}," typer.Option(",[138,1237,1238],{"class":155},"False",[138,1240,272],{"class":162},[138,1242,1243],{"class":268},"\"--json-logs\"",[138,1245,1246],{"class":162},")) -> ",[138,1248,354],{"class":155},[138,1250,309],{"class":162},[138,1252,1253],{"class":140,"line":566},[138,1254,1255],{"class":268},"    \"\"\"Sync tool with correlated logs.\"\"\"\n",[138,1257,1258],{"class":140,"line":577},[138,1259,1260],{"class":162},"    setup_logging(json_logs)\n",[138,1262,1263,1266,1268,1270,1273,1275,1277,1280,1282,1284,1286],{"class":140,"line":586},[138,1264,1265],{"class":162},"    bind(",[138,1267,95],{"class":275},[138,1269,262],{"class":151},[138,1271,1272],{"class":162},"new_run_id(), ",[138,1274,103],{"class":275},[138,1276,262],{"class":151},[138,1278,1279],{"class":155},"VERSION",[138,1281,272],{"class":162},[138,1283,99],{"class":275},[138,1285,262],{"class":151},[138,1287,1288],{"class":162},"ctx.invoked_subcommand)\n",[138,1290,1291],{"class":140,"line":591},[138,1292,170],{"emptyLinePlaceholder":169},[138,1294,1295],{"class":140,"line":596},[138,1296,170],{"emptyLinePlaceholder":169},[138,1298,1299,1302],{"class":140,"line":615},[138,1300,1301],{"class":300},"@app.command",[138,1303,1218],{"class":162},[138,1305,1306,1308,1311,1314,1316,1319,1321],{"class":140,"line":629},[138,1307,297],{"class":151},[138,1309,1310],{"class":300}," sync",[138,1312,1313],{"class":162},"(items: list[",[138,1315,256],{"class":155},[138,1317,1318],{"class":162},"]) -> ",[138,1320,354],{"class":155},[138,1322,309],{"class":162},[138,1324,1325],{"class":140,"line":652},[138,1326,1327],{"class":268},"    \"\"\"Upload ITEMS in parallel.\"\"\"\n",[138,1329,1330,1333,1336],{"class":140,"line":675},[138,1331,1332],{"class":162},"    log.info(",[138,1334,1335],{"class":268},"\"sync started\"",[138,1337,718],{"class":162},[138,1339,1340,1342,1345,1348,1350,1353,1356,1359],{"class":140,"line":684},[138,1341,1153],{"class":151},[138,1343,1344],{"class":162}," ThreadPoolExecutor(",[138,1346,1347],{"class":275},"max_workers",[138,1349,262],{"class":151},[138,1351,1352],{"class":155},"4",[138,1354,1355],{"class":162},") ",[138,1357,1358],{"class":151},"as",[138,1360,1361],{"class":162}," pool:\n",[138,1363,1364],{"class":140,"line":704},[138,1365,1366],{"class":144},"        # Threads do not inherit context variables: run each task in a copy of ours.\n",[138,1368,1369,1372,1374,1377,1380,1383,1385],{"class":140,"line":721},[138,1370,1371],{"class":162},"        futures ",[138,1373,262],{"class":151},[138,1375,1376],{"class":162}," [pool.submit(copy_context().run, upload, item) ",[138,1378,1379],{"class":151},"for",[138,1381,1382],{"class":162}," item ",[138,1384,808],{"class":151},[138,1386,1387],{"class":162}," items]\n",[138,1389,1390,1393,1396,1398],{"class":140,"line":726},[138,1391,1392],{"class":151},"        for",[138,1394,1395],{"class":162}," f ",[138,1397,808],{"class":151},[138,1399,1400],{"class":162}," futures:\n",[138,1402,1403],{"class":140,"line":731},[138,1404,1405],{"class":162},"            f.result()\n",[138,1407,1408,1410,1413],{"class":140,"line":749},[138,1409,1332],{"class":162},[138,1411,1412],{"class":268},"\"sync finished\"",[138,1414,718],{"class":162},[138,1416,1417,1420,1422,1425,1427,1430,1433,1436,1438,1441,1443,1446,1448,1451],{"class":140,"line":762},[138,1418,1419],{"class":162},"    typer.echo(",[138,1421,776],{"class":151},[138,1423,1424],{"class":268},"\"run ",[138,1426,782],{"class":155},[138,1428,1429],{"class":162},"current()[",[138,1431,1432],{"class":268},"'run_id'",[138,1434,1435],{"class":162},"]",[138,1437,788],{"class":155},[138,1439,1440],{"class":268}," done\"",[138,1442,272],{"class":162},[138,1444,1445],{"class":275},"err",[138,1447,262],{"class":151},[138,1449,1450],{"class":155},"True",[138,1452,718],{"class":162},[138,1454,1455],{"class":140,"line":821},[138,1456,170],{"emptyLinePlaceholder":169},[138,1458,1460],{"class":140,"line":1459},59,[138,1461,170],{"emptyLinePlaceholder":169},[138,1463,1465,1467,1470,1472,1474,1476,1478],{"class":140,"line":1464},60,[138,1466,297],{"class":151},[138,1468,1469],{"class":300}," request_headers",[138,1471,488],{"class":162},[138,1473,256],{"class":155},[138,1475,272],{"class":162},[138,1477,256],{"class":155},[138,1479,414],{"class":162},[138,1481,1483],{"class":140,"line":1482},61,[138,1484,1485],{"class":268},"    \"\"\"Send the run ID to APIs so their logs can be joined with ours.\"\"\"\n",[138,1487,1489,1491,1493,1496,1499,1502,1504,1507],{"class":140,"line":1488},62,[138,1490,315],{"class":151},[138,1492,637],{"class":162},[138,1494,1495],{"class":268},"\"X-Request-ID\"",[138,1497,1498],{"class":162},": current().get(",[138,1500,1501],{"class":268},"\"run_id\"",[138,1503,272],{"class":162},[138,1505,1506],{"class":268},"\"\"",[138,1508,1509],{"class":162},")}\n",[10,1511,1512,1513,1516],{},"Running ",[14,1514,1515],{},"mytool --json-logs sync a.csv b.csv"," produces lines that can be grouped and filtered with any log tool:",[60,1518],{"name":1519},"tr-terminal",[1521,1522,1524],"h3",{"id":1523},"why-it-is-built-this-way","Why it is built this way",[10,1526,1527,1530,1531,1534,1535,1538,1539,1541,1542,1544],{},[67,1528,1529],{},"Context variables, not globals."," A module-level dictionary would work for a single-threaded command, but context variables are what ",[14,1532,1533],{},"asyncio"," tasks and ",[14,1536,1537],{},"copy_context()"," understand. Each task sees its own ",[14,1540,107],{},", while all of them share the run's ",[14,1543,95],{},", and nothing needs to pass a logger adapter through every function signature.",[10,1546,1547,1550],{},[67,1548,1549],{},"The filter goes on the handler."," A filter attached to the handler sees every record that reaches it, including records from libraries' loggers that propagate to the root. Attaching it to your own logger only would leave third-party lines without a run ID — exactly the lines you need when a library is misbehaving.",[10,1552,1553,1556,1557,1560,1561,1564,1565,1567,1568,1572],{},[67,1554,1555],{},"Copy the context into threads."," ",[14,1558,1559],{},"ThreadPoolExecutor"," does not carry the submitting thread's context variables into worker threads by default. Wrapping each task in ",[14,1562,1563],{},"copy_context().run"," gives the worker a snapshot of the current fields; any ",[14,1566,126],{}," inside the worker affects only that copy. The same concern appears in ",[23,1569,1571],{"href":1570},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fparallelising-cli-work-with-thread-pools\u002F","parallelising CLI work with thread pools",". Asyncio tasks copy the context automatically when they are created.",[10,1574,1575,1578,1579,1582],{},[67,1576,1577],{},"The ID is short and printed once."," Twelve hex characters are unique enough for correlating one user's runs and short enough to read aloud. Printing it at the end (on stderr, so pipelines stay clean) gives the user something to quote: \"run ",[14,1580,1581],{},"76c4371f9fea"," failed\".",[29,1584,1586],{"id":1585},"sending-the-id-to-apis","Sending the ID to APIs",[10,1588,1589,1590,1592],{},"The run ID becomes much more useful when the server logs it too. With ",[14,1591,53],{},", an event hook adds the header to every request the client makes, so no call site can forget it:",[129,1594,1596],{"className":131,"code":1595,"language":133,"meta":134,"style":134},"import httpx\n\nfrom mytool.context import current\n\n\ndef add_request_id(request: httpx.Request) -> None:\n    request.headers.setdefault(\"X-Request-ID\", current().get(\"run_id\", \"\"))\n\n\nclient = httpx.Client(base_url=\"https:\u002F\u002Fapi.example.com\", event_hooks={\"request\": [add_request_id]})\n",[14,1597,1598,1605,1609,1620,1624,1628,1642,1661,1665,1669],{"__ignoreMap":134},[138,1599,1600,1602],{"class":140,"line":141},[138,1601,176],{"class":151},[138,1603,1604],{"class":162}," httpx\n",[138,1606,1607],{"class":140,"line":148},[138,1608,170],{"emptyLinePlaceholder":169},[138,1610,1611,1613,1615,1617],{"class":140,"line":166},[138,1612,152],{"class":151},[138,1614,956],{"class":162},[138,1616,176],{"class":151},[138,1618,1619],{"class":162}," current\n",[138,1621,1622],{"class":140,"line":173},[138,1623,170],{"emptyLinePlaceholder":169},[138,1625,1626],{"class":140,"line":182},[138,1627,170],{"emptyLinePlaceholder":169},[138,1629,1630,1632,1635,1638,1640],{"class":140,"line":190},[138,1631,297],{"class":151},[138,1633,1634],{"class":300}," add_request_id",[138,1636,1637],{"class":162},"(request: httpx.Request) -> ",[138,1639,354],{"class":155},[138,1641,309],{"class":162},[138,1643,1644,1647,1649,1652,1654,1656,1658],{"class":140,"line":198},[138,1645,1646],{"class":162},"    request.headers.setdefault(",[138,1648,1495],{"class":268},[138,1650,1651],{"class":162},", current().get(",[138,1653,1501],{"class":268},[138,1655,272],{"class":162},[138,1657,1506],{"class":268},[138,1659,1660],{"class":162},"))\n",[138,1662,1663],{"class":140,"line":206},[138,1664,170],{"emptyLinePlaceholder":169},[138,1666,1667],{"class":140,"line":219},[138,1668,170],{"emptyLinePlaceholder":169},[138,1670,1671,1674,1676,1679,1682,1684,1687,1689,1692,1694,1696,1699],{"class":140,"line":232},[138,1672,1673],{"class":162},"client ",[138,1675,262],{"class":151},[138,1677,1678],{"class":162}," httpx.Client(",[138,1680,1681],{"class":275},"base_url",[138,1683,262],{"class":151},[138,1685,1686],{"class":268},"\"https:\u002F\u002Fapi.example.com\"",[138,1688,272],{"class":162},[138,1690,1691],{"class":275},"event_hooks",[138,1693,262],{"class":151},[138,1695,782],{"class":162},[138,1697,1698],{"class":268},"\"request\"",[138,1700,1701],{"class":162},": [add_request_id]})\n",[10,1703,1704,1707,1708,1711,1712,27],{},[14,1705,1706],{},"X-Request-ID"," is the de facto header most proxies and frameworks recognise; if your platform uses W3C trace context (",[14,1709,1710],{},"traceparent","), send that instead, generated from the same run ID. The client setup this plugs into is described in ",[23,1713,1715],{"href":1714},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fbuilding-an-api-client-cli-with-httpx\u002F","building an API client CLI with httpx",[29,1717,1719],{"id":1718},"ux-considerations","UX considerations",[34,1721,1722,1737,1743,1754],{},[37,1723,1724,1727,1728,1731,1732,1736],{},[67,1725,1726],{},"Show the ID when it helps."," Print it in error messages (\"error: upload failed (run 76c4371f9fea)\") and in the ",[14,1729,1730],{},"--verbose"," footer, not on every successful run. Combined with ",[23,1733,1735],{"href":1734},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Ffriendly-error-messages-and-tracebacks\u002F","friendly error messages and tracebacks",", it turns a vague report into a searchable one.",[37,1738,1739,1742],{},[67,1740,1741],{},"Keep text mode readable."," Human-readable output puts context after the message, so the message stays the first thing the eye reads; JSON mode puts everything in fields for machines.",[37,1744,1745,1748,1749,1753],{},[67,1746,1747],{},"Never bind secrets."," Context fields end up in every line, so a token bound by mistake is copied thousands of times. Bind identifiers, not credentials, and keep the rules from ",[23,1750,1752],{"href":1751},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fredacting-secrets-from-cli-output-and-logs\u002F","redacting secrets from CLI output and logs"," in mind.",[37,1755,1756,1759,1760,1763],{},[67,1757,1758],{},"Accept an ID from outside."," When a CI job or a wrapper script already has a correlation ID, let ",[14,1761,1762],{},"MYTOOL_RUN_ID"," override the generated one so the CLI's lines join the caller's.",[29,1765,1767],{"id":1766},"testing-the-behaviour","Testing the behaviour",[10,1769,1770],{},"Tests parse the JSON output and check that every record from one run has the same ID, that the command is recorded, and that the failing line names its item:",[129,1772,1774],{"className":131,"code":1773,"language":133,"meta":134,"style":134},"# tests\u002Ftest_context.py\nimport contextvars\nimport json\n\nfrom typer.testing import CliRunner\n\nfrom mytool.cli import app\nfrom mytool.context import bind, bound, current\n\nrunner = CliRunner()\n\n\ndef test_every_record_carries_the_run_id():\n    result = runner.invoke(app, [\"--json-logs\", \"sync\", \"a.csv\", \"b.csv\", \"c.csv\"])\n    events = [json.loads(line) for line in result.output.splitlines() if line.startswith(\"{\")]\n    run_ids = {e[\"run_id\"] for e in events}\n    assert len(run_ids) == 1 and len(events) == 5\n    assert all(e[\"command\"] == \"sync\" for e in events)\n    failed = [e for e in events if e[\"level\"] == \"error\"]\n    assert failed == [{**failed[0], \"item\": \"b.csv\"}]\n\n\ndef test_bound_fields_are_scoped():\n    def body():\n        bind(run_id=\"r1\")\n        with bound(item=\"x\"):\n            assert current() == {\"run_id\": \"r1\", \"item\": \"x\"}\n        assert current() == {\"run_id\": \"r1\"}\n    contextvars.Context().run(body)      # a fresh, empty context: no leakage between tests\n\n\ndef test_text_format_is_readable():\n    result = runner.invoke(app, [\"sync\", \"a.csv\"])\n    assert \"uploaded  run_id=\" in result.output and \"item=a.csv\" in result.output\n",[14,1775,1776,1781,1787,1793,1797,1809,1813,1825,1836,1840,1850,1854,1858,1868,1903,1934,1958,1988,2017,2052,2086,2090,2094,2103,2112,2126,2142,2171,2190,2198,2202,2206,2215,2231],{"__ignoreMap":134},[138,1777,1778],{"class":140,"line":141},[138,1779,1780],{"class":144},"# tests\u002Ftest_context.py\n",[138,1782,1783,1785],{"class":140,"line":148},[138,1784,176],{"class":151},[138,1786,179],{"class":162},[138,1788,1789,1791],{"class":140,"line":166},[138,1790,176],{"class":151},[138,1792,187],{"class":162},[138,1794,1795],{"class":140,"line":173},[138,1796,170],{"emptyLinePlaceholder":169},[138,1798,1799,1801,1804,1806],{"class":140,"line":182},[138,1800,152],{"class":151},[138,1802,1803],{"class":162}," typer.testing ",[138,1805,176],{"class":151},[138,1807,1808],{"class":162}," CliRunner\n",[138,1810,1811],{"class":140,"line":190},[138,1812,170],{"emptyLinePlaceholder":169},[138,1814,1815,1817,1820,1822],{"class":140,"line":198},[138,1816,152],{"class":151},[138,1818,1819],{"class":162}," mytool.cli ",[138,1821,176],{"class":151},[138,1823,1824],{"class":162}," app\n",[138,1826,1827,1829,1831,1833],{"class":140,"line":206},[138,1828,152],{"class":151},[138,1830,956],{"class":162},[138,1832,176],{"class":151},[138,1834,1835],{"class":162}," bind, bound, current\n",[138,1837,1838],{"class":140,"line":219},[138,1839,170],{"emptyLinePlaceholder":169},[138,1841,1842,1845,1847],{"class":140,"line":232},[138,1843,1844],{"class":162},"runner ",[138,1846,262],{"class":151},[138,1848,1849],{"class":162}," CliRunner()\n",[138,1851,1852],{"class":140,"line":245},[138,1853,170],{"emptyLinePlaceholder":169},[138,1855,1856],{"class":140,"line":250},[138,1857,170],{"emptyLinePlaceholder":169},[138,1859,1860,1862,1865],{"class":140,"line":284},[138,1861,297],{"class":151},[138,1863,1864],{"class":300}," test_every_record_carries_the_run_id",[138,1866,1867],{"class":162},"():\n",[138,1869,1870,1873,1875,1878,1880,1882,1885,1887,1890,1892,1895,1897,1900],{"class":140,"line":289},[138,1871,1872],{"class":162},"    result ",[138,1874,262],{"class":151},[138,1876,1877],{"class":162}," runner.invoke(app, [",[138,1879,1243],{"class":268},[138,1881,272],{"class":162},[138,1883,1884],{"class":268},"\"sync\"",[138,1886,272],{"class":162},[138,1888,1889],{"class":268},"\"a.csv\"",[138,1891,272],{"class":162},[138,1893,1894],{"class":268},"\"b.csv\"",[138,1896,272],{"class":162},[138,1898,1899],{"class":268},"\"c.csv\"",[138,1901,1902],{"class":162},"])\n",[138,1904,1905,1908,1910,1913,1915,1918,1920,1923,1925,1928,1931],{"class":140,"line":294},[138,1906,1907],{"class":162},"    events ",[138,1909,262],{"class":151},[138,1911,1912],{"class":162}," [json.loads(line) ",[138,1914,1379],{"class":151},[138,1916,1917],{"class":162}," line ",[138,1919,808],{"class":151},[138,1921,1922],{"class":162}," result.output.splitlines() ",[138,1924,1083],{"class":151},[138,1926,1927],{"class":162}," line.startswith(",[138,1929,1930],{"class":268},"\"{\"",[138,1932,1933],{"class":162},")]\n",[138,1935,1936,1939,1941,1944,1946,1948,1950,1953,1955],{"class":140,"line":312},[138,1937,1938],{"class":162},"    run_ids ",[138,1940,262],{"class":151},[138,1942,1943],{"class":162}," {e[",[138,1945,1501],{"class":268},[138,1947,693],{"class":162},[138,1949,1379],{"class":151},[138,1951,1952],{"class":162}," e ",[138,1954,808],{"class":151},[138,1956,1957],{"class":162}," events}\n",[138,1959,1960,1963,1966,1969,1972,1975,1978,1980,1983,1985],{"class":140,"line":327},[138,1961,1962],{"class":151},"    assert",[138,1964,1965],{"class":155}," len",[138,1967,1968],{"class":162},"(run_ids) ",[138,1970,1971],{"class":151},"==",[138,1973,1974],{"class":155}," 1",[138,1976,1977],{"class":151}," and",[138,1979,1965],{"class":155},[138,1981,1982],{"class":162},"(events) ",[138,1984,1971],{"class":151},[138,1986,1987],{"class":155}," 5\n",[138,1989,1990,1992,1995,1998,2001,2003,2005,2008,2010,2012,2014],{"class":140,"line":332},[138,1991,1962],{"class":151},[138,1993,1994],{"class":155}," all",[138,1996,1997],{"class":162},"(e[",[138,1999,2000],{"class":268},"\"command\"",[138,2002,693],{"class":162},[138,2004,1971],{"class":151},[138,2006,2007],{"class":268}," \"sync\"",[138,2009,802],{"class":151},[138,2011,1952],{"class":162},[138,2013,808],{"class":151},[138,2015,2016],{"class":162}," events)\n",[138,2018,2019,2022,2024,2027,2029,2031,2033,2036,2038,2041,2043,2045,2047,2050],{"class":140,"line":337},[138,2020,2021],{"class":162},"    failed ",[138,2023,262],{"class":151},[138,2025,2026],{"class":162}," [e ",[138,2028,1379],{"class":151},[138,2030,1952],{"class":162},[138,2032,808],{"class":151},[138,2034,2035],{"class":162}," events ",[138,2037,1083],{"class":151},[138,2039,2040],{"class":162}," e[",[138,2042,640],{"class":268},[138,2044,693],{"class":162},[138,2046,1971],{"class":151},[138,2048,2049],{"class":268}," \"error\"",[138,2051,324],{"class":162},[138,2053,2054,2056,2059,2061,2064,2066,2069,2072,2075,2078,2081,2083],{"class":140,"line":359},[138,2055,1962],{"class":151},[138,2057,2058],{"class":162}," failed ",[138,2060,1971],{"class":151},[138,2062,2063],{"class":162}," [{",[138,2065,348],{"class":151},[138,2067,2068],{"class":162},"failed[",[138,2070,2071],{"class":155},"0",[138,2073,2074],{"class":162},"], ",[138,2076,2077],{"class":268},"\"item\"",[138,2079,2080],{"class":162},": ",[138,2082,1894],{"class":268},[138,2084,2085],{"class":162},"}]\n",[138,2087,2088],{"class":140,"line":365},[138,2089,170],{"emptyLinePlaceholder":169},[138,2091,2092],{"class":140,"line":381},[138,2093,170],{"emptyLinePlaceholder":169},[138,2095,2096,2098,2101],{"class":140,"line":386},[138,2097,297],{"class":151},[138,2099,2100],{"class":300}," test_bound_fields_are_scoped",[138,2102,1867],{"class":162},[138,2104,2105,2107,2110],{"class":140,"line":391},[138,2106,552],{"class":151},[138,2108,2109],{"class":300}," body",[138,2111,1867],{"class":162},[138,2113,2114,2117,2119,2121,2124],{"class":140,"line":397},[138,2115,2116],{"class":162},"        bind(",[138,2118,95],{"class":275},[138,2120,262],{"class":151},[138,2122,2123],{"class":268},"\"r1\"",[138,2125,718],{"class":162},[138,2127,2128,2131,2133,2135,2137,2140],{"class":140,"line":417},[138,2129,2130],{"class":151},"        with",[138,2132,1156],{"class":162},[138,2134,107],{"class":275},[138,2136,262],{"class":151},[138,2138,2139],{"class":268},"\"x\"",[138,2141,535],{"class":162},[138,2143,2144,2147,2150,2152,2154,2156,2158,2160,2162,2164,2166,2168],{"class":140,"line":423},[138,2145,2146],{"class":151},"            assert",[138,2148,2149],{"class":162}," current() ",[138,2151,1971],{"class":151},[138,2153,637],{"class":162},[138,2155,1501],{"class":268},[138,2157,2080],{"class":162},[138,2159,2123],{"class":268},[138,2161,272],{"class":162},[138,2163,2077],{"class":268},[138,2165,2080],{"class":162},[138,2167,2139],{"class":268},[138,2169,2170],{"class":162},"}\n",[138,2172,2173,2176,2178,2180,2182,2184,2186,2188],{"class":140,"line":442},[138,2174,2175],{"class":151},"        assert",[138,2177,2149],{"class":162},[138,2179,1971],{"class":151},[138,2181,637],{"class":162},[138,2183,1501],{"class":268},[138,2185,2080],{"class":162},[138,2187,2123],{"class":268},[138,2189,2170],{"class":162},[138,2191,2192,2195],{"class":140,"line":450},[138,2193,2194],{"class":162},"    contextvars.Context().run(body)      ",[138,2196,2197],{"class":144},"# a fresh, empty context: no leakage between tests\n",[138,2199,2200],{"class":140,"line":456},[138,2201,170],{"emptyLinePlaceholder":169},[138,2203,2204],{"class":140,"line":464},[138,2205,170],{"emptyLinePlaceholder":169},[138,2207,2208,2210,2213],{"class":140,"line":470},[138,2209,297],{"class":151},[138,2211,2212],{"class":300}," test_text_format_is_readable",[138,2214,1867],{"class":162},[138,2216,2217,2219,2221,2223,2225,2227,2229],{"class":140,"line":475},[138,2218,1872],{"class":162},[138,2220,262],{"class":151},[138,2222,1877],{"class":162},[138,2224,1884],{"class":268},[138,2226,272],{"class":162},[138,2228,1889],{"class":268},[138,2230,1902],{"class":162},[138,2232,2233,2235,2238,2241,2244,2247,2250,2252],{"class":140,"line":480},[138,2234,1962],{"class":151},[138,2236,2237],{"class":268}," \"uploaded  run_id=\"",[138,2239,2240],{"class":151}," in",[138,2242,2243],{"class":162}," result.output ",[138,2245,2246],{"class":151},"and",[138,2248,2249],{"class":268}," \"item=a.csv\"",[138,2251,2240],{"class":151},[138,2253,2254],{"class":162}," result.output\n",[10,2256,2257,2258,2261,2262,2265],{},"The second test runs inside a fresh ",[14,2259,2260],{},"contextvars.Context()"," for a reason worth knowing: ",[14,2263,2264],{},"CliRunner"," invokes the app in the test's own thread, so fields bound by one invocation are still set when the next test starts. In a real process that never matters — each run is a new process — but unit tests of context helpers should isolate themselves the same way.",[29,2267,2269],{"id":2268},"conclusion","Conclusion",[10,2271,2272,2273,2275,2276,2278,2279,2281],{},"Correlated logs cost a module of about fifty lines: a context variable holding a dictionary, ",[14,2274,122],{}," for run-level fields and ",[14,2277,126],{}," for per-item fields, a filter on the handler that copies them onto every record, and formatters that print them. Generate a short run ID at startup, bind the command and version with it, copy the context into worker threads, send the ID to servers as ",[14,2280,1706],{},", and show it in error messages. After that, \"the sync failed last night\" becomes one grep on each side.",[29,2283,2285],{"id":2284},"frequently-asked-questions","Frequently asked questions",[1521,2287,2289,2290,2293,2294,2297],{"id":2288},"why-not-use-loggingloggeradapter-with-extra","Why not use ",[14,2291,2292],{},"logging.LoggerAdapter"," with ",[14,2295,2296],{},"extra","?",[10,2299,2300],{},"Adapters work, but the adapter has to be passed to or created in every function that logs, and fields added deep in the call stack do not reach loggers created elsewhere — including libraries. A context variable read by a filter reaches every record without changing any call site.",[1521,2302,2304],{"id":2303},"should-the-run-id-be-a-full-uuid","Should the run ID be a full UUID?",[10,2306,2307],{},"A full UUID is fine for machines and awkward for humans. Twelve hex characters (48 bits) make collisions between one user's runs practically impossible while staying easy to copy from a terminal. If the ID must match a tracing system's format, generate that format instead.",[1521,2309,2311],{"id":2310},"how-does-this-work-with-asyncio","How does this work with asyncio?",[10,2313,2314,2315,2318,2319,2322,2323,2326,2327,2329,2330,27],{},"Each task created with ",[14,2316,2317],{},"asyncio.create_task"," or ",[14,2320,2321],{},"TaskGroup"," gets a copy of the current context automatically, so ",[14,2324,2325],{},"bound(item=...)"," inside a task affects only that task. No ",[14,2328,1537],{}," is needed, as shown in ",[23,2331,2333],{"href":2332},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Frunning-async-code-in-typer-and-click\u002F","running async code in Typer and Click",[1521,2335,2337],{"id":2336},"do-the-fields-go-into-the-rotating-log-file-as-well","Do the fields go into the rotating log file as well?",[10,2339,2340,2341,2344,2345,2349],{},"Yes, if the file handler has the same filter attached. Attach ",[14,2342,2343],{},"ContextFilter"," to every handler you create — console and file — so that ",[23,2346,2348],{"href":2347},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fwriting-rotating-log-files-from-a-cli\u002F","rotating log files"," can be split per run with a single grep.",[1521,2351,2353],{"id":2352},"can-the-servers-id-be-logged-too","Can the server's ID be logged too?",[10,2355,2356],{},"Yes. Many APIs return their own request ID in a response header. Log it at debug level with the response status, bound to the current item, so both IDs appear on the same line when you need to escalate to the service's owners.",[29,2358,2360],{"id":2359},"related","Related",[34,2362,2363,2369,2374,2379,2385],{},[37,2364,2365,2366],{},"Up: ",[23,2367,2368],{"href":25},"Structured logging for CLI apps",[37,2370,2371],{},[23,2372,2373],{"href":45},"Structured JSON logging in Python CLIs",[37,2375,2376],{},[23,2377,2378],{"href":2347},"Writing rotating log files from a CLI",[37,2380,2381],{},[23,2382,2384],{"href":2383},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-verbose-and-quiet-logging-flags\u002F","Adding verbose and quiet logging flags",[37,2386,2387],{},[23,2388,2389],{"href":1714},"Building an API client CLI with httpx",[2391,2392,2393],"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 .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}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":134,"searchDepth":148,"depth":148,"links":2395},[2396,2397,2398,2399,2402,2403,2404,2405,2406,2414],{"id":31,"depth":148,"text":32},{"id":57,"depth":148,"text":58},{"id":85,"depth":148,"text":86},{"id":111,"depth":148,"text":112,"children":2400},[2401],{"id":1523,"depth":166,"text":1524},{"id":1585,"depth":148,"text":1586},{"id":1718,"depth":148,"text":1719},{"id":1766,"depth":148,"text":1767},{"id":2268,"depth":148,"text":2269},{"id":2284,"depth":148,"text":2285,"children":2407},[2408,2410,2411,2412,2413],{"id":2288,"depth":166,"text":2409},"Why not use logging.LoggerAdapter with extra?",{"id":2303,"depth":166,"text":2304},{"id":2310,"depth":166,"text":2311},{"id":2336,"depth":166,"text":2337},{"id":2352,"depth":166,"text":2353},{"id":2359,"depth":148,"text":2360},"2026-09-18","Give every log line from a Python CLI run the same run ID, command and version, carry item context into threads, and send the ID to APIs as a request header.","intermediate",false,"md",{},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-trace-ids-and-context-to-cli-logs",{"title":5,"description":2416},"advanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-trace-ids-and-context-to-cli-logs\u002Findex",[20,16,2425,53,2426],"observability","typer","Ss7hUMcHfzsHmIO-291ZvR8O5URVi_StlGwMqGgINgw",[2429,2432,2435,2438,2441,2444,2447,2450,2453,2456,2459,2462,2465,2468,2471,2474,2477,2480,2483,2486,2489,2492,2495,2498,2501,2504,2507,2510,2513,2516,2519,2522,2525,2528,2531,2534,2537,2540,2543,2546,2549,2552,2555,2558,2561,2562,2565,2568,2571,2574,2577,2580,2583,2586,2589,2592,2595,2598,2601,2604,2607,2610,2613,2616,2619,2622,2625,2628,2631,2634,2637,2640,2643,2646,2649,2652,2655,2658,2661,2664,2667,2670,2673,2676,2679,2682,2685,2688,2691,2694,2697,2700,2703,2706,2709,2712,2715,2718,2721,2724,2727,2730,2733,2736,2739,2742,2745,2748,2751,2754,2757,2760,2763,2766,2769,2772,2775,2778,2781,2784,2787,2790,2793,2796,2799,2802,2805,2808,2811,2814,2817,2820,2823,2826,2829,2832,2835,2838,2841,2844,2847,2850,2853,2856,2859,2862,2865,2868,2871,2874,2877,2880,2883,2886,2889,2892,2895,2898,2901,2904,2907,2910,2913,2916,2919,2922,2925,2928,2931,2934,2937,2940,2943,2946,2949,2952,2955,2958,2961,2964,2967,2970,2973],{"path":2430,"title":2431},"\u002Fabout","About Python CLI Toolcraft",{"path":2433,"title":2434},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies","Advanced Argument Validation Strategies",{"path":2436,"title":2437},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fparsing-nested-json-arguments-in-python-clis","Parsing Nested JSON Args in Python CLIs",{"path":2439,"title":2440},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-dependent-and-conflicting-options","Validating Dependent and Conflicting CLI Options",{"path":2442,"title":2443},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-file-and-directory-paths-in-clis","Validating File and Directory Paths in CLIs",{"path":2445,"title":2446},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fwriting-custom-click-parameter-types","Writing Custom Click Parameter Types",{"path":2448,"title":2449},"\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":2451,"title":2452},"\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":2454,"title":2455},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual","Building Terminal UIs with Textual for Python CLIs",{"path":2457,"title":2458},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Ftesting-textual-apps-with-pilot","Testing Textual Apps with Pilot",{"path":2460,"title":2461},"\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":2463,"title":2464},"\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":2466,"title":2467},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation","CLI Help Output and Documentation",{"path":2469,"title":2470},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fversioning-and-deprecating-cli-flags","Versioning and Deprecating CLI Flags",{"path":2472,"title":2473},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fwriting-help-text-users-actually-read","Writing Help Text Users Actually Read",{"path":2475,"title":2476},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fadapting-output-to-terminal-width","Adapting Python CLI Output to Terminal Width",{"path":2478,"title":2479},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fdetecting-ci-environments-and-non-interactive-shells","Detecting CI Environments and Non-Interactive Shells",{"path":2481,"title":2482},"\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":2484,"title":2485},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility","Cross-Platform Terminal Compatibility for Python CLIs",{"path":2487,"title":2488},"\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":2490,"title":2491},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fchoosing-exit-codes-for-cli-tools","Choosing Exit Codes for CLI Tools",{"path":2493,"title":2494},"\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":2496,"title":2497},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Ffriendly-error-messages-and-tracebacks","Friendly Error Messages and Tracebacks",{"path":2499,"title":2500},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fhandling-keyboard-interrupt-cleanly","Handling Keyboard Interrupt Cleanly",{"path":2502,"title":2503},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes","Error Handling and Exit Codes for CLIs",{"path":2505,"title":2506},"\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":2508,"title":2509},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fconfig-precedence-flags-env-files-defaults","Config Precedence: Flags, Env, Files, Defaults",{"path":2511,"title":2512},"\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":2514,"title":2515},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars","Handling Config Files and Env Vars in CLIs",{"path":2517,"title":2518},"\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":2520,"title":2521},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Freading-toml-config-with-tomllib","Reading TOML Config with tomllib in Python CLIs",{"path":2523,"title":2524},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Ftyped-settings-with-pydantic-settings","Typed Settings with pydantic-settings in Python CLIs",{"path":2526,"title":2527},"\u002Fadvanced-input-parsing-user-experience","Advanced Input Parsing for Python CLIs",{"path":2529,"title":2530},"\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":2532,"title":2533},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Fbuilding-interactive-prompts-and-menus","Building Interactive Prompts and Menus in Python CLIs",{"path":2535,"title":2536},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich","Interactive Terminal UI with Rich",{"path":2538,"title":2539},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Flive-dashboards-with-rich-live","Live Dashboards with Rich Live in Python CLIs",{"path":2541,"title":2542},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Frendering-tables-and-json-with-rich","Rendering Tables and JSON with Rich",{"path":2544,"title":2545},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Ftheming-rich-output-consistently","Theming Rich Output Consistently in Python CLIs",{"path":2547,"title":2548},"\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":2550,"title":2551},"\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":2553,"title":2554},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis","Shell Completion for Python CLIs",{"path":2556,"title":2557},"\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":2559,"title":2560},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Ftesting-shell-completion-in-python-clis","Testing Shell Completion in Python CLIs",{"path":2421,"title":5},{"path":2563,"title":2564},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-verbose-and-quiet-logging-flags","Adding Verbose and Quiet Logging Flags",{"path":2566,"title":2567},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps","Structured Logging for CLI Apps",{"path":2569,"title":2570},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fstructured-json-logging-in-python-clis","Structured JSON Logging in Python CLIs",{"path":2572,"title":2573},"\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":2575,"title":2576},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fdetecting-tty-and-adapting-output","Detecting a TTY and Adapting Output",{"path":2578,"title":2579},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Femitting-json-output-for-scripting","Emitting JSON Output for Scripting",{"path":2581,"title":2582},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fhandling-broken-pipe-and-sigpipe","Handling Broken Pipe and SIGPIPE",{"path":2584,"title":2585},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes","Working with stdin, stdout and Pipes",{"path":2587,"title":2588},"\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":2590,"title":2591},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Freading-piped-input-in-python-clis","Reading Piped Input in Python CLIs",{"path":2593,"title":2594},"\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":2596,"title":2597},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fdownloading-files-with-progress-in-python","Downloading Files with Progress in Python CLIs",{"path":2599,"title":2600},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis","Calling HTTP APIs from Python CLIs",{"path":2602,"title":2603},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Foauth-device-flow-login-for-clis","OAuth Device Flow Login for Python CLIs",{"path":2605,"title":2606},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fpaginating-api-results-in-a-cli","Paginating API Results in a Python CLI",{"path":2608,"title":2609},"\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":2611,"title":2612},"\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":2614,"title":2615},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis","Concurrency and Async in Python CLIs",{"path":2617,"title":2618},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fmultiprocessing-for-cpu-bound-cli-tasks","Multiprocessing for CPU-Bound CLI Tasks",{"path":2620,"title":2621},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fparallelising-cli-work-with-thread-pools","Parallelising CLI Work with Thread Pools",{"path":2623,"title":2624},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Frate-limiting-concurrent-requests-in-clis","Rate-Limiting Concurrent Requests in Python CLIs",{"path":2626,"title":2627},"\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":2629,"title":2630},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fcross-platform-paths-with-pathlib","Cross-Platform Paths with pathlib in CLIs",{"path":2632,"title":2633},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Ffile-locking-for-concurrent-cli-runs","File Locking for Concurrent CLI Runs in Python",{"path":2635,"title":2636},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes","Filesystem Paths and Atomic Writes for CLIs",{"path":2638,"title":2639},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fsafe-temporary-files-and-directories","Safe Temporary Files and Directories in CLIs",{"path":2641,"title":2642},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fstoring-app-data-with-platformdirs","Storing CLI App Data with platformdirs",{"path":2644,"title":2645},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fwriting-files-atomically-in-python-clis","Writing Files Atomically in Python CLIs",{"path":2647,"title":2648},"\u002Fcli-runtime-systems-integration","CLI Runtime & Systems Integration for Python",{"path":2650,"title":2651},"\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":2653,"title":2654},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fhandling-sigterm-and-graceful-shutdown","Handling SIGTERM and Graceful Shutdown in CLIs",{"path":2656,"title":2657},"\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":2659,"title":2660},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis","Long-Running and Watch-Mode Python CLIs",{"path":2662,"title":2663},"\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":2665,"title":2666},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Favoiding-shell-injection-in-python-clis","Avoiding Shell Injection in Python CLIs",{"path":2668,"title":2669},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fcalling-external-commands-safely-with-subprocess","Calling External Commands Safely with subprocess",{"path":2671,"title":2672},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fhandling-subprocess-timeouts-and-exit-codes","Handling Subprocess Timeouts and Exit Codes",{"path":2674,"title":2675},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis","Running Subprocesses from Python CLIs",{"path":2677,"title":2678},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fstreaming-subprocess-output-in-real-time","Streaming Subprocess Output in Real Time",{"path":2680,"title":2681},"\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":2683,"title":2684},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis","Secrets and Credentials in Python CLIs",{"path":2686,"title":2687},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fprompting-for-passwords-securely","Prompting for Passwords Securely in Python CLIs",{"path":2689,"title":2690},"\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":2692,"title":2693},"\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":2695,"title":2696},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fstoring-tokens-with-keyring","Storing CLI Tokens Securely with keyring",{"path":2698,"title":2699},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fsupporting-multiple-profiles-and-accounts","Supporting Multiple Profiles and Accounts in CLIs",{"path":2701,"title":2702},"\u002F","Python CLI Toolcraft",{"path":2704,"title":2705},"\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":2707,"title":2708},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading","CLI Startup Performance and Lazy Loading",{"path":2710,"title":2711},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup","Lazy Loading Subcommands for Faster Startup",{"path":2713,"title":2714},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fprofiling-python-cli-startup-time","Profiling Python CLI Startup Time",{"path":2716,"title":2717},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Freducing-cli-dependency-weight","Reducing CLI Dependency Weight",{"path":2719,"title":2720},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-subparsers-for-subcommands","argparse Subparsers for Subcommands",{"path":2722,"title":2723},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-vs-click-vs-typer-comparison","argparse vs Click vs Typer Compared",{"path":2725,"title":2726},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse","Command-Line Parsing with argparse",{"path":2728,"title":2729},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmigrating-from-argparse-to-typer","Migrating from argparse to Typer",{"path":2731,"title":2732},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmutually-exclusive-options-in-argparse","Mutually Exclusive Options in argparse",{"path":2734,"title":2735},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fwriting-custom-argparse-actions","Writing Custom argparse Actions in Python",{"path":2737,"title":2738},"\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":2740,"title":2741},"\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":2743,"title":2744},"\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":2746,"title":2747},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions","Designing CLI Interfaces and Conventions in Python",{"path":2749,"title":2750},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fnaming-commands-and-flags-consistently","Naming Commands and Flags Consistently in Python CLIs",{"path":2752,"title":2753},"\u002Fmodern-python-cli-frameworks-architecture","Python CLI Frameworks and Architecture",{"path":2755,"title":2756},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fdiscovering-plugins-with-entry-points","Discovering Plugins with Entry Points in Python CLIs",{"path":2758,"title":2759},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fhook-based-plugins-with-pluggy","Hook-Based Plugins for Python CLIs with pluggy",{"path":2761,"title":2762},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis","Plugin Architectures for Extensible CLIs",{"path":2764,"title":2765},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fversioning-a-plugin-api","Versioning a Plugin API for a Python CLI",{"path":2767,"title":2768},"\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":2770,"title":2771},"\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":2773,"title":2774},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fdependency-injection-patterns-for-cli-commands","Dependency Injection Patterns for CLI Commands",{"path":2776,"title":2777},"\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":2779,"title":2780},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis","Structuring Multi-Command Python CLIs",{"path":2782,"title":2783},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-common-options-across-commands","Sharing Common Options Across Python CLI Commands",{"path":2785,"title":2786},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-state-with-click-context-objects","Sharing State with Click Context Objects",{"path":2788,"title":2789},"\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":2791,"title":2792},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications","Testing Python CLI Applications",{"path":2794,"title":2795},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fmeasuring-cli-test-coverage","Measuring CLI Test Coverage",{"path":2797,"title":2798},"\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":2800,"title":2801},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fproperty-based-testing-cli-arguments-with-hypothesis","Property-Based Testing CLI Arguments with Hypothesis",{"path":2803,"title":2804},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fsnapshot-testing-cli-output","Snapshot Testing CLI Output",{"path":2806,"title":2807},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-click-commands-with-clirunner","Testing Click Commands with CliRunner",{"path":2809,"title":2810},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-interactive-prompts-and-stdin","Testing Interactive Prompts and stdin",{"path":2812,"title":2813},"\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":2815,"title":2816},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fbuilding-dynamic-commands-in-click","Building Dynamic Commands in Click",{"path":2818,"title":2819},"\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":2821,"title":2822},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each","Typer vs Click: When to Use Each",{"path":2824,"title":2825},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Ftyper-callback-functions-explained","Typer callback functions explained",{"path":2827,"title":2828},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fusing-annotated-options-in-typer","Using Annotated Options in Typer",{"path":2830,"title":2831},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fautomating-releases-from-git-tags","Automating Python CLI Releases from Git Tags",{"path":2833,"title":2834},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fcaching-uv-dependencies-in-ci","Caching uv Dependencies in CI for Python CLIs",{"path":2836,"title":2837},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis","CI\u002FCD Pipelines for Python CLIs",{"path":2839,"title":2840},"\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":2842,"title":2843},"\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":2845,"title":2846},"\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":2848,"title":2849},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fbuilding-a-cookiecutter-template-for-typer-clis","Building a Cookiecutter Template for Typer CLIs",{"path":2851,"title":2852},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fcopier-vs-cookiecutter-for-cli-templates","Copier vs Cookiecutter for CLI Templates",{"path":2854,"title":2855},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter","CLI Project Scaffolding with Cookiecutter",{"path":2857,"title":2858},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fpost-generation-hooks-in-cli-templates","Post-Generation Hooks in Python CLI Templates",{"path":2860,"title":2861},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbuilding-cross-platform-release-binaries-in-ci","Building Cross-Platform Release Binaries in CI",{"path":2863,"title":2864},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbundling-a-python-cli-with-pyinstaller","Bundling a Python CLI with PyInstaller",{"path":2866,"title":2867},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fhomebrew-and-scoop-packaging-for-python-clis","Homebrew and Scoop Packaging for Python CLIs",{"path":2869,"title":2870},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries","Distributing CLIs as Standalone Binaries",{"path":2872,"title":2873},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fnuitka-vs-pyinstaller-for-python-clis","Nuitka vs PyInstaller for Python CLI Binaries",{"path":2875,"title":2876},"\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":2878,"title":2879},"\u002Fproject-setup-dependency-management","Project Setup & Dependency Management",{"path":2881,"title":2882},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Fconfiguring-ruff-for-a-cli-project","Configuring Ruff for a Python CLI Project",{"path":2884,"title":2885},"\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":2887,"title":2888},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code","Linting and Type-Checking Python CLI Code",{"path":2890,"title":2891},"\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":2893,"title":2894},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fautomating-changelogs-with-conventional-commits","Automating Changelogs with Conventional Commits",{"path":2896,"title":2897},"\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":2899,"title":2900},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fexposing-version-info-and-build-metadata","Exposing Version Info and Build Metadata",{"path":2902,"title":2903},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs","Managing CLI Versioning & Changelogs",{"path":2905,"title":2906},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fsemantic-versioning-policy-for-cli-tools","A Semantic Versioning Policy for CLI Tools",{"path":2908,"title":2909},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbuilding-wheels-and-sdists-for-python-clis","Building Wheels and sdists for Python CLIs",{"path":2911,"title":2912},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbundling-data-files-with-importlib-resources","Bundling Data Files with importlib.resources in CLIs",{"path":2914,"title":2915},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution","Packaging Python CLIs for Distribution",{"path":2917,"title":2918},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Finstalling-and-distributing-clis-with-pipx","Installing and Distributing CLIs with pipx",{"path":2920,"title":2921},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fpublishing-a-python-cli-to-pypi","Publishing a Python CLI to PyPI",{"path":2923,"title":2924},"\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":2926,"title":2927},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development","Poetry Workflows for CLI Development",{"path":2929,"title":2930},"\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":2932,"title":2933},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-dependency-groups-for-cli-tooling","Poetry Dependency Groups for CLI Tooling",{"path":2935,"title":2936},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-entry-points-and-scripts-for-clis","Poetry Entry Points and Scripts for CLIs",{"path":2938,"title":2939},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects","Pre-commit Hooks for CLI Projects",{"path":2941,"title":2942},"\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":2944,"title":2945},"\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":2947,"title":2948},"\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":2950,"title":2951},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management","uv for Python CLI Dependency Management",{"path":2953,"title":2954},"\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":2956,"title":2957},"\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":2959,"title":2960},"\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":2962,"title":2963},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fuv-workspaces-for-multi-package-clis","uv Workspaces for Multi-Package Python CLIs",{"path":2965,"title":2966},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices","Python CLI Env Isolation Best Practices",{"path":2968,"title":2969},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fmanaging-virtual-environments-for-cross-platform-clis","Managing Python CLI Virtual Environments",{"path":2971,"title":2972},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fpinning-the-python-version-for-a-cli","Pinning the Python Version for a CLI",{"path":2974,"title":2975},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fsupporting-multiple-python-versions-with-nox","Supporting Multiple Python Versions with nox",1789736905047]