[{"data":1,"prerenderedAt":3474},["ShallowReactive",2],{"page-\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Foauth-device-flow-login-for-clis\u002F":3,"content-directory":2927},{"id":4,"title":5,"body":6,"date":2913,"description":2914,"difficulty":2915,"draft":2916,"extension":2917,"meta":2918,"navigation":180,"path":2919,"seo":2920,"stem":2921,"tags":2922,"updated":2913,"__hash__":2926},"content\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Foauth-device-flow-login-for-clis\u002Findex.md","OAuth Device Flow Login for Python CLIs",{"type":7,"value":8,"toc":2895},"minimark",[9,41,46,81,85,88,92,135,139,1148,1151,1154,1206,1209,1216,1838,1854,1858,1861,1920,1924,1931,2783,2798,2802,2808,2812,2817,2820,2824,2827,2835,2838,2842,2856,2860,2891],[10,11,12,13,17,18,21,22,26,27,30,31,34,35,40],"p",{},"Your CLI needs to act on behalf of a user against an API protected by your organisation's identity provider — Okta, Entra ID, Auth0, Keycloak, GitHub. Asking for a username and password is out: it breaks with single sign-on and multi-factor authentication, and it trains people to type their most sensitive credential into programs. The standard answer, used by ",[14,15,16],"code",{},"gh auth login",", ",[14,19,20],{},"az login --use-device-code"," and most cloud CLIs, is the ",[23,24,25],"strong",{},"OAuth 2.0 device authorization grant"," (RFC 8628). The CLI shows a short code and a URL; the user approves in any browser, with whatever SSO and MFA their organisation requires; the CLI receives tokens. This guide implements that flow with ",[14,28,29],{},"httpx",", handles every polling response correctly, and wires it into a ",[14,32,33],{},"login"," command. It belongs to the ",[36,37,39],"a",{"href":38},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002F","HTTP APIs topic",".",[42,43,45],"h2",{"id":44},"prerequisites","Prerequisites",[47,48,49,60,78],"ul",{},[50,51,52,53,55,56,59],"li",{},"Python 3.10+ and ",[14,54,29],{},"; ",[14,57,58],{},"keyring"," for token storage.",[50,61,62,63,66,67,70,71,74,75,40],{},"An OAuth client registered with your identity provider with the device grant enabled. You need its ",[23,64,65],{},"client ID",", the ",[23,68,69],{},"device authorization endpoint"," and the ",[23,72,73],{},"token endpoint"," — all listed in the provider's discovery document at ",[14,76,77],{},"\u002F.well-known\u002Fopenid-configuration",[50,79,80],{},"A public client (no client secret). CLIs cannot keep secrets; the device flow is designed for exactly that constraint.",[42,82,84],{"id":83},"how-the-device-flow-works","How the device flow works",[10,86,87],{},"The flow involves three parties: your CLI, the authorisation server, and the user's browser — which can be on a different machine, such as a phone approving a login on a headless server.",[89,90],"inline-diagram",{"name":91},"http-device-flow",[93,94,95,102,120,123,132],"ol",{},[50,96,97,98,101],{},"The CLI ",[14,99,100],{},"POST","s its client ID and requested scopes to the device authorization endpoint.",[50,103,104,105,108,109,112,113,116,117,40],{},"The server returns a ",[14,106,107],{},"device_code"," (secret, for the CLI), a short ",[14,110,111],{},"user_code"," (for the human), a ",[14,114,115],{},"verification_uri",", an expiry, and a polling ",[14,118,119],{},"interval",[50,121,122],{},"The CLI shows the code and URL. The user opens the URL, signs in however their organisation requires, enters the code and approves.",[50,124,125,126,128,129,131],{},"Meanwhile the CLI polls the token endpoint with the ",[14,127,107],{},", waiting ",[14,130,119],{}," seconds between attempts.",[50,133,134],{},"Once the user approves, the token endpoint returns an access token and usually a refresh token.",[42,136,138],{"id":137},"the-recipe","The recipe",[140,141,146],"pre",{"className":142,"code":143,"language":144,"meta":145,"style":145},"language-python shiki shiki-themes github-light github-dark","# src\u002Fmytool\u002Fdevice_login.py\nfrom __future__ import annotations\n\nimport time\nfrom collections.abc import Callable\nfrom dataclasses import dataclass\n\nimport httpx\n\nGRANT = \"urn:ietf:params:oauth:grant-type:device_code\"\n\n\nclass LoginError(Exception):\n    pass\n\n\n@dataclass(frozen=True)\nclass DeviceCode:\n    device_code: str\n    user_code: str\n    verification_uri: str\n    verification_uri_complete: str | None\n    expires_in: int\n    interval: int\n\n\n@dataclass(frozen=True)\nclass Tokens:\n    access_token: str\n    refresh_token: str | None\n    expires_in: int | None\n\n\ndef start(client: httpx.Client, device_url: str, client_id: str, scope: str) -> DeviceCode:\n    r = client.post(device_url, data={\"client_id\": client_id, \"scope\": scope},\n                    headers={\"Accept\": \"application\u002Fjson\"})\n    if r.is_error:\n        raise LoginError(f\"could not start login ({r.status_code}): {r.text[:200]}\")\n    body = r.json()\n    return DeviceCode(\n        device_code=body[\"device_code\"],\n        user_code=body[\"user_code\"],\n        verification_uri=body[\"verification_uri\"],\n        verification_uri_complete=body.get(\"verification_uri_complete\"),\n        expires_in=int(body.get(\"expires_in\", 900)),\n        interval=int(body.get(\"interval\", 5)),\n    )\n\n\ndef poll(client: httpx.Client, token_url: str, client_id: str, code: DeviceCode, *,\n         sleep: Callable[[float], None] = time.sleep,\n         clock: Callable[[], float] = time.monotonic) -> Tokens:\n    deadline = clock() + code.expires_in\n    interval = code.interval\n    while clock() \u003C deadline:\n        sleep(interval)\n        r = client.post(token_url, headers={\"Accept\": \"application\u002Fjson\"}, data={\n            \"grant_type\": GRANT, \"device_code\": code.device_code, \"client_id\": client_id,\n        })\n        body = r.json()\n        if r.is_success and \"access_token\" in body:\n            return Tokens(body[\"access_token\"], body.get(\"refresh_token\"), body.get(\"expires_in\"))\n        error = body.get(\"error\")\n        if error == \"authorization_pending\":\n            continue\n        if error == \"slow_down\":\n            interval += 5                      # RFC 8628 §3.5\n            continue\n        if error == \"access_denied\":\n            raise LoginError(\"login was declined in the browser\")\n        if error == \"expired_token\":\n            break\n        raise LoginError(f\"login failed: {error or r.status_code} {body.get('error_description', '')}\")\n    raise LoginError(\"the code expired before it was approved — run login again\")\n","python","",[14,147,148,157,175,182,191,204,217,222,230,235,248,253,258,277,283,288,293,314,325,334,342,350,365,374,382,387,392,407,417,425,437,449,454,459,486,517,539,548,592,603,612,629,644,659,676,700,722,728,733,738,764,787,802,819,830,844,850,884,906,912,922,943,969,985,1001,1007,1021,1036,1041,1055,1068,1082,1088,1135],{"__ignoreMap":145},[149,150,153],"span",{"class":151,"line":152},"line",1,[149,154,156],{"class":155},"sJ8bj","# src\u002Fmytool\u002Fdevice_login.py\n",[149,158,160,164,168,171],{"class":151,"line":159},2,[149,161,163],{"class":162},"szBVR","from",[149,165,167],{"class":166},"sj4cs"," __future__",[149,169,170],{"class":162}," import",[149,172,174],{"class":173},"sVt8B"," annotations\n",[149,176,178],{"class":151,"line":177},3,[149,179,181],{"emptyLinePlaceholder":180},true,"\n",[149,183,185,188],{"class":151,"line":184},4,[149,186,187],{"class":162},"import",[149,189,190],{"class":173}," time\n",[149,192,194,196,199,201],{"class":151,"line":193},5,[149,195,163],{"class":162},[149,197,198],{"class":173}," collections.abc ",[149,200,187],{"class":162},[149,202,203],{"class":173}," Callable\n",[149,205,207,209,212,214],{"class":151,"line":206},6,[149,208,163],{"class":162},[149,210,211],{"class":173}," dataclasses ",[149,213,187],{"class":162},[149,215,216],{"class":173}," dataclass\n",[149,218,220],{"class":151,"line":219},7,[149,221,181],{"emptyLinePlaceholder":180},[149,223,225,227],{"class":151,"line":224},8,[149,226,187],{"class":162},[149,228,229],{"class":173}," httpx\n",[149,231,233],{"class":151,"line":232},9,[149,234,181],{"emptyLinePlaceholder":180},[149,236,238,241,244],{"class":151,"line":237},10,[149,239,240],{"class":166},"GRANT",[149,242,243],{"class":162}," =",[149,245,247],{"class":246},"sZZnC"," \"urn:ietf:params:oauth:grant-type:device_code\"\n",[149,249,251],{"class":151,"line":250},11,[149,252,181],{"emptyLinePlaceholder":180},[149,254,256],{"class":151,"line":255},12,[149,257,181],{"emptyLinePlaceholder":180},[149,259,261,264,268,271,274],{"class":151,"line":260},13,[149,262,263],{"class":162},"class",[149,265,267],{"class":266},"sScJk"," LoginError",[149,269,270],{"class":173},"(",[149,272,273],{"class":166},"Exception",[149,275,276],{"class":173},"):\n",[149,278,280],{"class":151,"line":279},14,[149,281,282],{"class":162},"    pass\n",[149,284,286],{"class":151,"line":285},15,[149,287,181],{"emptyLinePlaceholder":180},[149,289,291],{"class":151,"line":290},16,[149,292,181],{"emptyLinePlaceholder":180},[149,294,296,299,301,305,308,311],{"class":151,"line":295},17,[149,297,298],{"class":266},"@dataclass",[149,300,270],{"class":173},[149,302,304],{"class":303},"s4XuR","frozen",[149,306,307],{"class":162},"=",[149,309,310],{"class":166},"True",[149,312,313],{"class":173},")\n",[149,315,317,319,322],{"class":151,"line":316},18,[149,318,263],{"class":162},[149,320,321],{"class":266}," DeviceCode",[149,323,324],{"class":173},":\n",[149,326,328,331],{"class":151,"line":327},19,[149,329,330],{"class":173},"    device_code: ",[149,332,333],{"class":166},"str\n",[149,335,337,340],{"class":151,"line":336},20,[149,338,339],{"class":173},"    user_code: ",[149,341,333],{"class":166},[149,343,345,348],{"class":151,"line":344},21,[149,346,347],{"class":173},"    verification_uri: ",[149,349,333],{"class":166},[149,351,353,356,359,362],{"class":151,"line":352},22,[149,354,355],{"class":173},"    verification_uri_complete: ",[149,357,358],{"class":166},"str",[149,360,361],{"class":162}," |",[149,363,364],{"class":166}," None\n",[149,366,368,371],{"class":151,"line":367},23,[149,369,370],{"class":173},"    expires_in: ",[149,372,373],{"class":166},"int\n",[149,375,377,380],{"class":151,"line":376},24,[149,378,379],{"class":173},"    interval: ",[149,381,373],{"class":166},[149,383,385],{"class":151,"line":384},25,[149,386,181],{"emptyLinePlaceholder":180},[149,388,390],{"class":151,"line":389},26,[149,391,181],{"emptyLinePlaceholder":180},[149,393,395,397,399,401,403,405],{"class":151,"line":394},27,[149,396,298],{"class":266},[149,398,270],{"class":173},[149,400,304],{"class":303},[149,402,307],{"class":162},[149,404,310],{"class":166},[149,406,313],{"class":173},[149,408,410,412,415],{"class":151,"line":409},28,[149,411,263],{"class":162},[149,413,414],{"class":266}," Tokens",[149,416,324],{"class":173},[149,418,420,423],{"class":151,"line":419},29,[149,421,422],{"class":173},"    access_token: ",[149,424,333],{"class":166},[149,426,428,431,433,435],{"class":151,"line":427},30,[149,429,430],{"class":173},"    refresh_token: ",[149,432,358],{"class":166},[149,434,361],{"class":162},[149,436,364],{"class":166},[149,438,440,442,445,447],{"class":151,"line":439},31,[149,441,370],{"class":173},[149,443,444],{"class":166},"int",[149,446,361],{"class":162},[149,448,364],{"class":166},[149,450,452],{"class":151,"line":451},32,[149,453,181],{"emptyLinePlaceholder":180},[149,455,457],{"class":151,"line":456},33,[149,458,181],{"emptyLinePlaceholder":180},[149,460,462,465,468,471,473,476,478,481,483],{"class":151,"line":461},34,[149,463,464],{"class":162},"def",[149,466,467],{"class":266}," start",[149,469,470],{"class":173},"(client: httpx.Client, device_url: ",[149,472,358],{"class":166},[149,474,475],{"class":173},", client_id: ",[149,477,358],{"class":166},[149,479,480],{"class":173},", scope: ",[149,482,358],{"class":166},[149,484,485],{"class":173},") -> DeviceCode:\n",[149,487,489,492,494,497,500,502,505,508,511,514],{"class":151,"line":488},35,[149,490,491],{"class":173},"    r ",[149,493,307],{"class":162},[149,495,496],{"class":173}," client.post(device_url, ",[149,498,499],{"class":303},"data",[149,501,307],{"class":162},[149,503,504],{"class":173},"{",[149,506,507],{"class":246},"\"client_id\"",[149,509,510],{"class":173},": client_id, ",[149,512,513],{"class":246},"\"scope\"",[149,515,516],{"class":173},": scope},\n",[149,518,520,523,525,527,530,533,536],{"class":151,"line":519},36,[149,521,522],{"class":303},"                    headers",[149,524,307],{"class":162},[149,526,504],{"class":173},[149,528,529],{"class":246},"\"Accept\"",[149,531,532],{"class":173},": ",[149,534,535],{"class":246},"\"application\u002Fjson\"",[149,537,538],{"class":173},"})\n",[149,540,542,545],{"class":151,"line":541},37,[149,543,544],{"class":162},"    if",[149,546,547],{"class":173}," r.is_error:\n",[149,549,551,554,557,560,563,565,568,571,574,576,579,582,585,587,590],{"class":151,"line":550},38,[149,552,553],{"class":162},"        raise",[149,555,556],{"class":173}," LoginError(",[149,558,559],{"class":162},"f",[149,561,562],{"class":246},"\"could not start login (",[149,564,504],{"class":166},[149,566,567],{"class":173},"r.status_code",[149,569,570],{"class":166},"}",[149,572,573],{"class":246},"): ",[149,575,504],{"class":166},[149,577,578],{"class":173},"r.text[:",[149,580,581],{"class":166},"200",[149,583,584],{"class":173},"]",[149,586,570],{"class":166},[149,588,589],{"class":246},"\"",[149,591,313],{"class":173},[149,593,595,598,600],{"class":151,"line":594},39,[149,596,597],{"class":173},"    body ",[149,599,307],{"class":162},[149,601,602],{"class":173}," r.json()\n",[149,604,606,609],{"class":151,"line":605},40,[149,607,608],{"class":162},"    return",[149,610,611],{"class":173}," DeviceCode(\n",[149,613,615,618,620,623,626],{"class":151,"line":614},41,[149,616,617],{"class":303},"        device_code",[149,619,307],{"class":162},[149,621,622],{"class":173},"body[",[149,624,625],{"class":246},"\"device_code\"",[149,627,628],{"class":173},"],\n",[149,630,632,635,637,639,642],{"class":151,"line":631},42,[149,633,634],{"class":303},"        user_code",[149,636,307],{"class":162},[149,638,622],{"class":173},[149,640,641],{"class":246},"\"user_code\"",[149,643,628],{"class":173},[149,645,647,650,652,654,657],{"class":151,"line":646},43,[149,648,649],{"class":303},"        verification_uri",[149,651,307],{"class":162},[149,653,622],{"class":173},[149,655,656],{"class":246},"\"verification_uri\"",[149,658,628],{"class":173},[149,660,662,665,667,670,673],{"class":151,"line":661},44,[149,663,664],{"class":303},"        verification_uri_complete",[149,666,307],{"class":162},[149,668,669],{"class":173},"body.get(",[149,671,672],{"class":246},"\"verification_uri_complete\"",[149,674,675],{"class":173},"),\n",[149,677,679,682,684,686,689,692,694,697],{"class":151,"line":678},45,[149,680,681],{"class":303},"        expires_in",[149,683,307],{"class":162},[149,685,444],{"class":166},[149,687,688],{"class":173},"(body.get(",[149,690,691],{"class":246},"\"expires_in\"",[149,693,17],{"class":173},[149,695,696],{"class":166},"900",[149,698,699],{"class":173},")),\n",[149,701,703,706,708,710,712,715,717,720],{"class":151,"line":702},46,[149,704,705],{"class":303},"        interval",[149,707,307],{"class":162},[149,709,444],{"class":166},[149,711,688],{"class":173},[149,713,714],{"class":246},"\"interval\"",[149,716,17],{"class":173},[149,718,719],{"class":166},"5",[149,721,699],{"class":173},[149,723,725],{"class":151,"line":724},47,[149,726,727],{"class":173},"    )\n",[149,729,731],{"class":151,"line":730},48,[149,732,181],{"emptyLinePlaceholder":180},[149,734,736],{"class":151,"line":735},49,[149,737,181],{"emptyLinePlaceholder":180},[149,739,741,743,746,749,751,753,755,758,761],{"class":151,"line":740},50,[149,742,464],{"class":162},[149,744,745],{"class":266}," poll",[149,747,748],{"class":173},"(client: httpx.Client, token_url: ",[149,750,358],{"class":166},[149,752,475],{"class":173},[149,754,358],{"class":166},[149,756,757],{"class":173},", code: DeviceCode, ",[149,759,760],{"class":162},"*",[149,762,763],{"class":173},",\n",[149,765,767,770,773,776,779,782,784],{"class":151,"line":766},51,[149,768,769],{"class":173},"         sleep: Callable[[",[149,771,772],{"class":166},"float",[149,774,775],{"class":173},"], ",[149,777,778],{"class":166},"None",[149,780,781],{"class":173},"] ",[149,783,307],{"class":162},[149,785,786],{"class":173}," time.sleep,\n",[149,788,790,793,795,797,799],{"class":151,"line":789},52,[149,791,792],{"class":173},"         clock: Callable[[], ",[149,794,772],{"class":166},[149,796,781],{"class":173},[149,798,307],{"class":162},[149,800,801],{"class":173}," time.monotonic) -> Tokens:\n",[149,803,805,808,810,813,816],{"class":151,"line":804},53,[149,806,807],{"class":173},"    deadline ",[149,809,307],{"class":162},[149,811,812],{"class":173}," clock() ",[149,814,815],{"class":162},"+",[149,817,818],{"class":173}," code.expires_in\n",[149,820,822,825,827],{"class":151,"line":821},54,[149,823,824],{"class":173},"    interval ",[149,826,307],{"class":162},[149,828,829],{"class":173}," code.interval\n",[149,831,833,836,838,841],{"class":151,"line":832},55,[149,834,835],{"class":162},"    while",[149,837,812],{"class":173},[149,839,840],{"class":162},"\u003C",[149,842,843],{"class":173}," deadline:\n",[149,845,847],{"class":151,"line":846},56,[149,848,849],{"class":173},"        sleep(interval)\n",[149,851,853,856,858,861,864,866,868,870,872,874,877,879,881],{"class":151,"line":852},57,[149,854,855],{"class":173},"        r ",[149,857,307],{"class":162},[149,859,860],{"class":173}," client.post(token_url, ",[149,862,863],{"class":303},"headers",[149,865,307],{"class":162},[149,867,504],{"class":173},[149,869,529],{"class":246},[149,871,532],{"class":173},[149,873,535],{"class":246},[149,875,876],{"class":173},"}, ",[149,878,499],{"class":303},[149,880,307],{"class":162},[149,882,883],{"class":173},"{\n",[149,885,887,890,892,894,896,898,901,903],{"class":151,"line":886},58,[149,888,889],{"class":246},"            \"grant_type\"",[149,891,532],{"class":173},[149,893,240],{"class":166},[149,895,17],{"class":173},[149,897,625],{"class":246},[149,899,900],{"class":173},": code.device_code, ",[149,902,507],{"class":246},[149,904,905],{"class":173},": client_id,\n",[149,907,909],{"class":151,"line":908},59,[149,910,911],{"class":173},"        })\n",[149,913,915,918,920],{"class":151,"line":914},60,[149,916,917],{"class":173},"        body ",[149,919,307],{"class":162},[149,921,602],{"class":173},[149,923,925,928,931,934,937,940],{"class":151,"line":924},61,[149,926,927],{"class":162},"        if",[149,929,930],{"class":173}," r.is_success ",[149,932,933],{"class":162},"and",[149,935,936],{"class":246}," \"access_token\"",[149,938,939],{"class":162}," in",[149,941,942],{"class":173}," body:\n",[149,944,946,949,952,955,958,961,964,966],{"class":151,"line":945},62,[149,947,948],{"class":162},"            return",[149,950,951],{"class":173}," Tokens(body[",[149,953,954],{"class":246},"\"access_token\"",[149,956,957],{"class":173},"], body.get(",[149,959,960],{"class":246},"\"refresh_token\"",[149,962,963],{"class":173},"), body.get(",[149,965,691],{"class":246},[149,967,968],{"class":173},"))\n",[149,970,972,975,977,980,983],{"class":151,"line":971},63,[149,973,974],{"class":173},"        error ",[149,976,307],{"class":162},[149,978,979],{"class":173}," body.get(",[149,981,982],{"class":246},"\"error\"",[149,984,313],{"class":173},[149,986,988,990,993,996,999],{"class":151,"line":987},64,[149,989,927],{"class":162},[149,991,992],{"class":173}," error ",[149,994,995],{"class":162},"==",[149,997,998],{"class":246}," \"authorization_pending\"",[149,1000,324],{"class":173},[149,1002,1004],{"class":151,"line":1003},65,[149,1005,1006],{"class":162},"            continue\n",[149,1008,1010,1012,1014,1016,1019],{"class":151,"line":1009},66,[149,1011,927],{"class":162},[149,1013,992],{"class":173},[149,1015,995],{"class":162},[149,1017,1018],{"class":246}," \"slow_down\"",[149,1020,324],{"class":173},[149,1022,1024,1027,1030,1033],{"class":151,"line":1023},67,[149,1025,1026],{"class":173},"            interval ",[149,1028,1029],{"class":162},"+=",[149,1031,1032],{"class":166}," 5",[149,1034,1035],{"class":155},"                      # RFC 8628 §3.5\n",[149,1037,1039],{"class":151,"line":1038},68,[149,1040,1006],{"class":162},[149,1042,1044,1046,1048,1050,1053],{"class":151,"line":1043},69,[149,1045,927],{"class":162},[149,1047,992],{"class":173},[149,1049,995],{"class":162},[149,1051,1052],{"class":246}," \"access_denied\"",[149,1054,324],{"class":173},[149,1056,1058,1061,1063,1066],{"class":151,"line":1057},70,[149,1059,1060],{"class":162},"            raise",[149,1062,556],{"class":173},[149,1064,1065],{"class":246},"\"login was declined in the browser\"",[149,1067,313],{"class":173},[149,1069,1071,1073,1075,1077,1080],{"class":151,"line":1070},71,[149,1072,927],{"class":162},[149,1074,992],{"class":173},[149,1076,995],{"class":162},[149,1078,1079],{"class":246}," \"expired_token\"",[149,1081,324],{"class":173},[149,1083,1085],{"class":151,"line":1084},72,[149,1086,1087],{"class":162},"            break\n",[149,1089,1091,1093,1095,1097,1100,1102,1105,1108,1111,1113,1116,1118,1121,1123,1126,1129,1131,1133],{"class":151,"line":1090},73,[149,1092,553],{"class":162},[149,1094,556],{"class":173},[149,1096,559],{"class":162},[149,1098,1099],{"class":246},"\"login failed: ",[149,1101,504],{"class":166},[149,1103,1104],{"class":173},"error ",[149,1106,1107],{"class":162},"or",[149,1109,1110],{"class":173}," r.status_code",[149,1112,570],{"class":166},[149,1114,1115],{"class":166}," {",[149,1117,669],{"class":173},[149,1119,1120],{"class":246},"'error_description'",[149,1122,17],{"class":173},[149,1124,1125],{"class":246},"''",[149,1127,1128],{"class":173},")",[149,1130,570],{"class":166},[149,1132,589],{"class":246},[149,1134,313],{"class":173},[149,1136,1138,1141,1143,1146],{"class":151,"line":1137},74,[149,1139,1140],{"class":162},"    raise",[149,1142,556],{"class":173},[149,1144,1145],{"class":246},"\"the code expired before it was approved — run login again\"",[149,1147,313],{"class":173},[10,1149,1150],{},"The polling loop is where most hand-written implementations go wrong, so the rules are worth stating plainly:",[89,1152],{"name":1153},"http-poll-states",[47,1155,1156,1169,1178,1187,1200],{},[50,1157,1158,1161,1162,1164,1165,1168],{},[23,1159,1160],{},"Wait before each poll",", including the first, and use the server's ",[14,1163,119],{}," (default 5 seconds). Polling faster gets you ",[14,1166,1167],{},"slow_down"," and, with some providers, a temporary block.",[50,1170,1171,1177],{},[23,1172,1173,1174,1176],{},"On ",[14,1175,1167],{},", increase the interval by five seconds"," and keep it increased — that is what RFC 8628 requires.",[50,1179,1180,1186],{},[23,1181,1182,1185],{},[14,1183,1184],{},"authorization_pending"," is normal",", not an error; it means \"keep waiting\".",[50,1188,1189,1199],{},[23,1190,1191,1192,1195,1196],{},"Stop on ",[14,1193,1194],{},"access_denied"," and ",[14,1197,1198],{},"expired_token",", and on anything unrecognised, with a message that says what to do.",[50,1201,1202,1205],{},[23,1203,1204],{},"Respect the overall expiry."," Use a monotonic clock so a system clock change cannot extend or cut the window.",[10,1207,1208],{},"Sleep and clock are injected, so the tests below can drive every branch instantly.",[42,1210,1212,1213,1215],{"id":1211},"the-login-command","The ",[14,1214,33],{}," command",[140,1217,1219],{"className":142,"code":1218,"language":144,"meta":145,"style":145},"# src\u002Fmytool\u002Fcli.py\nimport webbrowser\n\nimport httpx\nimport keyring\nimport typer\n\nfrom mytool.device_login import LoginError, poll, start\n\napp = typer.Typer()\n\nISSUER = \"https:\u002F\u002Flogin.example.com\"\nCLIENT_ID = \"mytool-cli\"\nSCOPE = \"openid offline_access api.read api.write\"\n\n\n@app.callback()\ndef main() -> None:\n    \"\"\"mytool command line.\"\"\"\n\n\n@app.command()\ndef login(no_browser: bool = typer.Option(False, \"--no-browser\")) -> None:\n    \"\"\"Sign in through your browser.\"\"\"\n    with httpx.Client(timeout=httpx.Timeout(15.0, connect=5.0)) as client:\n        try:\n            code = start(client, f\"{ISSUER}\u002Foauth\u002Fdevice\u002Fcode\", CLIENT_ID, SCOPE)\n            typer.echo(f\"Open {code.verification_uri} and enter the code:\\n\", err=True)\n            typer.secho(f\"    {code.user_code}\\n\", bold=True, err=True)\n            if not no_browser and code.verification_uri_complete:\n                webbrowser.open(code.verification_uri_complete)\n            minutes = code.expires_in \u002F\u002F 60\n            typer.echo(f\"Waiting for approval (expires in {minutes} minutes)...\", err=True)\n            tokens = poll(client, f\"{ISSUER}\u002Foauth\u002Ftoken\", CLIENT_ID, code)\n        except LoginError as exc:\n            typer.secho(f\"error: {exc}\", fg=\"red\", err=True)\n            raise typer.Exit(1)\n        except KeyboardInterrupt:\n            typer.echo(\"\\nlogin cancelled\", err=True)\n            raise typer.Exit(130)\n    keyring.set_password(\"mytool\", \"access_token\", tokens.access_token)\n    if tokens.refresh_token:\n        keyring.set_password(\"mytool\", \"refresh_token\", tokens.refresh_token)\n    typer.echo(\"Logged in. Token stored in the system keychain.\", err=True)\n\n\nif __name__ == \"__main__\":\n    app()\n",[14,1220,1221,1226,1233,1237,1243,1250,1257,1261,1273,1277,1287,1291,1301,1311,1321,1325,1329,1337,1351,1356,1360,1364,1371,1404,1409,1447,1454,1484,1520,1559,1575,1580,1596,1625,1651,1664,1702,1714,1723,1744,1755,1770,1777,1791,1809,1813,1817,1833],{"__ignoreMap":145},[149,1222,1223],{"class":151,"line":152},[149,1224,1225],{"class":155},"# src\u002Fmytool\u002Fcli.py\n",[149,1227,1228,1230],{"class":151,"line":159},[149,1229,187],{"class":162},[149,1231,1232],{"class":173}," webbrowser\n",[149,1234,1235],{"class":151,"line":177},[149,1236,181],{"emptyLinePlaceholder":180},[149,1238,1239,1241],{"class":151,"line":184},[149,1240,187],{"class":162},[149,1242,229],{"class":173},[149,1244,1245,1247],{"class":151,"line":193},[149,1246,187],{"class":162},[149,1248,1249],{"class":173}," keyring\n",[149,1251,1252,1254],{"class":151,"line":206},[149,1253,187],{"class":162},[149,1255,1256],{"class":173}," typer\n",[149,1258,1259],{"class":151,"line":219},[149,1260,181],{"emptyLinePlaceholder":180},[149,1262,1263,1265,1268,1270],{"class":151,"line":224},[149,1264,163],{"class":162},[149,1266,1267],{"class":173}," mytool.device_login ",[149,1269,187],{"class":162},[149,1271,1272],{"class":173}," LoginError, poll, start\n",[149,1274,1275],{"class":151,"line":232},[149,1276,181],{"emptyLinePlaceholder":180},[149,1278,1279,1282,1284],{"class":151,"line":237},[149,1280,1281],{"class":173},"app ",[149,1283,307],{"class":162},[149,1285,1286],{"class":173}," typer.Typer()\n",[149,1288,1289],{"class":151,"line":250},[149,1290,181],{"emptyLinePlaceholder":180},[149,1292,1293,1296,1298],{"class":151,"line":255},[149,1294,1295],{"class":166},"ISSUER",[149,1297,243],{"class":162},[149,1299,1300],{"class":246}," \"https:\u002F\u002Flogin.example.com\"\n",[149,1302,1303,1306,1308],{"class":151,"line":260},[149,1304,1305],{"class":166},"CLIENT_ID",[149,1307,243],{"class":162},[149,1309,1310],{"class":246}," \"mytool-cli\"\n",[149,1312,1313,1316,1318],{"class":151,"line":279},[149,1314,1315],{"class":166},"SCOPE",[149,1317,243],{"class":162},[149,1319,1320],{"class":246}," \"openid offline_access api.read api.write\"\n",[149,1322,1323],{"class":151,"line":285},[149,1324,181],{"emptyLinePlaceholder":180},[149,1326,1327],{"class":151,"line":290},[149,1328,181],{"emptyLinePlaceholder":180},[149,1330,1331,1334],{"class":151,"line":295},[149,1332,1333],{"class":266},"@app.callback",[149,1335,1336],{"class":173},"()\n",[149,1338,1339,1341,1344,1347,1349],{"class":151,"line":316},[149,1340,464],{"class":162},[149,1342,1343],{"class":266}," main",[149,1345,1346],{"class":173},"() -> ",[149,1348,778],{"class":166},[149,1350,324],{"class":173},[149,1352,1353],{"class":151,"line":327},[149,1354,1355],{"class":246},"    \"\"\"mytool command line.\"\"\"\n",[149,1357,1358],{"class":151,"line":336},[149,1359,181],{"emptyLinePlaceholder":180},[149,1361,1362],{"class":151,"line":344},[149,1363,181],{"emptyLinePlaceholder":180},[149,1365,1366,1369],{"class":151,"line":352},[149,1367,1368],{"class":266},"@app.command",[149,1370,1336],{"class":173},[149,1372,1373,1375,1378,1381,1384,1386,1389,1392,1394,1397,1400,1402],{"class":151,"line":367},[149,1374,464],{"class":162},[149,1376,1377],{"class":266}," login",[149,1379,1380],{"class":173},"(no_browser: ",[149,1382,1383],{"class":166},"bool",[149,1385,243],{"class":162},[149,1387,1388],{"class":173}," typer.Option(",[149,1390,1391],{"class":166},"False",[149,1393,17],{"class":173},[149,1395,1396],{"class":246},"\"--no-browser\"",[149,1398,1399],{"class":173},")) -> ",[149,1401,778],{"class":166},[149,1403,324],{"class":173},[149,1405,1406],{"class":151,"line":376},[149,1407,1408],{"class":246},"    \"\"\"Sign in through your browser.\"\"\"\n",[149,1410,1411,1414,1417,1420,1422,1425,1428,1430,1433,1435,1438,1441,1444],{"class":151,"line":384},[149,1412,1413],{"class":162},"    with",[149,1415,1416],{"class":173}," httpx.Client(",[149,1418,1419],{"class":303},"timeout",[149,1421,307],{"class":162},[149,1423,1424],{"class":173},"httpx.Timeout(",[149,1426,1427],{"class":166},"15.0",[149,1429,17],{"class":173},[149,1431,1432],{"class":303},"connect",[149,1434,307],{"class":162},[149,1436,1437],{"class":166},"5.0",[149,1439,1440],{"class":173},")) ",[149,1442,1443],{"class":162},"as",[149,1445,1446],{"class":173}," client:\n",[149,1448,1449,1452],{"class":151,"line":389},[149,1450,1451],{"class":162},"        try",[149,1453,324],{"class":173},[149,1455,1456,1459,1461,1464,1466,1468,1471,1474,1476,1478,1480,1482],{"class":151,"line":394},[149,1457,1458],{"class":173},"            code ",[149,1460,307],{"class":162},[149,1462,1463],{"class":173}," start(client, ",[149,1465,559],{"class":162},[149,1467,589],{"class":246},[149,1469,1470],{"class":166},"{ISSUER}",[149,1472,1473],{"class":246},"\u002Foauth\u002Fdevice\u002Fcode\"",[149,1475,17],{"class":173},[149,1477,1305],{"class":166},[149,1479,17],{"class":173},[149,1481,1315],{"class":166},[149,1483,313],{"class":173},[149,1485,1486,1489,1491,1494,1496,1499,1501,1504,1507,1509,1511,1514,1516,1518],{"class":151,"line":409},[149,1487,1488],{"class":173},"            typer.echo(",[149,1490,559],{"class":162},[149,1492,1493],{"class":246},"\"Open ",[149,1495,504],{"class":166},[149,1497,1498],{"class":173},"code.verification_uri",[149,1500,570],{"class":166},[149,1502,1503],{"class":246}," and enter the code:",[149,1505,1506],{"class":166},"\\n",[149,1508,589],{"class":246},[149,1510,17],{"class":173},[149,1512,1513],{"class":303},"err",[149,1515,307],{"class":162},[149,1517,310],{"class":166},[149,1519,313],{"class":173},[149,1521,1522,1525,1527,1530,1532,1535,1538,1540,1542,1545,1547,1549,1551,1553,1555,1557],{"class":151,"line":419},[149,1523,1524],{"class":173},"            typer.secho(",[149,1526,559],{"class":162},[149,1528,1529],{"class":246},"\"    ",[149,1531,504],{"class":166},[149,1533,1534],{"class":173},"code.user_code",[149,1536,1537],{"class":166},"}\\n",[149,1539,589],{"class":246},[149,1541,17],{"class":173},[149,1543,1544],{"class":303},"bold",[149,1546,307],{"class":162},[149,1548,310],{"class":166},[149,1550,17],{"class":173},[149,1552,1513],{"class":303},[149,1554,307],{"class":162},[149,1556,310],{"class":166},[149,1558,313],{"class":173},[149,1560,1561,1564,1567,1570,1572],{"class":151,"line":427},[149,1562,1563],{"class":162},"            if",[149,1565,1566],{"class":162}," not",[149,1568,1569],{"class":173}," no_browser ",[149,1571,933],{"class":162},[149,1573,1574],{"class":173}," code.verification_uri_complete:\n",[149,1576,1577],{"class":151,"line":439},[149,1578,1579],{"class":173},"                webbrowser.open(code.verification_uri_complete)\n",[149,1581,1582,1585,1587,1590,1593],{"class":151,"line":451},[149,1583,1584],{"class":173},"            minutes ",[149,1586,307],{"class":162},[149,1588,1589],{"class":173}," code.expires_in ",[149,1591,1592],{"class":162},"\u002F\u002F",[149,1594,1595],{"class":166}," 60\n",[149,1597,1598,1600,1602,1605,1607,1610,1612,1615,1617,1619,1621,1623],{"class":151,"line":456},[149,1599,1488],{"class":173},[149,1601,559],{"class":162},[149,1603,1604],{"class":246},"\"Waiting for approval (expires in ",[149,1606,504],{"class":166},[149,1608,1609],{"class":173},"minutes",[149,1611,570],{"class":166},[149,1613,1614],{"class":246}," minutes)...\"",[149,1616,17],{"class":173},[149,1618,1513],{"class":303},[149,1620,307],{"class":162},[149,1622,310],{"class":166},[149,1624,313],{"class":173},[149,1626,1627,1630,1632,1635,1637,1639,1641,1644,1646,1648],{"class":151,"line":461},[149,1628,1629],{"class":173},"            tokens ",[149,1631,307],{"class":162},[149,1633,1634],{"class":173}," poll(client, ",[149,1636,559],{"class":162},[149,1638,589],{"class":246},[149,1640,1470],{"class":166},[149,1642,1643],{"class":246},"\u002Foauth\u002Ftoken\"",[149,1645,17],{"class":173},[149,1647,1305],{"class":166},[149,1649,1650],{"class":173},", code)\n",[149,1652,1653,1656,1659,1661],{"class":151,"line":488},[149,1654,1655],{"class":162},"        except",[149,1657,1658],{"class":173}," LoginError ",[149,1660,1443],{"class":162},[149,1662,1663],{"class":173}," exc:\n",[149,1665,1666,1668,1670,1673,1675,1678,1680,1682,1684,1687,1689,1692,1694,1696,1698,1700],{"class":151,"line":519},[149,1667,1524],{"class":173},[149,1669,559],{"class":162},[149,1671,1672],{"class":246},"\"error: ",[149,1674,504],{"class":166},[149,1676,1677],{"class":173},"exc",[149,1679,570],{"class":166},[149,1681,589],{"class":246},[149,1683,17],{"class":173},[149,1685,1686],{"class":303},"fg",[149,1688,307],{"class":162},[149,1690,1691],{"class":246},"\"red\"",[149,1693,17],{"class":173},[149,1695,1513],{"class":303},[149,1697,307],{"class":162},[149,1699,310],{"class":166},[149,1701,313],{"class":173},[149,1703,1704,1706,1709,1712],{"class":151,"line":541},[149,1705,1060],{"class":162},[149,1707,1708],{"class":173}," typer.Exit(",[149,1710,1711],{"class":166},"1",[149,1713,313],{"class":173},[149,1715,1716,1718,1721],{"class":151,"line":550},[149,1717,1655],{"class":162},[149,1719,1720],{"class":166}," KeyboardInterrupt",[149,1722,324],{"class":173},[149,1724,1725,1727,1729,1731,1734,1736,1738,1740,1742],{"class":151,"line":594},[149,1726,1488],{"class":173},[149,1728,589],{"class":246},[149,1730,1506],{"class":166},[149,1732,1733],{"class":246},"login cancelled\"",[149,1735,17],{"class":173},[149,1737,1513],{"class":303},[149,1739,307],{"class":162},[149,1741,310],{"class":166},[149,1743,313],{"class":173},[149,1745,1746,1748,1750,1753],{"class":151,"line":605},[149,1747,1060],{"class":162},[149,1749,1708],{"class":173},[149,1751,1752],{"class":166},"130",[149,1754,313],{"class":173},[149,1756,1757,1760,1763,1765,1767],{"class":151,"line":614},[149,1758,1759],{"class":173},"    keyring.set_password(",[149,1761,1762],{"class":246},"\"mytool\"",[149,1764,17],{"class":173},[149,1766,954],{"class":246},[149,1768,1769],{"class":173},", tokens.access_token)\n",[149,1771,1772,1774],{"class":151,"line":631},[149,1773,544],{"class":162},[149,1775,1776],{"class":173}," tokens.refresh_token:\n",[149,1778,1779,1782,1784,1786,1788],{"class":151,"line":646},[149,1780,1781],{"class":173},"        keyring.set_password(",[149,1783,1762],{"class":246},[149,1785,17],{"class":173},[149,1787,960],{"class":246},[149,1789,1790],{"class":173},", tokens.refresh_token)\n",[149,1792,1793,1796,1799,1801,1803,1805,1807],{"class":151,"line":661},[149,1794,1795],{"class":173},"    typer.echo(",[149,1797,1798],{"class":246},"\"Logged in. Token stored in the system keychain.\"",[149,1800,17],{"class":173},[149,1802,1513],{"class":303},[149,1804,307],{"class":162},[149,1806,310],{"class":166},[149,1808,313],{"class":173},[149,1810,1811],{"class":151,"line":678},[149,1812,181],{"emptyLinePlaceholder":180},[149,1814,1815],{"class":151,"line":702},[149,1816,181],{"emptyLinePlaceholder":180},[149,1818,1819,1822,1825,1828,1831],{"class":151,"line":724},[149,1820,1821],{"class":162},"if",[149,1823,1824],{"class":166}," __name__",[149,1826,1827],{"class":162}," ==",[149,1829,1830],{"class":246}," \"__main__\"",[149,1832,324],{"class":173},[149,1834,1835],{"class":151,"line":730},[149,1836,1837],{"class":173},"    app()\n",[10,1839,1840,1841,1845,1846,1849,1850,1853],{},"Tokens go to the operating system's keychain rather than a file; the details, including fallbacks for headless Linux machines, are in ",[36,1842,1844],{"href":1843},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fstoring-tokens-with-keyring\u002F","storing tokens with keyring",". Access tokens are short-lived, so other commands should refresh them using the refresh token (a normal ",[14,1847,1848],{},"grant_type=refresh_token"," POST to the token endpoint) and fall back to \"run ",[14,1851,1852],{},"mytool login","\" only when refreshing fails.",[42,1855,1857],{"id":1856},"ux-considerations","UX considerations",[89,1859],{"name":1860},"http-device-terminal",[47,1862,1863,1869,1882,1888,1897,1910],{},[50,1864,1865,1868],{},[23,1866,1867],{},"Make the code impossible to misread."," Put it on its own line, indented and bold. Most providers generate codes without ambiguous characters; do not reformat them.",[50,1870,1871,1874,1875,1878,1879,40],{},[23,1872,1873],{},"Offer to open the browser, never require it."," ",[14,1876,1877],{},"verification_uri_complete"," pre-fills the code, which saves typing on a desktop. On SSH sessions and containers there is no browser, which is the whole point of the device flow — so always print the URL and code too, and provide ",[14,1880,1881],{},"--no-browser",[50,1883,1884,1887],{},[23,1885,1886],{},"Say how long they have."," \"expires in 15 minutes\" prevents the user wandering off and coming back to an expired code.",[50,1889,1890,1893,1894,1896],{},[23,1891,1892],{},"Put everything on stderr."," A ",[14,1895,33],{}," command has no data output, and keeping its prompts off stdout means scripts wrapping it do not capture them.",[50,1898,1899,1902,1903,1906,1907,1909],{},[23,1900,1901],{},"Support a non-interactive path."," CI cannot approve in a browser. Accept a token from an environment variable (",[14,1904,1905],{},"MYTOOL_TOKEN",") so pipelines never need ",[14,1908,33],{}," at all.",[50,1911,1912,1915,1916,1919],{},[23,1913,1914],{},"Handle Ctrl+C gracefully."," Users abandon logins all the time. Exit 130 with a short message rather than a ",[14,1917,1918],{},"KeyboardInterrupt"," traceback.",[42,1921,1923],{"id":1922},"testing-the-behaviour","Testing the behaviour",[10,1925,1926,1927,1930],{},"Script the token endpoint's responses with ",[14,1928,1929],{},"httpx.MockTransport"," and inject a fake sleep and clock. Each branch of the polling loop gets a test, and none of them waits:",[140,1932,1934],{"className":142,"code":1933,"language":144,"meta":145,"style":145},"# tests\u002Ftest_device_login.py\nimport httpx\nimport pytest\n\nfrom mytool.device_login import DeviceCode, LoginError, poll\n\nCODE = DeviceCode(\"dev-123\", \"WDJB-MJHT\", \"https:\u002F\u002Flogin.test\u002Fdevice\", None, 900, 5)\n\n\ndef token_endpoint(*bodies):\n    it = iter(bodies)\n\n    def handler(request):\n        status, body = next(it)\n        assert b\"device_code=dev-123\" in request.content\n        return httpx.Response(status, json=body)\n\n    return httpx.Client(transport=httpx.MockTransport(handler))\n\n\nclass FakeClock:\n    def __init__(self):\n        self.now = 0.0\n        self.slept = []\n\n    def sleep(self, s):\n        self.slept.append(s)\n        self.now += s\n\n    def __call__(self):\n        return self.now\n\n\ndef test_pending_then_success():\n    client = token_endpoint(\n        (400, {\"error\": \"authorization_pending\"}),\n        (200, {\"access_token\": \"at\", \"refresh_token\": \"rt\", \"expires_in\": 3600}),\n    )\n    clock = FakeClock()\n    tokens = poll(client, \"https:\u002F\u002Flogin.test\u002Ftoken\", \"cli\", CODE, sleep=clock.sleep, clock=clock)\n    assert tokens.access_token == \"at\"\n    assert clock.slept == [5, 5]\n\n\ndef test_slow_down_increases_interval():\n    client = token_endpoint(\n        (400, {\"error\": \"slow_down\"}),\n        (400, {\"error\": \"authorization_pending\"}),\n        (200, {\"access_token\": \"at\"}),\n    )\n    clock = FakeClock()\n    poll(client, \"https:\u002F\u002Flogin.test\u002Ftoken\", \"cli\", CODE, sleep=clock.sleep, clock=clock)\n    assert clock.slept == [5, 10, 10]\n\n\ndef test_denied():\n    client = token_endpoint((400, {\"error\": \"access_denied\"}))\n    clock = FakeClock()\n    with pytest.raises(LoginError, match=\"declined\"):\n        poll(client, \"https:\u002F\u002Flogin.test\u002Ftoken\", \"cli\", CODE, sleep=clock.sleep, clock=clock)\n\n\ndef test_expiry_stops_polling():\n    short = DeviceCode(\"dev-123\", \"X\", \"u\", None, 12, 5)\n    client = token_endpoint(*[(400, {\"error\": \"authorization_pending\"})] * 10)\n    clock = FakeClock()\n    with pytest.raises(LoginError, match=\"expired\"):\n        poll(client, \"https:\u002F\u002Flogin.test\u002Ftoken\", \"cli\", short, sleep=clock.sleep, clock=clock)\n    assert len(clock.slept) == 3\n",[14,1935,1936,1941,1947,1954,1958,1969,1973,2010,2014,2018,2032,2045,2049,2060,2073,2089,2105,2109,2123,2127,2131,2140,2150,2163,2175,2179,2189,2196,2207,2211,2220,2230,2234,2238,2248,2258,2279,2314,2318,2328,2367,2380,2401,2405,2409,2418,2426,2443,2459,2475,2479,2487,2516,2539,2543,2547,2556,2579,2587,2604,2633,2637,2641,2650,2686,2720,2728,2743,2768],{"__ignoreMap":145},[149,1937,1938],{"class":151,"line":152},[149,1939,1940],{"class":155},"# tests\u002Ftest_device_login.py\n",[149,1942,1943,1945],{"class":151,"line":159},[149,1944,187],{"class":162},[149,1946,229],{"class":173},[149,1948,1949,1951],{"class":151,"line":177},[149,1950,187],{"class":162},[149,1952,1953],{"class":173}," pytest\n",[149,1955,1956],{"class":151,"line":184},[149,1957,181],{"emptyLinePlaceholder":180},[149,1959,1960,1962,1964,1966],{"class":151,"line":193},[149,1961,163],{"class":162},[149,1963,1267],{"class":173},[149,1965,187],{"class":162},[149,1967,1968],{"class":173}," DeviceCode, LoginError, poll\n",[149,1970,1971],{"class":151,"line":206},[149,1972,181],{"emptyLinePlaceholder":180},[149,1974,1975,1978,1980,1983,1986,1988,1991,1993,1996,1998,2000,2002,2004,2006,2008],{"class":151,"line":219},[149,1976,1977],{"class":166},"CODE",[149,1979,243],{"class":162},[149,1981,1982],{"class":173}," DeviceCode(",[149,1984,1985],{"class":246},"\"dev-123\"",[149,1987,17],{"class":173},[149,1989,1990],{"class":246},"\"WDJB-MJHT\"",[149,1992,17],{"class":173},[149,1994,1995],{"class":246},"\"https:\u002F\u002Flogin.test\u002Fdevice\"",[149,1997,17],{"class":173},[149,1999,778],{"class":166},[149,2001,17],{"class":173},[149,2003,696],{"class":166},[149,2005,17],{"class":173},[149,2007,719],{"class":166},[149,2009,313],{"class":173},[149,2011,2012],{"class":151,"line":224},[149,2013,181],{"emptyLinePlaceholder":180},[149,2015,2016],{"class":151,"line":232},[149,2017,181],{"emptyLinePlaceholder":180},[149,2019,2020,2022,2025,2027,2029],{"class":151,"line":237},[149,2021,464],{"class":162},[149,2023,2024],{"class":266}," token_endpoint",[149,2026,270],{"class":173},[149,2028,760],{"class":162},[149,2030,2031],{"class":173},"bodies):\n",[149,2033,2034,2037,2039,2042],{"class":151,"line":250},[149,2035,2036],{"class":173},"    it ",[149,2038,307],{"class":162},[149,2040,2041],{"class":166}," iter",[149,2043,2044],{"class":173},"(bodies)\n",[149,2046,2047],{"class":151,"line":255},[149,2048,181],{"emptyLinePlaceholder":180},[149,2050,2051,2054,2057],{"class":151,"line":260},[149,2052,2053],{"class":162},"    def",[149,2055,2056],{"class":266}," handler",[149,2058,2059],{"class":173},"(request):\n",[149,2061,2062,2065,2067,2070],{"class":151,"line":279},[149,2063,2064],{"class":173},"        status, body ",[149,2066,307],{"class":162},[149,2068,2069],{"class":166}," next",[149,2071,2072],{"class":173},"(it)\n",[149,2074,2075,2078,2081,2084,2086],{"class":151,"line":285},[149,2076,2077],{"class":162},"        assert",[149,2079,2080],{"class":162}," b",[149,2082,2083],{"class":246},"\"device_code=dev-123\"",[149,2085,939],{"class":162},[149,2087,2088],{"class":173}," request.content\n",[149,2090,2091,2094,2097,2100,2102],{"class":151,"line":290},[149,2092,2093],{"class":162},"        return",[149,2095,2096],{"class":173}," httpx.Response(status, ",[149,2098,2099],{"class":303},"json",[149,2101,307],{"class":162},[149,2103,2104],{"class":173},"body)\n",[149,2106,2107],{"class":151,"line":295},[149,2108,181],{"emptyLinePlaceholder":180},[149,2110,2111,2113,2115,2118,2120],{"class":151,"line":316},[149,2112,608],{"class":162},[149,2114,1416],{"class":173},[149,2116,2117],{"class":303},"transport",[149,2119,307],{"class":162},[149,2121,2122],{"class":173},"httpx.MockTransport(handler))\n",[149,2124,2125],{"class":151,"line":327},[149,2126,181],{"emptyLinePlaceholder":180},[149,2128,2129],{"class":151,"line":336},[149,2130,181],{"emptyLinePlaceholder":180},[149,2132,2133,2135,2138],{"class":151,"line":344},[149,2134,263],{"class":162},[149,2136,2137],{"class":266}," FakeClock",[149,2139,324],{"class":173},[149,2141,2142,2144,2147],{"class":151,"line":352},[149,2143,2053],{"class":162},[149,2145,2146],{"class":166}," __init__",[149,2148,2149],{"class":173},"(self):\n",[149,2151,2152,2155,2158,2160],{"class":151,"line":367},[149,2153,2154],{"class":166},"        self",[149,2156,2157],{"class":173},".now ",[149,2159,307],{"class":162},[149,2161,2162],{"class":166}," 0.0\n",[149,2164,2165,2167,2170,2172],{"class":151,"line":376},[149,2166,2154],{"class":166},[149,2168,2169],{"class":173},".slept ",[149,2171,307],{"class":162},[149,2173,2174],{"class":173}," []\n",[149,2176,2177],{"class":151,"line":384},[149,2178,181],{"emptyLinePlaceholder":180},[149,2180,2181,2183,2186],{"class":151,"line":389},[149,2182,2053],{"class":162},[149,2184,2185],{"class":266}," sleep",[149,2187,2188],{"class":173},"(self, s):\n",[149,2190,2191,2193],{"class":151,"line":394},[149,2192,2154],{"class":166},[149,2194,2195],{"class":173},".slept.append(s)\n",[149,2197,2198,2200,2202,2204],{"class":151,"line":409},[149,2199,2154],{"class":166},[149,2201,2157],{"class":173},[149,2203,1029],{"class":162},[149,2205,2206],{"class":173}," s\n",[149,2208,2209],{"class":151,"line":419},[149,2210,181],{"emptyLinePlaceholder":180},[149,2212,2213,2215,2218],{"class":151,"line":427},[149,2214,2053],{"class":162},[149,2216,2217],{"class":166}," __call__",[149,2219,2149],{"class":173},[149,2221,2222,2224,2227],{"class":151,"line":439},[149,2223,2093],{"class":162},[149,2225,2226],{"class":166}," self",[149,2228,2229],{"class":173},".now\n",[149,2231,2232],{"class":151,"line":451},[149,2233,181],{"emptyLinePlaceholder":180},[149,2235,2236],{"class":151,"line":456},[149,2237,181],{"emptyLinePlaceholder":180},[149,2239,2240,2242,2245],{"class":151,"line":461},[149,2241,464],{"class":162},[149,2243,2244],{"class":266}," test_pending_then_success",[149,2246,2247],{"class":173},"():\n",[149,2249,2250,2253,2255],{"class":151,"line":488},[149,2251,2252],{"class":173},"    client ",[149,2254,307],{"class":162},[149,2256,2257],{"class":173}," token_endpoint(\n",[149,2259,2260,2263,2266,2269,2271,2273,2276],{"class":151,"line":519},[149,2261,2262],{"class":173},"        (",[149,2264,2265],{"class":166},"400",[149,2267,2268],{"class":173},", {",[149,2270,982],{"class":246},[149,2272,532],{"class":173},[149,2274,2275],{"class":246},"\"authorization_pending\"",[149,2277,2278],{"class":173},"}),\n",[149,2280,2281,2283,2285,2287,2289,2291,2294,2296,2298,2300,2303,2305,2307,2309,2312],{"class":151,"line":541},[149,2282,2262],{"class":173},[149,2284,581],{"class":166},[149,2286,2268],{"class":173},[149,2288,954],{"class":246},[149,2290,532],{"class":173},[149,2292,2293],{"class":246},"\"at\"",[149,2295,17],{"class":173},[149,2297,960],{"class":246},[149,2299,532],{"class":173},[149,2301,2302],{"class":246},"\"rt\"",[149,2304,17],{"class":173},[149,2306,691],{"class":246},[149,2308,532],{"class":173},[149,2310,2311],{"class":166},"3600",[149,2313,2278],{"class":173},[149,2315,2316],{"class":151,"line":550},[149,2317,727],{"class":173},[149,2319,2320,2323,2325],{"class":151,"line":594},[149,2321,2322],{"class":173},"    clock ",[149,2324,307],{"class":162},[149,2326,2327],{"class":173}," FakeClock()\n",[149,2329,2330,2333,2335,2337,2340,2342,2345,2347,2349,2351,2354,2356,2359,2362,2364],{"class":151,"line":605},[149,2331,2332],{"class":173},"    tokens ",[149,2334,307],{"class":162},[149,2336,1634],{"class":173},[149,2338,2339],{"class":246},"\"https:\u002F\u002Flogin.test\u002Ftoken\"",[149,2341,17],{"class":173},[149,2343,2344],{"class":246},"\"cli\"",[149,2346,17],{"class":173},[149,2348,1977],{"class":166},[149,2350,17],{"class":173},[149,2352,2353],{"class":303},"sleep",[149,2355,307],{"class":162},[149,2357,2358],{"class":173},"clock.sleep, ",[149,2360,2361],{"class":303},"clock",[149,2363,307],{"class":162},[149,2365,2366],{"class":173},"clock)\n",[149,2368,2369,2372,2375,2377],{"class":151,"line":614},[149,2370,2371],{"class":162},"    assert",[149,2373,2374],{"class":173}," tokens.access_token ",[149,2376,995],{"class":162},[149,2378,2379],{"class":246}," \"at\"\n",[149,2381,2382,2384,2387,2389,2392,2394,2396,2398],{"class":151,"line":631},[149,2383,2371],{"class":162},[149,2385,2386],{"class":173}," clock.slept ",[149,2388,995],{"class":162},[149,2390,2391],{"class":173}," [",[149,2393,719],{"class":166},[149,2395,17],{"class":173},[149,2397,719],{"class":166},[149,2399,2400],{"class":173},"]\n",[149,2402,2403],{"class":151,"line":646},[149,2404,181],{"emptyLinePlaceholder":180},[149,2406,2407],{"class":151,"line":661},[149,2408,181],{"emptyLinePlaceholder":180},[149,2410,2411,2413,2416],{"class":151,"line":678},[149,2412,464],{"class":162},[149,2414,2415],{"class":266}," test_slow_down_increases_interval",[149,2417,2247],{"class":173},[149,2419,2420,2422,2424],{"class":151,"line":702},[149,2421,2252],{"class":173},[149,2423,307],{"class":162},[149,2425,2257],{"class":173},[149,2427,2428,2430,2432,2434,2436,2438,2441],{"class":151,"line":724},[149,2429,2262],{"class":173},[149,2431,2265],{"class":166},[149,2433,2268],{"class":173},[149,2435,982],{"class":246},[149,2437,532],{"class":173},[149,2439,2440],{"class":246},"\"slow_down\"",[149,2442,2278],{"class":173},[149,2444,2445,2447,2449,2451,2453,2455,2457],{"class":151,"line":730},[149,2446,2262],{"class":173},[149,2448,2265],{"class":166},[149,2450,2268],{"class":173},[149,2452,982],{"class":246},[149,2454,532],{"class":173},[149,2456,2275],{"class":246},[149,2458,2278],{"class":173},[149,2460,2461,2463,2465,2467,2469,2471,2473],{"class":151,"line":735},[149,2462,2262],{"class":173},[149,2464,581],{"class":166},[149,2466,2268],{"class":173},[149,2468,954],{"class":246},[149,2470,532],{"class":173},[149,2472,2293],{"class":246},[149,2474,2278],{"class":173},[149,2476,2477],{"class":151,"line":740},[149,2478,727],{"class":173},[149,2480,2481,2483,2485],{"class":151,"line":766},[149,2482,2322],{"class":173},[149,2484,307],{"class":162},[149,2486,2327],{"class":173},[149,2488,2489,2492,2494,2496,2498,2500,2502,2504,2506,2508,2510,2512,2514],{"class":151,"line":789},[149,2490,2491],{"class":173},"    poll(client, ",[149,2493,2339],{"class":246},[149,2495,17],{"class":173},[149,2497,2344],{"class":246},[149,2499,17],{"class":173},[149,2501,1977],{"class":166},[149,2503,17],{"class":173},[149,2505,2353],{"class":303},[149,2507,307],{"class":162},[149,2509,2358],{"class":173},[149,2511,2361],{"class":303},[149,2513,307],{"class":162},[149,2515,2366],{"class":173},[149,2517,2518,2520,2522,2524,2526,2528,2530,2533,2535,2537],{"class":151,"line":804},[149,2519,2371],{"class":162},[149,2521,2386],{"class":173},[149,2523,995],{"class":162},[149,2525,2391],{"class":173},[149,2527,719],{"class":166},[149,2529,17],{"class":173},[149,2531,2532],{"class":166},"10",[149,2534,17],{"class":173},[149,2536,2532],{"class":166},[149,2538,2400],{"class":173},[149,2540,2541],{"class":151,"line":821},[149,2542,181],{"emptyLinePlaceholder":180},[149,2544,2545],{"class":151,"line":832},[149,2546,181],{"emptyLinePlaceholder":180},[149,2548,2549,2551,2554],{"class":151,"line":846},[149,2550,464],{"class":162},[149,2552,2553],{"class":266}," test_denied",[149,2555,2247],{"class":173},[149,2557,2558,2560,2562,2565,2567,2569,2571,2573,2576],{"class":151,"line":852},[149,2559,2252],{"class":173},[149,2561,307],{"class":162},[149,2563,2564],{"class":173}," token_endpoint((",[149,2566,2265],{"class":166},[149,2568,2268],{"class":173},[149,2570,982],{"class":246},[149,2572,532],{"class":173},[149,2574,2575],{"class":246},"\"access_denied\"",[149,2577,2578],{"class":173},"}))\n",[149,2580,2581,2583,2585],{"class":151,"line":886},[149,2582,2322],{"class":173},[149,2584,307],{"class":162},[149,2586,2327],{"class":173},[149,2588,2589,2591,2594,2597,2599,2602],{"class":151,"line":908},[149,2590,1413],{"class":162},[149,2592,2593],{"class":173}," pytest.raises(LoginError, ",[149,2595,2596],{"class":303},"match",[149,2598,307],{"class":162},[149,2600,2601],{"class":246},"\"declined\"",[149,2603,276],{"class":173},[149,2605,2606,2609,2611,2613,2615,2617,2619,2621,2623,2625,2627,2629,2631],{"class":151,"line":914},[149,2607,2608],{"class":173},"        poll(client, ",[149,2610,2339],{"class":246},[149,2612,17],{"class":173},[149,2614,2344],{"class":246},[149,2616,17],{"class":173},[149,2618,1977],{"class":166},[149,2620,17],{"class":173},[149,2622,2353],{"class":303},[149,2624,307],{"class":162},[149,2626,2358],{"class":173},[149,2628,2361],{"class":303},[149,2630,307],{"class":162},[149,2632,2366],{"class":173},[149,2634,2635],{"class":151,"line":924},[149,2636,181],{"emptyLinePlaceholder":180},[149,2638,2639],{"class":151,"line":945},[149,2640,181],{"emptyLinePlaceholder":180},[149,2642,2643,2645,2648],{"class":151,"line":971},[149,2644,464],{"class":162},[149,2646,2647],{"class":266}," test_expiry_stops_polling",[149,2649,2247],{"class":173},[149,2651,2652,2655,2657,2659,2661,2663,2666,2668,2671,2673,2675,2677,2680,2682,2684],{"class":151,"line":987},[149,2653,2654],{"class":173},"    short ",[149,2656,307],{"class":162},[149,2658,1982],{"class":173},[149,2660,1985],{"class":246},[149,2662,17],{"class":173},[149,2664,2665],{"class":246},"\"X\"",[149,2667,17],{"class":173},[149,2669,2670],{"class":246},"\"u\"",[149,2672,17],{"class":173},[149,2674,778],{"class":166},[149,2676,17],{"class":173},[149,2678,2679],{"class":166},"12",[149,2681,17],{"class":173},[149,2683,719],{"class":166},[149,2685,313],{"class":173},[149,2687,2688,2690,2692,2695,2697,2700,2702,2704,2706,2708,2710,2713,2715,2718],{"class":151,"line":1003},[149,2689,2252],{"class":173},[149,2691,307],{"class":162},[149,2693,2694],{"class":173}," token_endpoint(",[149,2696,760],{"class":162},[149,2698,2699],{"class":173},"[(",[149,2701,2265],{"class":166},[149,2703,2268],{"class":173},[149,2705,982],{"class":246},[149,2707,532],{"class":173},[149,2709,2275],{"class":246},[149,2711,2712],{"class":173},"})] ",[149,2714,760],{"class":162},[149,2716,2717],{"class":166}," 10",[149,2719,313],{"class":173},[149,2721,2722,2724,2726],{"class":151,"line":1009},[149,2723,2322],{"class":173},[149,2725,307],{"class":162},[149,2727,2327],{"class":173},[149,2729,2730,2732,2734,2736,2738,2741],{"class":151,"line":1023},[149,2731,1413],{"class":162},[149,2733,2593],{"class":173},[149,2735,2596],{"class":303},[149,2737,307],{"class":162},[149,2739,2740],{"class":246},"\"expired\"",[149,2742,276],{"class":173},[149,2744,2745,2747,2749,2751,2753,2756,2758,2760,2762,2764,2766],{"class":151,"line":1038},[149,2746,2608],{"class":173},[149,2748,2339],{"class":246},[149,2750,17],{"class":173},[149,2752,2344],{"class":246},[149,2754,2755],{"class":173},", short, ",[149,2757,2353],{"class":303},[149,2759,307],{"class":162},[149,2761,2358],{"class":173},[149,2763,2361],{"class":303},[149,2765,307],{"class":162},[149,2767,2366],{"class":173},[149,2769,2770,2772,2775,2778,2780],{"class":151,"line":1043},[149,2771,2371],{"class":162},[149,2773,2774],{"class":166}," len",[149,2776,2777],{"class":173},"(clock.slept) ",[149,2779,995],{"class":162},[149,2781,2782],{"class":166}," 3\n",[10,2784,1212,2785,2787,2788,1195,2791,2794,2795,2797],{},[14,2786,1167],{}," test pins the RFC's requirement that the interval stays increased, and the expiry test proves the loop cannot poll forever. For the command itself, patch ",[14,2789,2790],{},"start",[14,2792,2793],{},"poll"," and assert on what reaches the keychain; ",[14,2796,58],{}," supports an in-memory backend for exactly this purpose.",[42,2799,2801],{"id":2800},"conclusion","Conclusion",[10,2803,2804,2805,2807],{},"The device flow gives a CLI proper, SSO-compatible authentication for the price of two HTTP endpoints and a careful polling loop. Show the code clearly, offer but do not require a browser, poll at the server's pace and honour ",[14,2806,1167],{},", handle denial and expiry explicitly, and store the resulting tokens in the keychain. Pair it with an environment-variable token for CI and your CLI works everywhere from a laptop to a headless build agent.",[42,2809,2811],{"id":2810},"frequently-asked-questions","Frequently asked questions",[2813,2814,2816],"h3",{"id":2815},"why-not-open-a-browser-and-listen-on-localhost-for-the-redirect","Why not open a browser and listen on localhost for the redirect?",[10,2818,2819],{},"That is the authorisation code flow with PKCE and a loopback redirect, and it gives a slightly smoother experience on desktops. It fails on remote machines, containers and WSL setups where the browser cannot reach the CLI's local port. Many tools offer both and fall back to the device flow when no browser is available.",[2813,2821,2823],{"id":2822},"do-i-need-to-validate-the-id-token","Do I need to validate the ID token?",[10,2825,2826],{},"If you only need an access token to call your API, the API validates it — the CLI just forwards it. If your CLI uses the ID token to show who is logged in, decode it for display only; do not make authorisation decisions in the client.",[2813,2828,2830,2831,2834],{"id":2829},"how-should-logout-work","How should ",[14,2832,2833],{},"logout"," work?",[10,2836,2837],{},"Delete the tokens from the keychain and, if the provider supports it, call its revocation endpoint (RFC 7009) with the refresh token so it cannot be reused. Report success even if revocation fails; the local deletion is what the user asked for.",[2813,2839,2841],{"id":2840},"can-i-use-the-device-flow-with-github","Can I use the device flow with GitHub?",[10,2843,2844,2845,1195,2848,2851,2852,2855],{},"Yes. Enable the device flow in your OAuth app's settings, then use ",[14,2846,2847],{},"https:\u002F\u002Fgithub.com\u002Flogin\u002Fdevice\u002Fcode",[14,2849,2850],{},"https:\u002F\u002Fgithub.com\u002Flogin\u002Foauth\u002Faccess_token"," as the endpoints. GitHub returns form-encoded responses unless you send ",[14,2853,2854],{},"Accept: application\u002Fjson",", which the code above does.",[42,2857,2859],{"id":2858},"related","Related",[47,2861,2862,2868,2873,2879,2885],{},[50,2863,2864,2865],{},"Up: ",[36,2866,2867],{"href":38},"Calling HTTP APIs from Python CLIs",[50,2869,2870],{},[36,2871,2872],{"href":1843},"Storing tokens with keyring",[50,2874,2875],{},[36,2876,2878],{"href":2877},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fsupporting-multiple-profiles-and-accounts\u002F","Supporting multiple profiles and accounts",[50,2880,2881],{},[36,2882,2884],{"href":2883},"\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",[50,2886,2887],{},[36,2888,2890],{"href":2889},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002F","Secrets and credentials in Python CLIs",[2892,2893,2894],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":145,"searchDepth":159,"depth":159,"links":2896},[2897,2898,2899,2900,2902,2903,2904,2905,2912],{"id":44,"depth":159,"text":45},{"id":83,"depth":159,"text":84},{"id":137,"depth":159,"text":138},{"id":1211,"depth":159,"text":2901},"The login command",{"id":1856,"depth":159,"text":1857},{"id":1922,"depth":159,"text":1923},{"id":2800,"depth":159,"text":2801},{"id":2810,"depth":159,"text":2811,"children":2906},[2907,2908,2909,2911],{"id":2815,"depth":177,"text":2816},{"id":2822,"depth":177,"text":2823},{"id":2829,"depth":177,"text":2910},"How should logout work?",{"id":2840,"depth":177,"text":2841},{"id":2858,"depth":159,"text":2859},"2026-09-18","Add a secure ‘mytool login’ to a Python CLI with the OAuth 2.0 device authorization flow: request a code, poll correctly, handle every response and store tokens.","advanced",false,"md",{},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Foauth-device-flow-login-for-clis",{"title":5,"description":2914},"cli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Foauth-device-flow-login-for-clis\u002Findex",[2923,2924,29,2925],"oauth","authentication","security","CTnvLxNjs6hoFbB8JNKB2JnX-VXjYKn56Dm1RDIfTFg",[2928,2931,2934,2937,2940,2943,2946,2949,2952,2955,2958,2961,2964,2967,2970,2973,2976,2979,2982,2985,2988,2991,2994,2997,3000,3003,3006,3009,3012,3015,3018,3021,3024,3027,3030,3033,3036,3039,3042,3045,3048,3051,3054,3057,3060,3063,3066,3069,3072,3075,3078,3081,3084,3087,3090,3093,3096,3099,3101,3102,3105,3108,3111,3114,3117,3120,3123,3126,3129,3132,3135,3138,3141,3144,3147,3150,3153,3156,3159,3162,3165,3168,3171,3174,3177,3180,3183,3186,3189,3192,3195,3198,3201,3204,3207,3210,3213,3216,3219,3222,3225,3228,3231,3234,3237,3240,3243,3246,3249,3252,3255,3258,3261,3264,3267,3270,3273,3276,3279,3282,3285,3288,3291,3294,3297,3300,3303,3306,3309,3312,3315,3318,3321,3324,3327,3330,3333,3336,3339,3342,3345,3348,3351,3354,3357,3360,3363,3366,3369,3372,3375,3378,3381,3384,3387,3390,3393,3396,3399,3402,3405,3408,3411,3414,3417,3420,3423,3426,3429,3432,3435,3438,3441,3444,3447,3450,3453,3456,3459,3462,3465,3468,3471],{"path":2929,"title":2930},"\u002Fabout","About Python CLI Toolcraft",{"path":2932,"title":2933},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies","Advanced Argument Validation Strategies",{"path":2935,"title":2936},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fparsing-nested-json-arguments-in-python-clis","Parsing Nested JSON Args in Python CLIs",{"path":2938,"title":2939},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-dependent-and-conflicting-options","Validating Dependent and Conflicting CLI Options",{"path":2941,"title":2942},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-file-and-directory-paths-in-clis","Validating File and Directory Paths in CLIs",{"path":2944,"title":2945},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fwriting-custom-click-parameter-types","Writing Custom Click Parameter Types",{"path":2947,"title":2948},"\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":2950,"title":2951},"\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":2953,"title":2954},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual","Building Terminal UIs with Textual for Python CLIs",{"path":2956,"title":2957},"\u002Fadvanced-input-parsing-user-experience\u002Fbuilding-terminal-uis-with-textual\u002Ftesting-textual-apps-with-pilot","Testing Textual Apps with Pilot",{"path":2959,"title":2960},"\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":2962,"title":2963},"\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":2965,"title":2966},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation","CLI Help Output and Documentation",{"path":2968,"title":2969},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fversioning-and-deprecating-cli-flags","Versioning and Deprecating CLI Flags",{"path":2971,"title":2972},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fwriting-help-text-users-actually-read","Writing Help Text Users Actually Read",{"path":2974,"title":2975},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fadapting-output-to-terminal-width","Adapting Python CLI Output to Terminal Width",{"path":2977,"title":2978},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility\u002Fdetecting-ci-environments-and-non-interactive-shells","Detecting CI Environments and Non-Interactive Shells",{"path":2980,"title":2981},"\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":2983,"title":2984},"\u002Fadvanced-input-parsing-user-experience\u002Fcross-platform-terminal-compatibility","Cross-Platform Terminal Compatibility for Python CLIs",{"path":2986,"title":2987},"\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":2989,"title":2990},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fchoosing-exit-codes-for-cli-tools","Choosing Exit Codes for CLI Tools",{"path":2992,"title":2993},"\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":2995,"title":2996},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Ffriendly-error-messages-and-tracebacks","Friendly Error Messages and Tracebacks",{"path":2998,"title":2999},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fhandling-keyboard-interrupt-cleanly","Handling Keyboard Interrupt Cleanly",{"path":3001,"title":3002},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes","Error Handling and Exit Codes for CLIs",{"path":3004,"title":3005},"\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":3007,"title":3008},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fconfig-precedence-flags-env-files-defaults","Config Precedence: Flags, Env, Files, Defaults",{"path":3010,"title":3011},"\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":3013,"title":3014},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars","Handling Config Files and Env Vars in CLIs",{"path":3016,"title":3017},"\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":3019,"title":3020},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Freading-toml-config-with-tomllib","Reading TOML Config with tomllib in Python CLIs",{"path":3022,"title":3023},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Ftyped-settings-with-pydantic-settings","Typed Settings with pydantic-settings in Python CLIs",{"path":3025,"title":3026},"\u002Fadvanced-input-parsing-user-experience","Advanced Input Parsing for Python CLIs",{"path":3028,"title":3029},"\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":3031,"title":3032},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Fbuilding-interactive-prompts-and-menus","Building Interactive Prompts and Menus in Python CLIs",{"path":3034,"title":3035},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich","Interactive Terminal UI with Rich",{"path":3037,"title":3038},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Flive-dashboards-with-rich-live","Live Dashboards with Rich Live in Python CLIs",{"path":3040,"title":3041},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Frendering-tables-and-json-with-rich","Rendering Tables and JSON with Rich",{"path":3043,"title":3044},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Ftheming-rich-output-consistently","Theming Rich Output Consistently in Python CLIs",{"path":3046,"title":3047},"\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":3049,"title":3050},"\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":3052,"title":3053},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis","Shell Completion for Python CLIs",{"path":3055,"title":3056},"\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":3058,"title":3059},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002Ftesting-shell-completion-in-python-clis","Testing Shell Completion in Python CLIs",{"path":3061,"title":3062},"\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":3064,"title":3065},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-verbose-and-quiet-logging-flags","Adding Verbose and Quiet Logging Flags",{"path":3067,"title":3068},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps","Structured Logging for CLI Apps",{"path":3070,"title":3071},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fstructured-json-logging-in-python-clis","Structured JSON Logging in Python CLIs",{"path":3073,"title":3074},"\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":3076,"title":3077},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fdetecting-tty-and-adapting-output","Detecting a TTY and Adapting Output",{"path":3079,"title":3080},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Femitting-json-output-for-scripting","Emitting JSON Output for Scripting",{"path":3082,"title":3083},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fhandling-broken-pipe-and-sigpipe","Handling Broken Pipe and SIGPIPE",{"path":3085,"title":3086},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes","Working with stdin, stdout and Pipes",{"path":3088,"title":3089},"\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":3091,"title":3092},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Freading-piped-input-in-python-clis","Reading Piped Input in Python CLIs",{"path":3094,"title":3095},"\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":3097,"title":3098},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fdownloading-files-with-progress-in-python","Downloading Files with Progress in Python CLIs",{"path":3100,"title":2867},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis",{"path":2919,"title":5},{"path":3103,"title":3104},"\u002Fcli-runtime-systems-integration\u002Fcalling-http-apis-from-python-clis\u002Fpaginating-api-results-in-a-cli","Paginating API Results in a Python CLI",{"path":3106,"title":3107},"\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":3109,"title":3110},"\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":3112,"title":3113},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis","Concurrency and Async in Python CLIs",{"path":3115,"title":3116},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fmultiprocessing-for-cpu-bound-cli-tasks","Multiprocessing for CPU-Bound CLI Tasks",{"path":3118,"title":3119},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Fparallelising-cli-work-with-thread-pools","Parallelising CLI Work with Thread Pools",{"path":3121,"title":3122},"\u002Fcli-runtime-systems-integration\u002Fconcurrency-and-async-in-python-clis\u002Frate-limiting-concurrent-requests-in-clis","Rate-Limiting Concurrent Requests in Python CLIs",{"path":3124,"title":3125},"\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":3127,"title":3128},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fcross-platform-paths-with-pathlib","Cross-Platform Paths with pathlib in CLIs",{"path":3130,"title":3131},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Ffile-locking-for-concurrent-cli-runs","File Locking for Concurrent CLI Runs in Python",{"path":3133,"title":3134},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes","Filesystem Paths and Atomic Writes for CLIs",{"path":3136,"title":3137},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fsafe-temporary-files-and-directories","Safe Temporary Files and Directories in CLIs",{"path":3139,"title":3140},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fstoring-app-data-with-platformdirs","Storing CLI App Data with platformdirs",{"path":3142,"title":3143},"\u002Fcli-runtime-systems-integration\u002Ffilesystem-paths-and-atomic-writes\u002Fwriting-files-atomically-in-python-clis","Writing Files Atomically in Python CLIs",{"path":3145,"title":3146},"\u002Fcli-runtime-systems-integration","CLI Runtime & Systems Integration for Python",{"path":3148,"title":3149},"\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":3151,"title":3152},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis\u002Fhandling-sigterm-and-graceful-shutdown","Handling SIGTERM and Graceful Shutdown in CLIs",{"path":3154,"title":3155},"\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":3157,"title":3158},"\u002Fcli-runtime-systems-integration\u002Flong-running-and-watch-mode-clis","Long-Running and Watch-Mode Python CLIs",{"path":3160,"title":3161},"\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":3163,"title":3164},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Favoiding-shell-injection-in-python-clis","Avoiding Shell Injection in Python CLIs",{"path":3166,"title":3167},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fcalling-external-commands-safely-with-subprocess","Calling External Commands Safely with subprocess",{"path":3169,"title":3170},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fhandling-subprocess-timeouts-and-exit-codes","Handling Subprocess Timeouts and Exit Codes",{"path":3172,"title":3173},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis","Running Subprocesses from Python CLIs",{"path":3175,"title":3176},"\u002Fcli-runtime-systems-integration\u002Frunning-subprocesses-from-python-clis\u002Fstreaming-subprocess-output-in-real-time","Streaming Subprocess Output in Real Time",{"path":3178,"title":3179},"\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":3181,"title":3182},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis","Secrets and Credentials in Python CLIs",{"path":3184,"title":3185},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fprompting-for-passwords-securely","Prompting for Passwords Securely in Python CLIs",{"path":3187,"title":3188},"\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":3190,"title":3191},"\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":3193,"title":3194},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fstoring-tokens-with-keyring","Storing CLI Tokens Securely with keyring",{"path":3196,"title":3197},"\u002Fcli-runtime-systems-integration\u002Fsecrets-and-credentials-in-python-clis\u002Fsupporting-multiple-profiles-and-accounts","Supporting Multiple Profiles and Accounts in CLIs",{"path":3199,"title":3200},"\u002F","Python CLI Toolcraft",{"path":3202,"title":3203},"\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":3205,"title":3206},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading","CLI Startup Performance and Lazy Loading",{"path":3208,"title":3209},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup","Lazy Loading Subcommands for Faster Startup",{"path":3211,"title":3212},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fprofiling-python-cli-startup-time","Profiling Python CLI Startup Time",{"path":3214,"title":3215},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Freducing-cli-dependency-weight","Reducing CLI Dependency Weight",{"path":3217,"title":3218},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-subparsers-for-subcommands","argparse Subparsers for Subcommands",{"path":3220,"title":3221},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-vs-click-vs-typer-comparison","argparse vs Click vs Typer Compared",{"path":3223,"title":3224},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse","Command-Line Parsing with argparse",{"path":3226,"title":3227},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmigrating-from-argparse-to-typer","Migrating from argparse to Typer",{"path":3229,"title":3230},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmutually-exclusive-options-in-argparse","Mutually Exclusive Options in argparse",{"path":3232,"title":3233},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fwriting-custom-argparse-actions","Writing Custom argparse Actions in Python",{"path":3235,"title":3236},"\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":3238,"title":3239},"\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":3241,"title":3242},"\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":3244,"title":3245},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions","Designing CLI Interfaces and Conventions in Python",{"path":3247,"title":3248},"\u002Fmodern-python-cli-frameworks-architecture\u002Fdesigning-cli-interfaces-and-conventions\u002Fnaming-commands-and-flags-consistently","Naming Commands and Flags Consistently in Python CLIs",{"path":3250,"title":3251},"\u002Fmodern-python-cli-frameworks-architecture","Python CLI Frameworks and Architecture",{"path":3253,"title":3254},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fdiscovering-plugins-with-entry-points","Discovering Plugins with Entry Points in Python CLIs",{"path":3256,"title":3257},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fhook-based-plugins-with-pluggy","Hook-Based Plugins for Python CLIs with pluggy",{"path":3259,"title":3260},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis","Plugin Architectures for Extensible CLIs",{"path":3262,"title":3263},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis\u002Fversioning-a-plugin-api","Versioning a Plugin API for a Python CLI",{"path":3265,"title":3266},"\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":3268,"title":3269},"\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":3271,"title":3272},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fdependency-injection-patterns-for-cli-commands","Dependency Injection Patterns for CLI Commands",{"path":3274,"title":3275},"\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":3277,"title":3278},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis","Structuring Multi-Command Python CLIs",{"path":3280,"title":3281},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-common-options-across-commands","Sharing Common Options Across Python CLI Commands",{"path":3283,"title":3284},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-state-with-click-context-objects","Sharing State with Click Context Objects",{"path":3286,"title":3287},"\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":3289,"title":3290},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications","Testing Python CLI Applications",{"path":3292,"title":3293},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fmeasuring-cli-test-coverage","Measuring CLI Test Coverage",{"path":3295,"title":3296},"\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":3298,"title":3299},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fproperty-based-testing-cli-arguments-with-hypothesis","Property-Based Testing CLI Arguments with Hypothesis",{"path":3301,"title":3302},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fsnapshot-testing-cli-output","Snapshot Testing CLI Output",{"path":3304,"title":3305},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-click-commands-with-clirunner","Testing Click Commands with CliRunner",{"path":3307,"title":3308},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-interactive-prompts-and-stdin","Testing Interactive Prompts and stdin",{"path":3310,"title":3311},"\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":3313,"title":3314},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fbuilding-dynamic-commands-in-click","Building Dynamic Commands in Click",{"path":3316,"title":3317},"\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":3319,"title":3320},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each","Typer vs Click: When to Use Each",{"path":3322,"title":3323},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Ftyper-callback-functions-explained","Typer callback functions explained",{"path":3325,"title":3326},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Fusing-annotated-options-in-typer","Using Annotated Options in Typer",{"path":3328,"title":3329},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fautomating-releases-from-git-tags","Automating Python CLI Releases from Git Tags",{"path":3331,"title":3332},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis\u002Fcaching-uv-dependencies-in-ci","Caching uv Dependencies in CI for Python CLIs",{"path":3334,"title":3335},"\u002Fproject-setup-dependency-management\u002Fci-cd-pipelines-for-python-clis","CI\u002FCD Pipelines for Python CLIs",{"path":3337,"title":3338},"\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":3340,"title":3341},"\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":3343,"title":3344},"\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":3346,"title":3347},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fbuilding-a-cookiecutter-template-for-typer-clis","Building a Cookiecutter Template for Typer CLIs",{"path":3349,"title":3350},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fcopier-vs-cookiecutter-for-cli-templates","Copier vs Cookiecutter for CLI Templates",{"path":3352,"title":3353},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter","CLI Project Scaffolding with Cookiecutter",{"path":3355,"title":3356},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fpost-generation-hooks-in-cli-templates","Post-Generation Hooks in Python CLI Templates",{"path":3358,"title":3359},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbuilding-cross-platform-release-binaries-in-ci","Building Cross-Platform Release Binaries in CI",{"path":3361,"title":3362},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbundling-a-python-cli-with-pyinstaller","Bundling a Python CLI with PyInstaller",{"path":3364,"title":3365},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fhomebrew-and-scoop-packaging-for-python-clis","Homebrew and Scoop Packaging for Python CLIs",{"path":3367,"title":3368},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries","Distributing CLIs as Standalone Binaries",{"path":3370,"title":3371},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fnuitka-vs-pyinstaller-for-python-clis","Nuitka vs PyInstaller for Python CLI Binaries",{"path":3373,"title":3374},"\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":3376,"title":3377},"\u002Fproject-setup-dependency-management","Project Setup & Dependency Management",{"path":3379,"title":3380},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code\u002Fconfiguring-ruff-for-a-cli-project","Configuring Ruff for a Python CLI Project",{"path":3382,"title":3383},"\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":3385,"title":3386},"\u002Fproject-setup-dependency-management\u002Flinting-and-type-checking-cli-code","Linting and Type-Checking Python CLI Code",{"path":3388,"title":3389},"\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":3391,"title":3392},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fautomating-changelogs-with-conventional-commits","Automating Changelogs with Conventional Commits",{"path":3394,"title":3395},"\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":3397,"title":3398},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fexposing-version-info-and-build-metadata","Exposing Version Info and Build Metadata",{"path":3400,"title":3401},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs","Managing CLI Versioning & Changelogs",{"path":3403,"title":3404},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fsemantic-versioning-policy-for-cli-tools","A Semantic Versioning Policy for CLI Tools",{"path":3406,"title":3407},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbuilding-wheels-and-sdists-for-python-clis","Building Wheels and sdists for Python CLIs",{"path":3409,"title":3410},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbundling-data-files-with-importlib-resources","Bundling Data Files with importlib.resources in CLIs",{"path":3412,"title":3413},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution","Packaging Python CLIs for Distribution",{"path":3415,"title":3416},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Finstalling-and-distributing-clis-with-pipx","Installing and Distributing CLIs with pipx",{"path":3418,"title":3419},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fpublishing-a-python-cli-to-pypi","Publishing a Python CLI to PyPI",{"path":3421,"title":3422},"\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":3424,"title":3425},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development","Poetry Workflows for CLI Development",{"path":3427,"title":3428},"\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":3430,"title":3431},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-dependency-groups-for-cli-tooling","Poetry Dependency Groups for CLI Tooling",{"path":3433,"title":3434},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-entry-points-and-scripts-for-clis","Poetry Entry Points and Scripts for CLIs",{"path":3436,"title":3437},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects","Pre-commit Hooks for CLI Projects",{"path":3439,"title":3440},"\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":3442,"title":3443},"\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":3445,"title":3446},"\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":3448,"title":3449},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management","uv for Python CLI Dependency Management",{"path":3451,"title":3452},"\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":3454,"title":3455},"\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":3457,"title":3458},"\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":3460,"title":3461},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management\u002Fuv-workspaces-for-multi-package-clis","uv Workspaces for Multi-Package Python CLIs",{"path":3463,"title":3464},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices","Python CLI Env Isolation Best Practices",{"path":3466,"title":3467},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fmanaging-virtual-environments-for-cross-platform-clis","Managing Python CLI Virtual Environments",{"path":3469,"title":3470},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fpinning-the-python-version-for-a-cli","Pinning the Python Version for a CLI",{"path":3472,"title":3473},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fsupporting-multiple-python-versions-with-nox","Supporting Multiple Python Versions with nox",1789736905048]