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