[{"data":1,"prerenderedAt":2402},["ShallowReactive",2],{"page-\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002F":3,"content-directory":1854},{"id":4,"title":5,"body":6,"date":1840,"description":1841,"difficulty":1842,"draft":1843,"extension":1844,"meta":1845,"navigation":219,"path":1846,"seo":1847,"stem":1848,"tags":1849,"updated":1840,"__hash__":1853},"content\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Findex.md","Calling HTTP APIs from Python CLIs",{"type":7,"value":8,"toc":1816},"minimark",[9,18,41,45,50,118,125,142,153,156,178,777,793,797,800,803,806,825,840,844,847,850,856,866,881,885,888,895,1099,1117,1121,1124,1142,1161,1165,1192,1196,1203,1517,1536,1540,1543,1566,1592,1610,1614,1646,1650,1660,1673,1677,1690,1694,1713,1721,1732,1736,1754,1758,1769,1773,1812],[10,11,12,13,17],"p",{},"A large share of internal CLIs are front ends to a web API: list the deployments, trigger a build, fetch the logs, download the dataset. They start as twenty lines around ",[14,15,16],"code",{},"requests.get()"," and grow into tools a whole team depends on. Along the way the same problems appear in roughly the same order. A command hangs forever because the server stopped responding mid-request. A 502 during a deploy aborts a script that would have succeeded a second later. A listing command silently shows only the first 100 results. Someone pastes a long-lived token into a config file. A two-gigabyte download fails at 95% and starts again from zero.",[10,19,20,21,24,25,30,31,35,36,40],{},"This topic covers the patterns that make an API-backed CLI dependable: one client module over a configured ",[14,22,23],{},"httpx"," session, explicit timeouts, retries that are safe and polite, pagination that streams instead of collecting, a login flow that never asks for a password, and downloads that show progress and resume. It is part of the ",[26,27,29],"a",{"href":28},"\u002Fcli-runtime-systems-integration\u002F","CLI Runtime & Systems Integration"," section; the concurrency side — many requests at once — lives in ",[26,32,34],{"href":33},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002F","concurrency and async in Python CLIs",", and token storage lives in ",[26,37,39],{"href":38},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002F","secrets and credentials",".",[42,43],"inline-diagram",{"name":44},"http-topic-map",[46,47,49],"h2",{"id":48},"tldr","TL;DR",[51,52,53,69,75,84,98,104],"ul",{},[54,55,56,64,65,68],"li",{},[57,58,59,60,63],"strong",{},"Use one ",[14,61,62],{},"httpx.Client"," per run",", configured once with a base URL, auth, timeouts, a ",[14,66,67],{},"User-Agent"," and retries. Keep it in one module; commands never build URLs.",[54,70,71,74],{},[57,72,73],{},"Always set timeouts."," httpx defaults to five seconds for everything, which is too short for some reads and says nothing about total duration. Choose values on purpose and add an overall deadline for long operations.",[54,76,77,80,81,40],{},[57,78,79],{},"Retry only what is safe to retry"," — connection failures, 429 and 5xx responses on idempotent requests — with capped exponential backoff and jitter, and honour ",[14,82,83],{},"Retry-After",[54,85,86,89,90,93,94,97],{},[57,87,88],{},"Paginate with a generator"," that yields items, so ",[14,91,92],{},"--limit"," stops fetching early and ",[14,95,96],{},"--all"," streams without holding everything in memory.",[54,99,100,103],{},[57,101,102],{},"Log in with the OAuth device flow"," where the API supports it, and store tokens in the system keychain, not a dot-file.",[54,105,106,113,114,117],{},[57,107,108,109,112],{},"Stream downloads to a ",[14,110,111],{},".part"," file",", verify, then rename; resume with a ",[14,115,116],{},"Range"," request when interrupted.",[46,119,121,122,124],{"id":120},"why-httpx-and-why-one-client","Why ",[14,123,23],{},", and why one client",[10,126,127,130,131,133,134,137,138,141],{},[14,128,129],{},"requests"," is still everywhere and still works. For new CLIs, ",[14,132,23],{}," is the better default: it has a nearly identical API, supports HTTP\u002F2, has a clean timeout model, provides ",[14,135,136],{},"MockTransport"," for tests without extra libraries, and offers the same interface in synchronous and ",[14,139,140],{},"async"," forms, so moving a command to concurrent requests later does not mean switching libraries.",[10,143,144,145,148,149,152],{},"Whichever library you use, create ",[57,146,147],{},"one client per invocation"," rather than calling module-level ",[14,150,151],{},"httpx.get()"," for each request. A client holds a connection pool: the first request pays for DNS, TCP and the TLS handshake, and subsequent requests to the same host reuse that connection. For a command that makes twenty requests, that is often the difference between two seconds and six.",[42,154],{"name":155},"http-client-layers",[10,157,158,159,162,163,166,167,170,171,173,174,40],{},"The client sits in the middle of a three-layer structure. Commands parse arguments and render output. An ",[57,160,161],{},"API client module"," — your code — exposes functions like ",[14,164,165],{},"list_projects()"," and ",[14,168,169],{},"get_build(build_id)"," that return typed objects. Underneath, a configured ",[14,172,62],{}," handles transport concerns. Commands never see URLs or status codes; the API module never prints. That separation is what makes each part testable, and it mirrors the thin-command-layer advice in ",[26,175,177],{"href":176},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fhow-to-structure-a-large-python-cli-project\u002F","how to structure a large Python CLI project",[179,180,185],"pre",{"className":181,"code":182,"language":183,"meta":184,"style":184},"language-python shiki shiki-themes github-light github-dark","# src\u002Fmytool\u002Fapi.py\nfrom __future__ import annotations\n\nfrom dataclasses import dataclass\nfrom importlib.metadata import version\n\nimport httpx\n\n\n@dataclass(frozen=True)\nclass Project:\n    name: str\n    owner: str\n    builds: int\n\n\nclass ApiError(Exception):\n    def __init__(self, message: str, exit_code: int = 1) -> None:\n        super().__init__(message)\n        self.exit_code = exit_code\n\n\ndef make_client(base_url: str, token: str | None) -> httpx.Client:\n    headers = {\"User-Agent\": f\"mytool\u002F{version('mytool')}\", \"Accept\": \"application\u002Fjson\"}\n    if token:\n        headers[\"Authorization\"] = f\"Bearer {token}\"\n    return httpx.Client(\n        base_url=base_url,\n        headers=headers,\n        timeout=httpx.Timeout(30.0, connect=5.0),\n        transport=httpx.HTTPTransport(retries=2),   # connection failures only\n        follow_redirects=True,\n    )\n\n\ndef list_projects(client: httpx.Client) -> list[Project]:\n    response = client.get(\"\u002Fprojects\")\n    if response.status_code == 401:\n        raise ApiError(\"not logged in — run: mytool login\", exit_code=4)\n    response.raise_for_status()\n    return [Project(p[\"name\"], p[\"owner\"], p[\"build_count\"]) for p in response.json()]\n","python","",[14,186,187,196,214,221,235,248,253,261,266,271,294,306,315,323,332,337,342,358,393,408,422,427,432,460,516,525,555,564,575,586,613,638,651,657,662,667,678,694,710,734,740],{"__ignoreMap":184},[188,189,192],"span",{"class":190,"line":191},"line",1,[188,193,195],{"class":194},"sJ8bj","# src\u002Fmytool\u002Fapi.py\n",[188,197,199,203,207,210],{"class":190,"line":198},2,[188,200,202],{"class":201},"szBVR","from",[188,204,206],{"class":205},"sj4cs"," __future__",[188,208,209],{"class":201}," import",[188,211,213],{"class":212},"sVt8B"," annotations\n",[188,215,217],{"class":190,"line":216},3,[188,218,220],{"emptyLinePlaceholder":219},true,"\n",[188,222,224,226,229,232],{"class":190,"line":223},4,[188,225,202],{"class":201},[188,227,228],{"class":212}," dataclasses ",[188,230,231],{"class":201},"import",[188,233,234],{"class":212}," dataclass\n",[188,236,238,240,243,245],{"class":190,"line":237},5,[188,239,202],{"class":201},[188,241,242],{"class":212}," importlib.metadata ",[188,244,231],{"class":201},[188,246,247],{"class":212}," version\n",[188,249,251],{"class":190,"line":250},6,[188,252,220],{"emptyLinePlaceholder":219},[188,254,256,258],{"class":190,"line":255},7,[188,257,231],{"class":201},[188,259,260],{"class":212}," httpx\n",[188,262,264],{"class":190,"line":263},8,[188,265,220],{"emptyLinePlaceholder":219},[188,267,269],{"class":190,"line":268},9,[188,270,220],{"emptyLinePlaceholder":219},[188,272,274,278,281,285,288,291],{"class":190,"line":273},10,[188,275,277],{"class":276},"sScJk","@dataclass",[188,279,280],{"class":212},"(",[188,282,284],{"class":283},"s4XuR","frozen",[188,286,287],{"class":201},"=",[188,289,290],{"class":205},"True",[188,292,293],{"class":212},")\n",[188,295,297,300,303],{"class":190,"line":296},11,[188,298,299],{"class":201},"class",[188,301,302],{"class":276}," Project",[188,304,305],{"class":212},":\n",[188,307,309,312],{"class":190,"line":308},12,[188,310,311],{"class":212},"    name: ",[188,313,314],{"class":205},"str\n",[188,316,318,321],{"class":190,"line":317},13,[188,319,320],{"class":212},"    owner: ",[188,322,314],{"class":205},[188,324,326,329],{"class":190,"line":325},14,[188,327,328],{"class":212},"    builds: ",[188,330,331],{"class":205},"int\n",[188,333,335],{"class":190,"line":334},15,[188,336,220],{"emptyLinePlaceholder":219},[188,338,340],{"class":190,"line":339},16,[188,341,220],{"emptyLinePlaceholder":219},[188,343,345,347,350,352,355],{"class":190,"line":344},17,[188,346,299],{"class":201},[188,348,349],{"class":276}," ApiError",[188,351,280],{"class":212},[188,353,354],{"class":205},"Exception",[188,356,357],{"class":212},"):\n",[188,359,361,364,367,370,373,376,379,382,385,388,391],{"class":190,"line":360},18,[188,362,363],{"class":201},"    def",[188,365,366],{"class":205}," __init__",[188,368,369],{"class":212},"(self, message: ",[188,371,372],{"class":205},"str",[188,374,375],{"class":212},", exit_code: ",[188,377,378],{"class":205},"int",[188,380,381],{"class":201}," =",[188,383,384],{"class":205}," 1",[188,386,387],{"class":212},") -> ",[188,389,390],{"class":205},"None",[188,392,305],{"class":212},[188,394,396,399,402,405],{"class":190,"line":395},19,[188,397,398],{"class":205},"        super",[188,400,401],{"class":212},"().",[188,403,404],{"class":205},"__init__",[188,406,407],{"class":212},"(message)\n",[188,409,411,414,417,419],{"class":190,"line":410},20,[188,412,413],{"class":205},"        self",[188,415,416],{"class":212},".exit_code ",[188,418,287],{"class":201},[188,420,421],{"class":212}," exit_code\n",[188,423,425],{"class":190,"line":424},21,[188,426,220],{"emptyLinePlaceholder":219},[188,428,430],{"class":190,"line":429},22,[188,431,220],{"emptyLinePlaceholder":219},[188,433,435,438,441,444,446,449,451,454,457],{"class":190,"line":434},23,[188,436,437],{"class":201},"def",[188,439,440],{"class":276}," make_client",[188,442,443],{"class":212},"(base_url: ",[188,445,372],{"class":205},[188,447,448],{"class":212},", token: ",[188,450,372],{"class":205},[188,452,453],{"class":201}," |",[188,455,456],{"class":205}," None",[188,458,459],{"class":212},") -> httpx.Client:\n",[188,461,463,466,468,471,475,478,481,484,487,490,493,496,499,502,505,508,510,513],{"class":190,"line":462},24,[188,464,465],{"class":212},"    headers ",[188,467,287],{"class":201},[188,469,470],{"class":212}," {",[188,472,474],{"class":473},"sZZnC","\"User-Agent\"",[188,476,477],{"class":212},": ",[188,479,480],{"class":201},"f",[188,482,483],{"class":473},"\"mytool\u002F",[188,485,486],{"class":205},"{",[188,488,489],{"class":212},"version(",[188,491,492],{"class":473},"'mytool'",[188,494,495],{"class":212},")",[188,497,498],{"class":205},"}",[188,500,501],{"class":473},"\"",[188,503,504],{"class":212},", ",[188,506,507],{"class":473},"\"Accept\"",[188,509,477],{"class":212},[188,511,512],{"class":473},"\"application\u002Fjson\"",[188,514,515],{"class":212},"}\n",[188,517,519,522],{"class":190,"line":518},25,[188,520,521],{"class":201},"    if",[188,523,524],{"class":212}," token:\n",[188,526,528,531,534,537,539,542,545,547,550,552],{"class":190,"line":527},26,[188,529,530],{"class":212},"        headers[",[188,532,533],{"class":473},"\"Authorization\"",[188,535,536],{"class":212},"] ",[188,538,287],{"class":201},[188,540,541],{"class":201}," f",[188,543,544],{"class":473},"\"Bearer ",[188,546,486],{"class":205},[188,548,549],{"class":212},"token",[188,551,498],{"class":205},[188,553,554],{"class":473},"\"\n",[188,556,558,561],{"class":190,"line":557},27,[188,559,560],{"class":201},"    return",[188,562,563],{"class":212}," httpx.Client(\n",[188,565,567,570,572],{"class":190,"line":566},28,[188,568,569],{"class":283},"        base_url",[188,571,287],{"class":201},[188,573,574],{"class":212},"base_url,\n",[188,576,578,581,583],{"class":190,"line":577},29,[188,579,580],{"class":283},"        headers",[188,582,287],{"class":201},[188,584,585],{"class":212},"headers,\n",[188,587,589,592,594,597,600,602,605,607,610],{"class":190,"line":588},30,[188,590,591],{"class":283},"        timeout",[188,593,287],{"class":201},[188,595,596],{"class":212},"httpx.Timeout(",[188,598,599],{"class":205},"30.0",[188,601,504],{"class":212},[188,603,604],{"class":283},"connect",[188,606,287],{"class":201},[188,608,609],{"class":205},"5.0",[188,611,612],{"class":212},"),\n",[188,614,616,619,621,624,627,629,632,635],{"class":190,"line":615},31,[188,617,618],{"class":283},"        transport",[188,620,287],{"class":201},[188,622,623],{"class":212},"httpx.HTTPTransport(",[188,625,626],{"class":283},"retries",[188,628,287],{"class":201},[188,630,631],{"class":205},"2",[188,633,634],{"class":212},"),   ",[188,636,637],{"class":194},"# connection failures only\n",[188,639,641,644,646,648],{"class":190,"line":640},32,[188,642,643],{"class":283},"        follow_redirects",[188,645,287],{"class":201},[188,647,290],{"class":205},[188,649,650],{"class":212},",\n",[188,652,654],{"class":190,"line":653},33,[188,655,656],{"class":212},"    )\n",[188,658,660],{"class":190,"line":659},34,[188,661,220],{"emptyLinePlaceholder":219},[188,663,665],{"class":190,"line":664},35,[188,666,220],{"emptyLinePlaceholder":219},[188,668,670,672,675],{"class":190,"line":669},36,[188,671,437],{"class":201},[188,673,674],{"class":276}," list_projects",[188,676,677],{"class":212},"(client: httpx.Client) -> list[Project]:\n",[188,679,681,684,686,689,692],{"class":190,"line":680},37,[188,682,683],{"class":212},"    response ",[188,685,287],{"class":201},[188,687,688],{"class":212}," client.get(",[188,690,691],{"class":473},"\"\u002Fprojects\"",[188,693,293],{"class":212},[188,695,697,699,702,705,708],{"class":190,"line":696},38,[188,698,521],{"class":201},[188,700,701],{"class":212}," response.status_code ",[188,703,704],{"class":201},"==",[188,706,707],{"class":205}," 401",[188,709,305],{"class":212},[188,711,713,716,719,722,724,727,729,732],{"class":190,"line":712},39,[188,714,715],{"class":201},"        raise",[188,717,718],{"class":212}," ApiError(",[188,720,721],{"class":473},"\"not logged in — run: mytool login\"",[188,723,504],{"class":212},[188,725,726],{"class":283},"exit_code",[188,728,287],{"class":201},[188,730,731],{"class":205},"4",[188,733,293],{"class":212},[188,735,737],{"class":190,"line":736},40,[188,738,739],{"class":212},"    response.raise_for_status()\n",[188,741,743,745,748,751,754,757,759,762,765,768,771,774],{"class":190,"line":742},41,[188,744,560],{"class":201},[188,746,747],{"class":212}," [Project(p[",[188,749,750],{"class":473},"\"name\"",[188,752,753],{"class":212},"], p[",[188,755,756],{"class":473},"\"owner\"",[188,758,753],{"class":212},[188,760,761],{"class":473},"\"build_count\"",[188,763,764],{"class":212},"]) ",[188,766,767],{"class":201},"for",[188,769,770],{"class":212}," p ",[188,772,773],{"class":201},"in",[188,775,776],{"class":212}," response.json()]\n",[10,778,779,780,782,783,787,788,792],{},"The ",[14,781,67],{}," with your tool's version is a small courtesy with a large payoff: when the API team sees a spike of errors, they can tell which client and which release is responsible. The version itself should come from package metadata, as described in ",[26,784,786],{"href":785},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fexposing-version-info-and-build-metadata\u002F","exposing version info and build metadata",". ",[26,789,791],{"href":790},"\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"," takes this module all the way to a finished command with tables, JSON output and tests.",[46,794,796],{"id":795},"timeouts-are-not-optional","Timeouts are not optional",[10,798,799],{},"A request without a meaningful timeout is a potential hang. A server can accept the connection and then never respond; a load balancer can hold a request open for minutes; a corporate proxy can stall silently. The user sees a frozen terminal and eventually presses Ctrl+C, which is the least helpful way to learn that the API is down.",[10,801,802],{},"httpx separates four timeouts, and each guards against a different stall:",[42,804],{"name":805},"http-timeout-matrix",[10,807,808,809,811,812,815,816,820,821,824],{},"The defaults are five seconds for each. For a CLI, a short ",[57,810,604],{}," timeout (a few seconds) is right: if the server cannot even complete a TLS handshake, waiting longer rarely helps, and the user deserves to know quickly. The ",[57,813,814],{},"read"," timeout should reflect the slowest legitimate endpoint — a report generation call might need sixty seconds. Note that the read timeout limits the gap ",[817,818,819],"em",{},"between"," bytes, not the total: a server trickling one byte every twenty seconds never trips it. For operations with a real time budget, wrap them in an overall deadline and expose it as a ",[14,822,823],{},"--timeout"," option.",[10,826,827,828,831,832,835,836,839],{},"When a timeout fires, httpx raises ",[14,829,830],{},"httpx.ConnectTimeout"," or ",[14,833,834],{},"httpx.ReadTimeout"," (both subclasses of ",[14,837,838],{},"httpx.TimeoutException","). Catch them at the API layer and turn them into a message that names the host and the limit: \"api.example.com did not respond within 30s — check the service status or retry with --timeout 120.\"",[46,841,843],{"id":842},"failing-well-status-codes-and-retries","Failing well: status codes and retries",[10,845,846],{},"Not all failures are equal, and the right response depends on who caused them.",[42,848],{"name":849},"http-status-handling",[10,851,852,855],{},[57,853,854],{},"Client errors (4xx)"," mean the request was wrong: bad credentials, a missing resource, invalid input. Retrying will produce the same answer, so report it — ideally using the server's own error message, which for a 422 usually says exactly which field was invalid — and exit non-zero. Map 401 and 403 to a message that tells the user how to authenticate.",[10,857,858,861,862,865],{},[57,859,860],{},"Server errors (5xx) and rate limits (429)"," mean the server is having trouble right now. These are worth retrying, a few times, with increasing delays. ",[57,863,864],{},"Network errors"," — DNS failures, refused connections, resets — are also worth a retry, and after the final attempt deserve a message that mentions the usual suspects: VPN, proxy settings, DNS.",[10,867,868,869,872,873,875,876,880],{},"The retry policy itself has subtleties that are easy to get wrong. Retrying a ",[14,870,871],{},"POST"," after a read timeout can create a duplicate, because the server may have processed the first attempt. Retrying immediately and in lockstep with every other client makes an overloaded server worse. And ignoring the server's ",[14,874,83],{}," header wastes both sides' time. ",[26,877,879],{"href":878},"\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"," builds a small retry wrapper that handles all three, with a deterministic test suite.",[46,882,884],{"id":883},"lists-that-do-not-fit-in-one-response","Lists that do not fit in one response",[10,886,887],{},"Every serious API paginates. The bug that ships most often in API-backed CLIs is not an error at all: a listing command that fetches the first page and presents it as the whole answer. The user filters for failed builds, sees none, and concludes everything is fine — because the failures were on page two.",[10,889,890,891,894],{},"The robust pattern is a generator in the API module that follows the API's pagination scheme — page numbers, cursors or ",[14,892,893],{},"Link"," headers — and yields individual items:",[179,896,898],{"className":181,"code":897,"language":183,"meta":184,"style":184},"from collections.abc import Iterator\nfrom typing import Any\n\nimport httpx\n\n\ndef iter_builds(client: httpx.Client, project: str) -> Iterator[dict[str, Any]]:\n    params: dict[str, Any] = {\"project\": project, \"per_page\": 100}\n    while True:\n        response = client.get(\"\u002Fbuilds\", params=params)\n        response.raise_for_status()\n        body = response.json()\n        yield from body[\"items\"]\n        cursor = body.get(\"next_cursor\")\n        if not cursor:\n            return\n        params[\"cursor\"] = cursor\n",[14,899,900,912,924,928,934,938,942,962,992,1002,1024,1029,1039,1053,1068,1079,1084],{"__ignoreMap":184},[188,901,902,904,907,909],{"class":190,"line":191},[188,903,202],{"class":201},[188,905,906],{"class":212}," collections.abc ",[188,908,231],{"class":201},[188,910,911],{"class":212}," Iterator\n",[188,913,914,916,919,921],{"class":190,"line":198},[188,915,202],{"class":201},[188,917,918],{"class":212}," typing ",[188,920,231],{"class":201},[188,922,923],{"class":212}," Any\n",[188,925,926],{"class":190,"line":216},[188,927,220],{"emptyLinePlaceholder":219},[188,929,930,932],{"class":190,"line":223},[188,931,231],{"class":201},[188,933,260],{"class":212},[188,935,936],{"class":190,"line":237},[188,937,220],{"emptyLinePlaceholder":219},[188,939,940],{"class":190,"line":250},[188,941,220],{"emptyLinePlaceholder":219},[188,943,944,946,949,952,954,957,959],{"class":190,"line":255},[188,945,437],{"class":201},[188,947,948],{"class":276}," iter_builds",[188,950,951],{"class":212},"(client: httpx.Client, project: ",[188,953,372],{"class":205},[188,955,956],{"class":212},") -> Iterator[dict[",[188,958,372],{"class":205},[188,960,961],{"class":212},", Any]]:\n",[188,963,964,967,969,972,974,976,979,982,985,987,990],{"class":190,"line":263},[188,965,966],{"class":212},"    params: dict[",[188,968,372],{"class":205},[188,970,971],{"class":212},", Any] ",[188,973,287],{"class":201},[188,975,470],{"class":212},[188,977,978],{"class":473},"\"project\"",[188,980,981],{"class":212},": project, ",[188,983,984],{"class":473},"\"per_page\"",[188,986,477],{"class":212},[188,988,989],{"class":205},"100",[188,991,515],{"class":212},[188,993,994,997,1000],{"class":190,"line":268},[188,995,996],{"class":201},"    while",[188,998,999],{"class":205}," True",[188,1001,305],{"class":212},[188,1003,1004,1007,1009,1011,1014,1016,1019,1021],{"class":190,"line":273},[188,1005,1006],{"class":212},"        response ",[188,1008,287],{"class":201},[188,1010,688],{"class":212},[188,1012,1013],{"class":473},"\"\u002Fbuilds\"",[188,1015,504],{"class":212},[188,1017,1018],{"class":283},"params",[188,1020,287],{"class":201},[188,1022,1023],{"class":212},"params)\n",[188,1025,1026],{"class":190,"line":296},[188,1027,1028],{"class":212},"        response.raise_for_status()\n",[188,1030,1031,1034,1036],{"class":190,"line":308},[188,1032,1033],{"class":212},"        body ",[188,1035,287],{"class":201},[188,1037,1038],{"class":212}," response.json()\n",[188,1040,1041,1044,1047,1050],{"class":190,"line":317},[188,1042,1043],{"class":201},"        yield from",[188,1045,1046],{"class":212}," body[",[188,1048,1049],{"class":473},"\"items\"",[188,1051,1052],{"class":212},"]\n",[188,1054,1055,1058,1060,1063,1066],{"class":190,"line":325},[188,1056,1057],{"class":212},"        cursor ",[188,1059,287],{"class":201},[188,1061,1062],{"class":212}," body.get(",[188,1064,1065],{"class":473},"\"next_cursor\"",[188,1067,293],{"class":212},[188,1069,1070,1073,1076],{"class":190,"line":334},[188,1071,1072],{"class":201},"        if",[188,1074,1075],{"class":201}," not",[188,1077,1078],{"class":212}," cursor:\n",[188,1080,1081],{"class":190,"line":339},[188,1082,1083],{"class":201},"            return\n",[188,1085,1086,1089,1092,1094,1096],{"class":190,"line":344},[188,1087,1088],{"class":212},"        params[",[188,1090,1091],{"class":473},"\"cursor\"",[188,1093,536],{"class":212},[188,1095,287],{"class":201},[188,1097,1098],{"class":212}," cursor\n",[10,1100,1101,1102,1105,1106,1108,1109,1113,1114,1116],{},"Because it is lazy, the command decides how much to fetch: ",[14,1103,1104],{},"itertools.islice(iter_builds(...), limit)"," stops after the first page when the user asked for twenty items, while ",[14,1107,96],{}," walks every page and can stream results as they arrive. ",[26,1110,1112],{"href":1111},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fpaginating-api-results-in-a-cli\u002F","Paginating API results in a CLI"," covers the three pagination styles, sensible defaults for ",[14,1115,92],{},", and streaming NDJSON output for scripts.",[46,1118,1120],{"id":1119},"authentication-without-passwords","Authentication without passwords",[10,1122,1123],{},"A CLI that asks for a username and password is asking users to type their most sensitive credential into a program they cannot inspect, and it breaks as soon as the organisation enables single sign-on or multi-factor authentication. Two better options cover almost every case:",[51,1125,1126,1136],{},[54,1127,1128,1131,1132,1135],{},[57,1129,1130],{},"Personal access tokens"," that the user creates in the web UI and passes via an environment variable or a ",[14,1133,1134],{},"login --token"," command. Simple, scriptable, and ideal for CI.",[54,1137,1138,1141],{},[57,1139,1140],{},"The OAuth 2.0 device authorization flow"," (RFC 8628), which GitHub, Microsoft, Google and most identity providers support. The CLI displays a short code and a URL; the user approves in any browser, on any device, using whatever SSO and MFA their organisation requires; the CLI receives tokens. No password ever touches your program.",[10,1143,1144,1145,166,1148,1151,1152,1156,1157,40],{},"The device flow is the one ",[14,1146,1147],{},"gh auth login",[14,1149,1150],{},"az login --use-device-code"," use, and it is less work to implement than most people expect — two endpoints and a polling loop. ",[26,1153,1155],{"href":1154},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Foauth-device-flow-login-for-clis\u002F","OAuth device flow login for CLIs"," implements it with httpx, handles every polling response, and stores the resulting tokens with ",[26,1158,1160],{"href":1159},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fstoring-tokens-with-keyring\u002F","keyring",[46,1162,1164],{"id":1163},"big-responses-downloads","Big responses: downloads",[10,1166,1167,1168,1171,1172,1175,1176,1178,1179,1183,1184,1186,1187,1191],{},"Downloading a large file is its own problem. ",[14,1169,1170],{},"response.content"," loads the whole body into memory; writing straight to the destination leaves a truncated file if the connection drops; and a silent two-minute download looks exactly like a hang. The pattern that fixes all three streams the body in chunks with ",[14,1173,1174],{},"client.stream(\"GET\", url)",", writes to a ",[14,1177,111],{}," file beside the destination while updating a progress bar, verifies size and checksum, and renames into place — the same shape as an ",[26,1180,1182],{"href":1181},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fwriting-files-atomically-in-python-clis\u002F","atomic write",". If the connection drops, a later run can send a ",[14,1185,116],{}," header to fetch only the missing bytes. ",[26,1188,1190],{"href":1189},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fdownloading-files-with-progress-in-python\u002F","Downloading files with progress in Python"," puts it together with a Rich progress bar.",[46,1193,1195],{"id":1194},"testing-api-backed-commands","Testing API-backed commands",[10,1197,1198,1199,1202],{},"Tests for an API client should never hit the network. httpx ships ",[14,1200,1201],{},"httpx.MockTransport",", which routes requests to a Python function you write, so you can return canned responses, simulate failures and count calls without any extra dependency:",[179,1204,1206],{"className":181,"code":1205,"language":183,"meta":184,"style":184},"import httpx\n\nfrom mytool.api import ApiError, list_projects\n\n\ndef make_test_client(handler) -> httpx.Client:\n    return httpx.Client(base_url=\"https:\u002F\u002Fapi.test\", transport=httpx.MockTransport(handler))\n\n\ndef test_list_projects():\n    def handler(request: httpx.Request) -> httpx.Response:\n        assert request.url.path == \"\u002Fprojects\"\n        return httpx.Response(200, json=[{\"name\": \"web\", \"owner\": \"ana\", \"build_count\": 3}])\n\n    projects = list_projects(make_test_client(handler))\n    assert [p.name for p in projects] == [\"web\"]\n\n\ndef test_unauthorised_is_a_clear_error():\n    client = make_test_client(lambda request: httpx.Response(401))\n    try:\n        list_projects(client)\n    except ApiError as exc:\n        assert exc.exit_code == 4\n        assert \"mytool login\" in str(exc)\n    else:\n        raise AssertionError(\"expected ApiError\")\n",[14,1207,1208,1214,1218,1230,1234,1238,1248,1273,1277,1281,1291,1301,1314,1363,1367,1377,1403,1407,1411,1420,1442,1449,1454,1468,1480,1496,1503],{"__ignoreMap":184},[188,1209,1210,1212],{"class":190,"line":191},[188,1211,231],{"class":201},[188,1213,260],{"class":212},[188,1215,1216],{"class":190,"line":198},[188,1217,220],{"emptyLinePlaceholder":219},[188,1219,1220,1222,1225,1227],{"class":190,"line":216},[188,1221,202],{"class":201},[188,1223,1224],{"class":212}," mytool.api ",[188,1226,231],{"class":201},[188,1228,1229],{"class":212}," ApiError, list_projects\n",[188,1231,1232],{"class":190,"line":223},[188,1233,220],{"emptyLinePlaceholder":219},[188,1235,1236],{"class":190,"line":237},[188,1237,220],{"emptyLinePlaceholder":219},[188,1239,1240,1242,1245],{"class":190,"line":250},[188,1241,437],{"class":201},[188,1243,1244],{"class":276}," make_test_client",[188,1246,1247],{"class":212},"(handler) -> httpx.Client:\n",[188,1249,1250,1252,1255,1258,1260,1263,1265,1268,1270],{"class":190,"line":255},[188,1251,560],{"class":201},[188,1253,1254],{"class":212}," httpx.Client(",[188,1256,1257],{"class":283},"base_url",[188,1259,287],{"class":201},[188,1261,1262],{"class":473},"\"https:\u002F\u002Fapi.test\"",[188,1264,504],{"class":212},[188,1266,1267],{"class":283},"transport",[188,1269,287],{"class":201},[188,1271,1272],{"class":212},"httpx.MockTransport(handler))\n",[188,1274,1275],{"class":190,"line":263},[188,1276,220],{"emptyLinePlaceholder":219},[188,1278,1279],{"class":190,"line":268},[188,1280,220],{"emptyLinePlaceholder":219},[188,1282,1283,1285,1288],{"class":190,"line":273},[188,1284,437],{"class":201},[188,1286,1287],{"class":276}," test_list_projects",[188,1289,1290],{"class":212},"():\n",[188,1292,1293,1295,1298],{"class":190,"line":296},[188,1294,363],{"class":201},[188,1296,1297],{"class":276}," handler",[188,1299,1300],{"class":212},"(request: httpx.Request) -> httpx.Response:\n",[188,1302,1303,1306,1309,1311],{"class":190,"line":308},[188,1304,1305],{"class":201},"        assert",[188,1307,1308],{"class":212}," request.url.path ",[188,1310,704],{"class":201},[188,1312,1313],{"class":473}," \"\u002Fprojects\"\n",[188,1315,1316,1319,1322,1325,1327,1330,1332,1335,1337,1339,1342,1344,1346,1348,1351,1353,1355,1357,1360],{"class":190,"line":317},[188,1317,1318],{"class":201},"        return",[188,1320,1321],{"class":212}," httpx.Response(",[188,1323,1324],{"class":205},"200",[188,1326,504],{"class":212},[188,1328,1329],{"class":283},"json",[188,1331,287],{"class":201},[188,1333,1334],{"class":212},"[{",[188,1336,750],{"class":473},[188,1338,477],{"class":212},[188,1340,1341],{"class":473},"\"web\"",[188,1343,504],{"class":212},[188,1345,756],{"class":473},[188,1347,477],{"class":212},[188,1349,1350],{"class":473},"\"ana\"",[188,1352,504],{"class":212},[188,1354,761],{"class":473},[188,1356,477],{"class":212},[188,1358,1359],{"class":205},"3",[188,1361,1362],{"class":212},"}])\n",[188,1364,1365],{"class":190,"line":325},[188,1366,220],{"emptyLinePlaceholder":219},[188,1368,1369,1372,1374],{"class":190,"line":334},[188,1370,1371],{"class":212},"    projects ",[188,1373,287],{"class":201},[188,1375,1376],{"class":212}," list_projects(make_test_client(handler))\n",[188,1378,1379,1382,1385,1387,1389,1391,1394,1396,1399,1401],{"class":190,"line":339},[188,1380,1381],{"class":201},"    assert",[188,1383,1384],{"class":212}," [p.name ",[188,1386,767],{"class":201},[188,1388,770],{"class":212},[188,1390,773],{"class":201},[188,1392,1393],{"class":212}," projects] ",[188,1395,704],{"class":201},[188,1397,1398],{"class":212}," [",[188,1400,1341],{"class":473},[188,1402,1052],{"class":212},[188,1404,1405],{"class":190,"line":344},[188,1406,220],{"emptyLinePlaceholder":219},[188,1408,1409],{"class":190,"line":360},[188,1410,220],{"emptyLinePlaceholder":219},[188,1412,1413,1415,1418],{"class":190,"line":395},[188,1414,437],{"class":201},[188,1416,1417],{"class":276}," test_unauthorised_is_a_clear_error",[188,1419,1290],{"class":212},[188,1421,1422,1425,1427,1430,1433,1436,1439],{"class":190,"line":410},[188,1423,1424],{"class":212},"    client ",[188,1426,287],{"class":201},[188,1428,1429],{"class":212}," make_test_client(",[188,1431,1432],{"class":201},"lambda",[188,1434,1435],{"class":212}," request: httpx.Response(",[188,1437,1438],{"class":205},"401",[188,1440,1441],{"class":212},"))\n",[188,1443,1444,1447],{"class":190,"line":424},[188,1445,1446],{"class":201},"    try",[188,1448,305],{"class":212},[188,1450,1451],{"class":190,"line":429},[188,1452,1453],{"class":212},"        list_projects(client)\n",[188,1455,1456,1459,1462,1465],{"class":190,"line":434},[188,1457,1458],{"class":201},"    except",[188,1460,1461],{"class":212}," ApiError ",[188,1463,1464],{"class":201},"as",[188,1466,1467],{"class":212}," exc:\n",[188,1469,1470,1472,1475,1477],{"class":190,"line":462},[188,1471,1305],{"class":201},[188,1473,1474],{"class":212}," exc.exit_code ",[188,1476,704],{"class":201},[188,1478,1479],{"class":205}," 4\n",[188,1481,1482,1484,1487,1490,1493],{"class":190,"line":518},[188,1483,1305],{"class":201},[188,1485,1486],{"class":473}," \"mytool login\"",[188,1488,1489],{"class":201}," in",[188,1491,1492],{"class":205}," str",[188,1494,1495],{"class":212},"(exc)\n",[188,1497,1498,1501],{"class":190,"line":527},[188,1499,1500],{"class":201},"    else",[188,1502,305],{"class":212},[188,1504,1505,1507,1510,1512,1515],{"class":190,"line":557},[188,1506,715],{"class":201},[188,1508,1509],{"class":205}," AssertionError",[188,1511,280],{"class":212},[188,1513,1514],{"class":473},"\"expected ApiError\"",[188,1516,293],{"class":212},[10,1518,1519,1520,1523,1524,1528,1529,831,1532,1535],{},"Because commands receive the client rather than creating it deep inside, a test can build the command's context with a mock-transport client and run the command end to end through ",[14,1521,1522],{},"CliRunner",". That pattern — construct collaborators at the edge, pass them in — is covered in ",[26,1525,1527],{"href":1526},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fdependency-injection-patterns-for-cli-commands\u002F","dependency injection patterns for CLI commands",". For recording real responses once and replaying them, libraries such as ",[14,1530,1531],{},"respx",[14,1533,1534],{},"pytest-recording"," build on the same transport hook.",[46,1537,1539],{"id":1538},"proxies-certificates-and-corporate-networks","Proxies, certificates and corporate networks",[10,1541,1542],{},"Internal tools run inside corporate networks more often than anywhere else, and those networks are where HTTP clients fail in confusing ways. Three things are worth handling deliberately.",[10,1544,1545,1548,1549,504,1552,504,1555,166,1558,1561,1562,1565],{},[57,1546,1547],{},"Proxies."," httpx honours ",[14,1550,1551],{},"HTTP_PROXY",[14,1553,1554],{},"HTTPS_PROXY",[14,1556,1557],{},"ALL_PROXY",[14,1559,1560],{},"NO_PROXY"," from the environment by default (",[14,1563,1564],{},"trust_env=True","). Keep that default — users behind a proxy have already configured those variables for every other tool — and mention them in your connection-error message, because \"cannot connect\" behind a misconfigured proxy is otherwise baffling.",[10,1567,1568,1571,1572,1575,1576,1579,1580,1583,1584,1587,1588,1591],{},[57,1569,1570],{},"Custom certificate authorities."," Many companies intercept TLS with their own root certificate. Requests then fail with ",[14,1573,1574],{},"CERTIFICATE_VERIFY_FAILED",", and the tempting fix is ",[14,1577,1578],{},"verify=False",", which disables the protection entirely. Instead, let users point at their bundle: honour ",[14,1581,1582],{},"SSL_CERT_FILE"," (httpx does, through ",[14,1585,1586],{},"trust_env","), and consider the ",[14,1589,1590],{},"truststore"," package, which makes Python use the operating system's certificate store — the one IT has already configured.",[10,1593,1594,1597,1598,1601,1602,1605,1606,40],{},[57,1595,1596],{},"Base URLs per environment."," Staging and production usually differ only in the host. Make the base URL a setting with the normal precedence — ",[14,1599,1600],{},"--api-url"," flag, ",[14,1603,1604],{},"MYTOOL_API_URL"," variable, config file, built-in default — so one binary works everywhere without code changes. The mechanics are in ",[26,1607,1609],{"href":1608},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fconfig-precedence-flags-env-files-defaults\u002F","config precedence: flags, env, files and defaults",[46,1611,1613],{"id":1612},"key-takeaways","Key takeaways",[51,1615,1616,1619,1628,1631,1634,1637,1640],{},[54,1617,1618],{},"Put every HTTP call behind an API client module that returns typed objects and raises one error type; commands only render.",[54,1620,1621,1622,1624,1625,1627],{},"Create one configured ",[14,1623,62],{}," per run for connection reuse, a proper ",[14,1626,67],{}," and consistent auth.",[54,1629,1630],{},"Choose connect and read timeouts deliberately and add an overall deadline where users need one.",[54,1632,1633],{},"Report 4xx errors clearly; retry 429, 5xx and network errors with capped, jittered backoff, and only for idempotent requests.",[54,1635,1636],{},"Paginate with generators so limits stop early and \"all\" streams.",[54,1638,1639],{},"Prefer device-flow login or personal access tokens over passwords; keep tokens in the keychain.",[54,1641,1642,1643,1645],{},"Test with ",[14,1644,1201],{}," — no network, no extra dependencies.",[46,1647,1649],{"id":1648},"frequently-asked-questions","Frequently asked questions",[1651,1652,1654,1655,831,1657,1659],"h3",{"id":1653},"should-i-use-requests-or-httpx-for-a-new-cli","Should I use ",[14,1656,129],{},[14,1658,23],{}," for a new CLI?",[10,1661,1662,1663,1665,1666,1668,1669,1672],{},"Either works; ",[14,1664,23],{}," is the better default for new code because of its timeout model, built-in mock transport, HTTP\u002F2 support and matching async API. If your team already has a ",[14,1667,129],{},"-based client with retries configured through ",[14,1670,1671],{},"urllib3",", there is no urgency to migrate.",[1651,1674,1676],{"id":1675},"how-do-i-let-users-point-the-cli-at-a-staging-server","How do I let users point the CLI at a staging server?",[10,1678,1679,1680,1682,1683,1685,1686,1689],{},"Make the base URL a setting with the usual precedence: a ",[14,1681,1600],{}," flag, then a ",[14,1684,1604],{}," environment variable, then the config file, then a built-in default. Print it in ",[14,1687,1688],{},"--verbose"," output so users can always see which server they are talking to.",[1651,1691,1693],{"id":1692},"how-do-i-debug-what-the-cli-sends","How do I debug what the CLI sends?",[10,1695,1696,1697,1700,1701,1704,1705,1708,1709,40],{},"Add a ",[14,1698,1699],{},"--debug"," flag that enables httpx's logging (",[14,1702,1703],{},"logging.getLogger(\"httpx\").setLevel(logging.DEBUG)","), or install event hooks that log method, URL, status and timing. Redact the ",[14,1706,1707],{},"Authorization"," header before anything is printed — see ",[26,1710,1712],{"href":1711},"\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",[1651,1714,1716,1717,1720],{"id":1715},"when-should-i-switch-to-httpxasyncclient","When should I switch to ",[14,1718,1719],{},"httpx.AsyncClient","?",[10,1722,1723,1724,166,1728,40],{},"When a command makes many independent requests and the total time matters — fetching details for 200 items, for example. A thread pool with a sync client is often simpler; the trade-offs are in ",[26,1725,1727],{"href":1726},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fparallelising-cli-work-with-thread-pools\u002F","parallelising CLI work with thread pools",[26,1729,1731],{"href":1730},"\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",[1651,1733,1735],{"id":1734},"how-should-the-cli-cope-with-api-version-changes","How should the CLI cope with API version changes?",[10,1737,1738,1739,1742,1743,1746,1747,831,1750,1753],{},"Pin the API version explicitly — in the URL path (",[14,1740,1741],{},"\u002Fv2\u002F",") or an ",[14,1744,1745],{},"Accept"," or version header — rather than taking whatever the server currently defaults to, so a server upgrade cannot silently change the shape of responses under an old CLI release. Parse responses into your own typed objects and ignore unknown fields, which lets the server add data without breaking you. When the server announces deprecations through a header such as ",[14,1748,1749],{},"Deprecation",[14,1751,1752],{},"Sunset",", surface a one-line warning on stderr so users upgrade the CLI before the old version is switched off.",[1651,1755,1757],{"id":1756},"does-importing-httpx-slow-down-my-clis-startup","Does importing httpx slow down my CLI's startup?",[10,1759,1760,1761,1764,1765,40],{},"It adds tens of milliseconds, which matters if you care about fast ",[14,1762,1763],{},"--help"," and shell completion. Import it inside the API module and import that module lazily from the commands that need it; the technique is in ",[26,1766,1768],{"href":1767},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup\u002F","lazy-loading subcommands for faster startup",[46,1770,1772],{"id":1771},"related","Related",[51,1774,1775,1780,1785,1789,1793,1797,1801,1807],{},[54,1776,1777,1778],{},"Up: ",[26,1779,29],{"href":28},[54,1781,1782,1783],{},"Down: ",[26,1784,791],{"href":790},[54,1786,1782,1787],{},[26,1788,879],{"href":878},[54,1790,1782,1791],{},[26,1792,1112],{"href":1111},[54,1794,1782,1795],{},[26,1796,1155],{"href":1154},[54,1798,1782,1799],{},[26,1800,1190],{"href":1189},[54,1802,1803,1804],{},"Sideways: ",[26,1805,1806],{"href":33},"Concurrency and async in Python CLIs",[54,1808,1803,1809],{},[26,1810,1811],{"href":38},"Secrets and credentials in Python CLIs",[1813,1814,1815],"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 .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}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);}",{"title":184,"searchDepth":198,"depth":198,"links":1817},[1818,1819,1821,1822,1823,1824,1825,1826,1827,1828,1829,1839],{"id":48,"depth":198,"text":49},{"id":120,"depth":198,"text":1820},"Why httpx, and why one client",{"id":795,"depth":198,"text":796},{"id":842,"depth":198,"text":843},{"id":883,"depth":198,"text":884},{"id":1119,"depth":198,"text":1120},{"id":1163,"depth":198,"text":1164},{"id":1194,"depth":198,"text":1195},{"id":1538,"depth":198,"text":1539},{"id":1612,"depth":198,"text":1613},{"id":1648,"depth":198,"text":1649,"children":1830},[1831,1833,1834,1835,1837,1838],{"id":1653,"depth":216,"text":1832},"Should I use requests or httpx for a new CLI?",{"id":1675,"depth":216,"text":1676},{"id":1692,"depth":216,"text":1693},{"id":1715,"depth":216,"text":1836},"When should I switch to httpx.AsyncClient?",{"id":1734,"depth":216,"text":1735},{"id":1756,"depth":216,"text":1757},{"id":1771,"depth":198,"text":1772},"2026-09-18","Build API-backed Python CLIs that stay dependable: an httpx client module, timeouts, retries with backoff, pagination, device-flow login and resumable downloads.","intermediate",false,"md",{},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis",{"title":5,"description":1841},"cli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Findex",[1850,23,1851,626,1852],"http","api","oauth","Iy8IPnfKit9uS24bSDale7Z68Rehf5iPhJ89-k10s2g",[1855,1858,1861,1864,1867,1870,1873,1876,1879,1882,1885,1888,1891,1894,1897,1900,1903,1906,1909,1912,1915,1918,1921,1924,1927,1930,1933,1936,1939,1942,1945,1948,1951,1954,1957,1960,1963,1966,1969,1972,1975,1978,1981,1984,1987,1990,1993,1996,1999,2002,2005,2008,2011,2014,2017,2020,2023,2026,2027,2030,2033,2036,2039,2042,2045,2048,2051,2054,2057,2060,2063,2066,2069,2072,2075,2078,2081,2084,2087,2090,2093,2096,2099,2102,2105,2108,2111,2114,2117,2120,2123,2126,2129,2132,2135,2138,2141,2144,2147,2150,2153,2156,2159,2162,2165,2168,2171,2174,2177,2180,2183,2186,2189,2192,2195,2198,2201,2204,2207,2210,2213,2216,2219,2222,2225,2228,2231,2234,2237,2240,2243,2246,2249,2252,2255,2258,2261,2264,2267,2270,2273,2276,2279,2282,2285,2288,2291,2294,2297,2300,2303,2306,2309,2312,2315,2318,2321,2324,2327,2330,2333,2336,2339,2342,2345,2348,2351,2354,2357,2360,2363,2366,2369,2372,2375,2378,2381,2384,2387,2390,2393,2396,2399],{"path":1856,"title":1857},"\u002Fabout","About Python CLI Toolcraft",{"path":1859,"title":1860},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies","Advanced Argument Validation Strategies",{"path":1862,"title":1863},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fparsing-nested-json-arguments-in-python-clis","Parsing Nested JSON Args in Python CLIs",{"path":1865,"title":1866},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-dependent-and-conflicting-options","Validating Dependent and Conflicting CLI Options",{"path":1868,"title":1869},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-file-and-directory-paths-in-clis","Validating File and Directory Paths in CLIs",{"path":1871,"title":1872},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fwriting-custom-click-parameter-types","Writing Custom Click Parameter Types",{"path":1874,"title":1875},"\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":1877,"title":1878},"\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":1880,"title":1881},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual","Building Terminal UIs with Textual for Python CLIs",{"path":1883,"title":1884},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Ftesting-textual-apps-with-pilot","Testing Textual Apps with Pilot",{"path":1886,"title":1887},"\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":1889,"title":1890},"\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":1892,"title":1893},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation","CLI Help Output and Documentation",{"path":1895,"title":1896},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fversioning-and-deprecating-cli-flags","Versioning and Deprecating CLI Flags",{"path":1898,"title":1899},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fwriting-help-text-users-actually-read","Writing Help Text Users Actually Read",{"path":1901,"title":1902},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fadapting-output-to-terminal-width","Adapting Python CLI Output to Terminal Width",{"path":1904,"title":1905},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fdetecting-ci-environments-and-non-interactive-shells","Detecting CI Environments and Non-Interactive Shells",{"path":1907,"title":1908},"\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":1910,"title":1911},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility","Cross-Platform Terminal Compatibility for Python CLIs",{"path":1913,"title":1914},"\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":1916,"title":1917},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fchoosing-exit-codes-for-cli-tools","Choosing Exit Codes for CLI Tools",{"path":1919,"title":1920},"\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":1922,"title":1923},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Ffriendly-error-messages-and-tracebacks","Friendly Error Messages and Tracebacks",{"path":1925,"title":1926},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fhandling-keyboard-interrupt-cleanly","Handling Keyboard Interrupt Cleanly",{"path":1928,"title":1929},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes","Error Handling and Exit Codes for CLIs",{"path":1931,"title":1932},"\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":1934,"title":1935},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fconfig-precedence-flags-env-files-defaults","Config Precedence: Flags, Env, Files, Defaults",{"path":1937,"title":1938},"\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":1940,"title":1941},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars","Handling Config Files and Env Vars in CLIs",{"path":1943,"title":1944},"\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":1946,"title":1947},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Freading-toml-config-with-tomllib","Reading TOML Config with tomllib in Python CLIs",{"path":1949,"title":1950},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Ftyped-settings-with-pydantic-settings","Typed Settings with pydantic-settings in Python CLIs",{"path":1952,"title":1953},"\u002Fadvanced-input-parsing-user-experience","Advanced Input Parsing for Python CLIs",{"path":1955,"title":1956},"\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":1958,"title":1959},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Fbuilding-interactive-prompts-and-menus","Building Interactive Prompts and Menus in Python CLIs",{"path":1961,"title":1962},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich","Interactive Terminal UI with Rich",{"path":1964,"title":1965},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Flive-dashboards-with-rich-live","Live Dashboards with Rich Live in Python CLIs",{"path":1967,"title":1968},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Frendering-tables-and-json-with-rich","Rendering Tables and JSON with Rich",{"path":1970,"title":1971},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Ftheming-rich-output-consistently","Theming Rich Output Consistently in Python CLIs",{"path":1973,"title":1974},"\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":1976,"title":1977},"\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":1979,"title":1980},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis","Shell Completion for Python CLIs",{"path":1982,"title":1983},"\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":1985,"title":1986},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Ftesting-shell-completion-in-python-clis","Testing Shell Completion in Python CLIs",{"path":1988,"title":1989},"\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":1991,"title":1992},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-verbose-and-quiet-logging-flags","Adding Verbose and Quiet Logging Flags",{"path":1994,"title":1995},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps","Structured Logging for CLI Apps",{"path":1997,"title":1998},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fstructured-json-logging-in-python-clis","Structured JSON Logging in Python CLIs",{"path":2000,"title":2001},"\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":2003,"title":2004},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fdetecting-tty-and-adapting-output","Detecting a TTY and Adapting Output",{"path":2006,"title":2007},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Femitting-json-output-for-scripting","Emitting JSON Output for Scripting",{"path":2009,"title":2010},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fhandling-broken-pipe-and-sigpipe","Handling Broken Pipe and SIGPIPE",{"path":2012,"title":2013},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes","Working with stdin, stdout and Pipes",{"path":2015,"title":2016},"\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":2018,"title":2019},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Freading-piped-input-in-python-clis","Reading Piped Input in Python CLIs",{"path":2021,"title":2022},"\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":2024,"title":2025},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fdownloading-files-with-progress-in-python","Downloading Files with Progress in Python CLIs",{"path":1846,"title":5},{"path":2028,"title":2029},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Foauth-device-flow-login-for-clis","OAuth Device Flow Login for Python CLIs",{"path":2031,"title":2032},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fpaginating-api-results-in-a-cli","Paginating API Results in a Python CLI",{"path":2034,"title":2035},"\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":2037,"title":2038},"\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":2040,"title":2041},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis","Concurrency and Async in Python CLIs",{"path":2043,"title":2044},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fmultiprocessing-for-cpu-bound-cli-tasks","Multiprocessing for CPU-Bound CLI Tasks",{"path":2046,"title":2047},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fparallelising-cli-work-with-thread-pools","Parallelising CLI Work with Thread Pools",{"path":2049,"title":2050},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Frate-limiting-concurrent-requests-in-clis","Rate-Limiting Concurrent Requests in Python CLIs",{"path":2052,"title":2053},"\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":2055,"title":2056},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fcross-platform-paths-with-pathlib","Cross-Platform Paths with pathlib in CLIs",{"path":2058,"title":2059},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Ffile-locking-for-concurrent-cli-runs","File Locking for Concurrent CLI Runs in Python",{"path":2061,"title":2062},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes","Filesystem Paths and Atomic Writes for CLIs",{"path":2064,"title":2065},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fsafe-temporary-files-and-directories","Safe Temporary Files and Directories in CLIs",{"path":2067,"title":2068},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fstoring-app-data-with-platformdirs","Storing CLI App Data with platformdirs",{"path":2070,"title":2071},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fwriting-files-atomically-in-python-clis","Writing Files Atomically in Python CLIs",{"path":2073,"title":2074},"\u002Fcli-runtime-systems-integration","CLI Runtime & Systems Integration for Python",{"path":2076,"title":2077},"\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":2079,"title":2080},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fhandling-sigterm-and-graceful-shutdown","Handling SIGTERM and Graceful Shutdown in CLIs",{"path":2082,"title":2083},"\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":2085,"title":2086},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis","Long-Running and Watch-Mode Python CLIs",{"path":2088,"title":2089},"\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":2091,"title":2092},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Favoiding-shell-injection-in-python-clis","Avoiding Shell Injection in Python CLIs",{"path":2094,"title":2095},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fcalling-external-commands-safely-with-subprocess","Calling External Commands Safely with subprocess",{"path":2097,"title":2098},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fhandling-subprocess-timeouts-and-exit-codes","Handling Subprocess Timeouts and Exit Codes",{"path":2100,"title":2101},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis","Running Subprocesses from Python CLIs",{"path":2103,"title":2104},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fstreaming-subprocess-output-in-real-time","Streaming Subprocess Output in Real Time",{"path":2106,"title":2107},"\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":2109,"title":2110},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis","Secrets and Credentials in Python CLIs",{"path":2112,"title":2113},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fprompting-for-passwords-securely","Prompting for Passwords Securely in Python CLIs",{"path":2115,"title":2116},"\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":2118,"title":2119},"\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":2121,"title":2122},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fstoring-tokens-with-keyring","Storing CLI Tokens Securely with keyring",{"path":2124,"title":2125},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fsupporting-multiple-profiles-and-accounts","Supporting Multiple Profiles and Accounts in CLIs",{"path":2127,"title":2128},"\u002F","Python CLI Toolcraft",{"path":2130,"title":2131},"\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":2133,"title":2134},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading","CLI Startup Performance and Lazy Loading",{"path":2136,"title":2137},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup","Lazy Loading Subcommands for Faster Startup",{"path":2139,"title":2140},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fprofiling-python-cli-startup-time","Profiling Python CLI Startup Time",{"path":2142,"title":2143},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Freducing-cli-dependency-weight","Reducing CLI Dependency Weight",{"path":2145,"title":2146},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-subparsers-for-subcommands","argparse Subparsers for Subcommands",{"path":2148,"title":2149},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-vs-click-vs-typer-comparison","argparse vs Click vs Typer Compared",{"path":2151,"title":2152},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse","Command-Line Parsing with argparse",{"path":2154,"title":2155},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmigrating-from-argparse-to-typer","Migrating from argparse to Typer",{"path":2157,"title":2158},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmutually-exclusive-options-in-argparse","Mutually Exclusive Options in argparse",{"path":2160,"title":2161},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fwriting-custom-argparse-actions","Writing Custom argparse Actions in Python",{"path":2163,"title":2164},"\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":2166,"title":2167},"\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":2169,"title":2170},"\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":2172,"title":2173},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions","Designing CLI Interfaces and Conventions in Python",{"path":2175,"title":2176},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fnaming-commands-and-flags-consistently","Naming Commands and Flags Consistently in Python CLIs",{"path":2178,"title":2179},"\u002Fmodern-python-cli-frameworks-architecture","Python CLI Frameworks and Architecture",{"path":2181,"title":2182},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fdiscovering-plugins-with-entry-points","Discovering Plugins with Entry Points in Python CLIs",{"path":2184,"title":2185},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fhook-based-plugins-with-pluggy","Hook-Based Plugins for Python CLIs with pluggy",{"path":2187,"title":2188},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis","Plugin Architectures for Extensible CLIs",{"path":2190,"title":2191},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fversioning-a-plugin-api","Versioning a Plugin API for a Python CLI",{"path":2193,"title":2194},"\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":2196,"title":2197},"\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":2199,"title":2200},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fdependency-injection-patterns-for-cli-commands","Dependency Injection Patterns for CLI Commands",{"path":2202,"title":2203},"\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":2205,"title":2206},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis","Structuring Multi-Command Python CLIs",{"path":2208,"title":2209},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-common-options-across-commands","Sharing Common Options Across Python CLI Commands",{"path":2211,"title":2212},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-state-with-click-context-objects","Sharing State with Click Context Objects",{"path":2214,"title":2215},"\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":2217,"title":2218},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications","Testing Python CLI Applications",{"path":2220,"title":2221},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fmeasuring-cli-test-coverage","Measuring CLI Test Coverage",{"path":2223,"title":2224},"\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":2226,"title":2227},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fproperty-based-testing-cli-arguments-with-hypothesis","Property-Based Testing CLI Arguments with Hypothesis",{"path":2229,"title":2230},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fsnapshot-testing-cli-output","Snapshot Testing CLI Output",{"path":2232,"title":2233},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-click-commands-with-clirunner","Testing Click Commands with CliRunner",{"path":2235,"title":2236},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-interactive-prompts-and-stdin","Testing Interactive Prompts and stdin",{"path":2238,"title":2239},"\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":2241,"title":2242},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fbuilding-dynamic-commands-in-click","Building Dynamic Commands in Click",{"path":2244,"title":2245},"\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":2247,"title":2248},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each","Typer vs Click: When to Use Each",{"path":2250,"title":2251},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Ftyper-callback-functions-explained","Typer callback functions explained",{"path":2253,"title":2254},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fusing-annotated-options-in-typer","Using Annotated Options in Typer",{"path":2256,"title":2257},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fautomating-releases-from-git-tags","Automating Python CLI Releases from Git Tags",{"path":2259,"title":2260},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fcaching-uv-dependencies-in-ci","Caching uv Dependencies in CI for Python CLIs",{"path":2262,"title":2263},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis","CI\u002FCD Pipelines for Python CLIs",{"path":2265,"title":2266},"\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":2268,"title":2269},"\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":2271,"title":2272},"\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":2274,"title":2275},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fbuilding-a-cookiecutter-template-for-typer-clis","Building a Cookiecutter Template for Typer CLIs",{"path":2277,"title":2278},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fcopier-vs-cookiecutter-for-cli-templates","Copier vs Cookiecutter for CLI Templates",{"path":2280,"title":2281},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter","CLI Project Scaffolding with Cookiecutter",{"path":2283,"title":2284},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fpost-generation-hooks-in-cli-templates","Post-Generation Hooks in Python CLI Templates",{"path":2286,"title":2287},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbuilding-cross-platform-release-binaries-in-ci","Building Cross-Platform Release Binaries in CI",{"path":2289,"title":2290},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbundling-a-python-cli-with-pyinstaller","Bundling a Python CLI with PyInstaller",{"path":2292,"title":2293},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fhomebrew-and-scoop-packaging-for-python-clis","Homebrew and Scoop Packaging for Python CLIs",{"path":2295,"title":2296},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries","Distributing CLIs as Standalone Binaries",{"path":2298,"title":2299},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fnuitka-vs-pyinstaller-for-python-clis","Nuitka vs PyInstaller for Python CLI Binaries",{"path":2301,"title":2302},"\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":2304,"title":2305},"\u002Fproject-setup-dependency-management","Project Setup & Dependency Management",{"path":2307,"title":2308},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Fconfiguring-ruff-for-a-cli-project","Configuring Ruff for a Python CLI Project",{"path":2310,"title":2311},"\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":2313,"title":2314},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code","Linting and Type-Checking Python CLI Code",{"path":2316,"title":2317},"\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":2319,"title":2320},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fautomating-changelogs-with-conventional-commits","Automating Changelogs with Conventional Commits",{"path":2322,"title":2323},"\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":2325,"title":2326},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fexposing-version-info-and-build-metadata","Exposing Version Info and Build Metadata",{"path":2328,"title":2329},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs","Managing CLI Versioning & Changelogs",{"path":2331,"title":2332},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fsemantic-versioning-policy-for-cli-tools","A Semantic Versioning Policy for CLI Tools",{"path":2334,"title":2335},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbuilding-wheels-and-sdists-for-python-clis","Building Wheels and sdists for Python CLIs",{"path":2337,"title":2338},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbundling-data-files-with-importlib-resources","Bundling Data Files with importlib.resources in CLIs",{"path":2340,"title":2341},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution","Packaging Python CLIs for Distribution",{"path":2343,"title":2344},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Finstalling-and-distributing-clis-with-pipx","Installing and Distributing CLIs with pipx",{"path":2346,"title":2347},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fpublishing-a-python-cli-to-pypi","Publishing a Python CLI to PyPI",{"path":2349,"title":2350},"\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":2352,"title":2353},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development","Poetry Workflows for CLI Development",{"path":2355,"title":2356},"\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":2358,"title":2359},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-dependency-groups-for-cli-tooling","Poetry Dependency Groups for CLI Tooling",{"path":2361,"title":2362},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-entry-points-and-scripts-for-clis","Poetry Entry Points and Scripts for CLIs",{"path":2364,"title":2365},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects","Pre-commit Hooks for CLI Projects",{"path":2367,"title":2368},"\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":2370,"title":2371},"\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":2373,"title":2374},"\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":2376,"title":2377},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management","uv for Python CLI Dependency Management",{"path":2379,"title":2380},"\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":2382,"title":2383},"\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":2385,"title":2386},"\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":2388,"title":2389},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fuv-workspaces-for-multi-package-clis","uv Workspaces for Multi-Package Python CLIs",{"path":2391,"title":2392},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices","Python CLI Env Isolation Best Practices",{"path":2394,"title":2395},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fmanaging-virtual-environments-for-cross-platform-clis","Managing Python CLI Virtual Environments",{"path":2397,"title":2398},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fpinning-the-python-version-for-a-cli","Pinning the Python Version for a CLI",{"path":2400,"title":2401},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fsupporting-multiple-python-versions-with-nox","Supporting Multiple Python Versions with nox",1789736905048]