[{"data":1,"prerenderedAt":2068},["ShallowReactive",2],{"page-\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup\u002F":3,"content-directory":1822},{"id":4,"title":5,"body":6,"date":1807,"description":1808,"difficulty":1809,"draft":1810,"extension":1811,"meta":1812,"navigation":170,"path":1813,"seo":1814,"stem":1815,"tags":1816,"updated":1807,"__hash__":1821},"content\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup\u002Findex.md","Lazy Loading Subcommands for Faster Startup",{"type":7,"value":8,"toc":1795},"minimark",[9,22,27,80,84,87,230,257,268,272,299,303,776,783,938,945,1087,1121,1126,1129,1405,1428,1432,1454,1457,1469,1473,1476,1512,1522,1526,1532,1535,1656,1681,1685,1748,1752,1791],[10,11,12,13,17,18,21],"p",{},"When a multi-command CLI constructs its command group, it typically imports every subcommand module — and every heavy dependency those modules pull in — before it even looks at what the user typed. This guide shows you how to defer that: a custom Click ",[14,15,16],"code",{},"Group"," that imports a subcommand's module only when that subcommand is actually invoked, so ",[14,19,20],{},"--help"," and completion stay instant no matter how heavy your commands are.",[23,24,26],"h2",{"id":25},"tldr","TL;DR",[28,29,30,38,60,67,70],"ul",{},[31,32,33,34,37],"li",{},"The problem is not slow commands — it's that constructing the CLI eagerly imports every command module, so one command's ",[14,35,36],{},"import pandas"," taxes all the others.",[31,39,40,41,44,45,48,49,52,53,59],{},"Subclass ",[14,42,43],{},"click.Group"," and override ",[14,46,47],{},"list_commands"," (cheap, just names) and ",[14,50,51],{},"get_command"," (imports the module on demand). This is a ",[54,55,56],"strong",{},[14,57,58],{},"LazyGroup",".",[31,61,62,63,66],{},"Register subcommands as ",[14,64,65],{},"\"module.path:attr\""," strings in a dict — the string is what lets you name a command without importing it.",[31,68,69],{},"Typer has no built-in lazy group, but you can wrap the underlying Click object or split into deferred sub-apps.",[31,71,72,73,76,77,79],{},"Verify the win with ",[14,74,75],{},"python -X importtime",": heavy modules should be absent from ",[14,78,20],{}," and present only when their command runs.",[23,81,83],{"id":82},"the-problem-one-command-taxes-them-all","The problem: one command taxes them all",[10,85,86],{},"Here is a conventional Click CLI. Each command lives in its own module and is added to the group at import time:",[88,89,94],"pre",{"className":90,"code":91,"language":92,"meta":93,"style":93},"language-python shiki shiki-themes github-light github-dark","# cli.py — the eager version\nimport click\nfrom .commands.convert import convert   # imports pandas at module top\nfrom .commands.fetch import fetch        # imports requests\nfrom .commands.report import report      # imports matplotlib\n\n@click.group()\ndef cli() -> None:\n    ...\n\ncli.add_command(convert)\ncli.add_command(fetch)\ncli.add_command(report)\n","python","",[14,95,96,105,116,133,149,165,172,182,201,207,212,218,224],{"__ignoreMap":93},[97,98,101],"span",{"class":99,"line":100},"line",1,[97,102,104],{"class":103},"sJ8bj","# cli.py — the eager version\n",[97,106,108,112],{"class":99,"line":107},2,[97,109,111],{"class":110},"szBVR","import",[97,113,115],{"class":114},"sVt8B"," click\n",[97,117,119,122,125,127,130],{"class":99,"line":118},3,[97,120,121],{"class":110},"from",[97,123,124],{"class":114}," .commands.convert ",[97,126,111],{"class":110},[97,128,129],{"class":114}," convert   ",[97,131,132],{"class":103},"# imports pandas at module top\n",[97,134,136,138,141,143,146],{"class":99,"line":135},4,[97,137,121],{"class":110},[97,139,140],{"class":114}," .commands.fetch ",[97,142,111],{"class":110},[97,144,145],{"class":114}," fetch        ",[97,147,148],{"class":103},"# imports requests\n",[97,150,152,154,157,159,162],{"class":99,"line":151},5,[97,153,121],{"class":110},[97,155,156],{"class":114}," .commands.report ",[97,158,111],{"class":110},[97,160,161],{"class":114}," report      ",[97,163,164],{"class":103},"# imports matplotlib\n",[97,166,168],{"class":99,"line":167},6,[97,169,171],{"emptyLinePlaceholder":170},true,"\n",[97,173,175,179],{"class":99,"line":174},7,[97,176,178],{"class":177},"sScJk","@click.group",[97,180,181],{"class":114},"()\n",[97,183,185,188,191,194,198],{"class":99,"line":184},8,[97,186,187],{"class":110},"def",[97,189,190],{"class":177}," cli",[97,192,193],{"class":114},"() -> ",[97,195,197],{"class":196},"sj4cs","None",[97,199,200],{"class":114},":\n",[97,202,204],{"class":99,"line":203},9,[97,205,206],{"class":196},"    ...\n",[97,208,210],{"class":99,"line":209},10,[97,211,171],{"emptyLinePlaceholder":170},[97,213,215],{"class":99,"line":214},11,[97,216,217],{"class":114},"cli.add_command(convert)\n",[97,219,221],{"class":99,"line":220},12,[97,222,223],{"class":114},"cli.add_command(fetch)\n",[97,225,227],{"class":99,"line":226},13,[97,228,229],{"class":114},"cli.add_command(report)\n",[10,231,232,233,236,237,240,241,244,245,248,249,252,253,256],{},"The three ",[14,234,235],{},"from .commands... import"," lines run the moment ",[14,238,239],{},"cli.py"," is imported, which is the moment the CLI starts. So ",[14,242,243],{},"mycli --help"," — a request for static text — imports ",[14,246,247],{},"pandas",", ",[14,250,251],{},"requests",", and ",[14,254,255],{},"matplotlib",". On a typical machine that is several hundred milliseconds of work to print help that needed none of it. Every subcommand pays for every other subcommand's dependencies. As the CLI grows, startup degrades linearly.",[10,258,259,260,264,265,267],{},"Deferring the imports ",[261,262,263],"em",{},"inside"," each command function helps only partly: importing the command module still runs that module's top-level ",[14,266,111],{}," statements. To truly avoid the cost you must not import the module at all until the command is invoked.",[23,269,271],{"id":270},"a-custom-click-lazygroup","A custom Click LazyGroup",[10,273,274,275,277,278,281,282,284,285,288,289,292,293,295,296,298],{},"Click looks up subcommands through two ",[14,276,16],{}," methods: ",[14,279,280],{},"list_commands(ctx)"," returns the names to display (for ",[14,283,20],{},"), and ",[14,286,287],{},"get_command(ctx, name)"," resolves one name to a ",[14,290,291],{},"Command"," object (for dispatch). The trick is to make ",[14,294,47],{}," cheap — it only needs strings — and to do the actual import inside ",[14,297,51],{},", which Click calls only for the command the user actually ran.",[300,301],"inline-diagram",{"name":302},"lazygroup-resolution",[88,304,306],{"className":90,"code":305,"language":92,"meta":93,"style":93},"# lazy_group.py\nfrom __future__ import annotations\n\nimport importlib\nimport click\n\n\nclass LazyGroup(click.Group):\n    \"\"\"A click.Group whose subcommands are imported on first use.\n\n    lazy_subcommands maps a command name to a \"module.path:attribute\"\n    string. The module is imported only when that command is invoked.\n    \"\"\"\n\n    def __init__(\n        self,\n        *args,\n        lazy_subcommands: dict[str, str] | None = None,\n        **kwargs,\n    ) -> None:\n        super().__init__(*args, **kwargs)\n        self._lazy: dict[str, str] = lazy_subcommands or {}\n\n    def list_commands(self, ctx: click.Context) -> list[str]:\n        # Eagerly-added commands + lazy names, without importing anything.\n        return sorted({*super().list_commands(ctx), *self._lazy})\n\n    def get_command(self, ctx: click.Context, name: str) -> click.Command | None:\n        if name in self._lazy:\n            return self._load(name)\n        return super().get_command(ctx, name)\n\n    def _load(self, name: str) -> click.Command:\n        module_path, _, attr = self._lazy[name].partition(\":\")\n        module = importlib.import_module(module_path)\n        cmd = getattr(module, attr)\n        if not isinstance(cmd, click.Command):\n            raise TypeError(f\"{self._lazy[name]!r} is not a click.Command\")\n        return cmd\n",[14,307,308,313,326,330,337,343,347,351,372,378,382,387,392,397,402,414,420,429,459,468,478,504,533,538,554,560,588,593,615,633,644,655,660,676,695,706,720,734,768],{"__ignoreMap":93},[97,309,310],{"class":99,"line":100},[97,311,312],{"class":103},"# lazy_group.py\n",[97,314,315,317,320,323],{"class":99,"line":107},[97,316,121],{"class":110},[97,318,319],{"class":196}," __future__",[97,321,322],{"class":110}," import",[97,324,325],{"class":114}," annotations\n",[97,327,328],{"class":99,"line":118},[97,329,171],{"emptyLinePlaceholder":170},[97,331,332,334],{"class":99,"line":135},[97,333,111],{"class":110},[97,335,336],{"class":114}," importlib\n",[97,338,339,341],{"class":99,"line":151},[97,340,111],{"class":110},[97,342,115],{"class":114},[97,344,345],{"class":99,"line":167},[97,346,171],{"emptyLinePlaceholder":170},[97,348,349],{"class":99,"line":174},[97,350,171],{"emptyLinePlaceholder":170},[97,352,353,356,359,362,365,367,369],{"class":99,"line":184},[97,354,355],{"class":110},"class",[97,357,358],{"class":177}," LazyGroup",[97,360,361],{"class":114},"(",[97,363,364],{"class":177},"click",[97,366,59],{"class":114},[97,368,16],{"class":177},[97,370,371],{"class":114},"):\n",[97,373,374],{"class":99,"line":203},[97,375,377],{"class":376},"sZZnC","    \"\"\"A click.Group whose subcommands are imported on first use.\n",[97,379,380],{"class":99,"line":209},[97,381,171],{"emptyLinePlaceholder":170},[97,383,384],{"class":99,"line":214},[97,385,386],{"class":376},"    lazy_subcommands maps a command name to a \"module.path:attribute\"\n",[97,388,389],{"class":99,"line":220},[97,390,391],{"class":376},"    string. The module is imported only when that command is invoked.\n",[97,393,394],{"class":99,"line":226},[97,395,396],{"class":376},"    \"\"\"\n",[97,398,400],{"class":99,"line":399},14,[97,401,171],{"emptyLinePlaceholder":170},[97,403,405,408,411],{"class":99,"line":404},15,[97,406,407],{"class":110},"    def",[97,409,410],{"class":196}," __init__",[97,412,413],{"class":114},"(\n",[97,415,417],{"class":99,"line":416},16,[97,418,419],{"class":114},"        self,\n",[97,421,423,426],{"class":99,"line":422},17,[97,424,425],{"class":110},"        *",[97,427,428],{"class":114},"args,\n",[97,430,432,435,438,440,442,445,448,451,454,456],{"class":99,"line":431},18,[97,433,434],{"class":114},"        lazy_subcommands: dict[",[97,436,437],{"class":196},"str",[97,439,248],{"class":114},[97,441,437],{"class":196},[97,443,444],{"class":114},"] ",[97,446,447],{"class":110},"|",[97,449,450],{"class":196}," None",[97,452,453],{"class":110}," =",[97,455,450],{"class":196},[97,457,458],{"class":114},",\n",[97,460,462,465],{"class":99,"line":461},19,[97,463,464],{"class":110},"        **",[97,466,467],{"class":114},"kwargs,\n",[97,469,471,474,476],{"class":99,"line":470},20,[97,472,473],{"class":114},"    ) -> ",[97,475,197],{"class":196},[97,477,200],{"class":114},[97,479,481,484,487,490,492,495,498,501],{"class":99,"line":480},21,[97,482,483],{"class":196},"        super",[97,485,486],{"class":114},"().",[97,488,489],{"class":196},"__init__",[97,491,361],{"class":114},[97,493,494],{"class":110},"*",[97,496,497],{"class":114},"args, ",[97,499,500],{"class":110},"**",[97,502,503],{"class":114},"kwargs)\n",[97,505,507,510,513,515,517,519,521,524,527,530],{"class":99,"line":506},22,[97,508,509],{"class":196},"        self",[97,511,512],{"class":114},"._lazy: dict[",[97,514,437],{"class":196},[97,516,248],{"class":114},[97,518,437],{"class":196},[97,520,444],{"class":114},[97,522,523],{"class":110},"=",[97,525,526],{"class":114}," lazy_subcommands ",[97,528,529],{"class":110},"or",[97,531,532],{"class":114}," {}\n",[97,534,536],{"class":99,"line":535},23,[97,537,171],{"emptyLinePlaceholder":170},[97,539,541,543,546,549,551],{"class":99,"line":540},24,[97,542,407],{"class":110},[97,544,545],{"class":177}," list_commands",[97,547,548],{"class":114},"(self, ctx: click.Context) -> list[",[97,550,437],{"class":196},[97,552,553],{"class":114},"]:\n",[97,555,557],{"class":99,"line":556},25,[97,558,559],{"class":103},"        # Eagerly-added commands + lazy names, without importing anything.\n",[97,561,563,566,569,572,574,577,580,582,585],{"class":99,"line":562},26,[97,564,565],{"class":110},"        return",[97,567,568],{"class":196}," sorted",[97,570,571],{"class":114},"({",[97,573,494],{"class":110},[97,575,576],{"class":196},"super",[97,578,579],{"class":114},"().list_commands(ctx), ",[97,581,494],{"class":110},[97,583,584],{"class":196},"self",[97,586,587],{"class":114},"._lazy})\n",[97,589,591],{"class":99,"line":590},27,[97,592,171],{"emptyLinePlaceholder":170},[97,594,596,598,601,604,606,609,611,613],{"class":99,"line":595},28,[97,597,407],{"class":110},[97,599,600],{"class":177}," get_command",[97,602,603],{"class":114},"(self, ctx: click.Context, name: ",[97,605,437],{"class":196},[97,607,608],{"class":114},") -> click.Command ",[97,610,447],{"class":110},[97,612,450],{"class":196},[97,614,200],{"class":114},[97,616,618,621,624,627,630],{"class":99,"line":617},29,[97,619,620],{"class":110},"        if",[97,622,623],{"class":114}," name ",[97,625,626],{"class":110},"in",[97,628,629],{"class":196}," self",[97,631,632],{"class":114},"._lazy:\n",[97,634,636,639,641],{"class":99,"line":635},30,[97,637,638],{"class":110},"            return",[97,640,629],{"class":196},[97,642,643],{"class":114},"._load(name)\n",[97,645,647,649,652],{"class":99,"line":646},31,[97,648,565],{"class":110},[97,650,651],{"class":196}," super",[97,653,654],{"class":114},"().get_command(ctx, name)\n",[97,656,658],{"class":99,"line":657},32,[97,659,171],{"emptyLinePlaceholder":170},[97,661,663,665,668,671,673],{"class":99,"line":662},33,[97,664,407],{"class":110},[97,666,667],{"class":177}," _load",[97,669,670],{"class":114},"(self, name: ",[97,672,437],{"class":196},[97,674,675],{"class":114},") -> click.Command:\n",[97,677,679,682,684,686,689,692],{"class":99,"line":678},34,[97,680,681],{"class":114},"        module_path, _, attr ",[97,683,523],{"class":110},[97,685,629],{"class":196},[97,687,688],{"class":114},"._lazy[name].partition(",[97,690,691],{"class":376},"\":\"",[97,693,694],{"class":114},")\n",[97,696,698,701,703],{"class":99,"line":697},35,[97,699,700],{"class":114},"        module ",[97,702,523],{"class":110},[97,704,705],{"class":114}," importlib.import_module(module_path)\n",[97,707,709,712,714,717],{"class":99,"line":708},36,[97,710,711],{"class":114},"        cmd ",[97,713,523],{"class":110},[97,715,716],{"class":196}," getattr",[97,718,719],{"class":114},"(module, attr)\n",[97,721,723,725,728,731],{"class":99,"line":722},37,[97,724,620],{"class":110},[97,726,727],{"class":110}," not",[97,729,730],{"class":196}," isinstance",[97,732,733],{"class":114},"(cmd, click.Command):\n",[97,735,737,740,743,745,748,751,754,757,760,763,766],{"class":99,"line":736},38,[97,738,739],{"class":110},"            raise",[97,741,742],{"class":196}," TypeError",[97,744,361],{"class":114},[97,746,747],{"class":110},"f",[97,749,750],{"class":376},"\"",[97,752,753],{"class":196},"{self",[97,755,756],{"class":114},"._lazy[name]",[97,758,759],{"class":110},"!r",[97,761,762],{"class":196},"}",[97,764,765],{"class":376}," is not a click.Command\"",[97,767,694],{"class":114},[97,769,771,773],{"class":99,"line":770},39,[97,772,565],{"class":110},[97,774,775],{"class":114}," cmd\n",[10,777,778,779,782],{},"Wiring the CLI to use it means passing the class and a registry of string paths — and crucially, ",[261,780,781],{},"not"," importing the command modules:",[88,784,786],{"className":90,"code":785,"language":92,"meta":93,"style":93},"# cli.py — the lazy version. Note: no `from .commands... import ...`\nimport click\nfrom .lazy_group import LazyGroup\n\n\n@click.group(\n    cls=LazyGroup,\n    lazy_subcommands={\n        \"convert\": \"myapp.commands.convert:convert\",\n        \"fetch\": \"myapp.commands.fetch:fetch\",\n        \"report\": \"myapp.commands.report:report\",\n    },\n)\ndef cli() -> None:\n    \"\"\"myapp — does three heavy things, but starts instantly.\"\"\"\n\n\nif __name__ == \"__main__\":\n    cli()\n",[14,787,788,793,799,811,815,819,825,836,846,859,871,883,888,892,904,909,913,917,933],{"__ignoreMap":93},[97,789,790],{"class":99,"line":100},[97,791,792],{"class":103},"# cli.py — the lazy version. Note: no `from .commands... import ...`\n",[97,794,795,797],{"class":99,"line":107},[97,796,111],{"class":110},[97,798,115],{"class":114},[97,800,801,803,806,808],{"class":99,"line":118},[97,802,121],{"class":110},[97,804,805],{"class":114}," .lazy_group ",[97,807,111],{"class":110},[97,809,810],{"class":114}," LazyGroup\n",[97,812,813],{"class":99,"line":135},[97,814,171],{"emptyLinePlaceholder":170},[97,816,817],{"class":99,"line":151},[97,818,171],{"emptyLinePlaceholder":170},[97,820,821,823],{"class":99,"line":167},[97,822,178],{"class":177},[97,824,413],{"class":114},[97,826,827,831,833],{"class":99,"line":174},[97,828,830],{"class":829},"s4XuR","    cls",[97,832,523],{"class":110},[97,834,835],{"class":114},"LazyGroup,\n",[97,837,838,841,843],{"class":99,"line":184},[97,839,840],{"class":829},"    lazy_subcommands",[97,842,523],{"class":110},[97,844,845],{"class":114},"{\n",[97,847,848,851,854,857],{"class":99,"line":203},[97,849,850],{"class":376},"        \"convert\"",[97,852,853],{"class":114},": ",[97,855,856],{"class":376},"\"myapp.commands.convert:convert\"",[97,858,458],{"class":114},[97,860,861,864,866,869],{"class":99,"line":209},[97,862,863],{"class":376},"        \"fetch\"",[97,865,853],{"class":114},[97,867,868],{"class":376},"\"myapp.commands.fetch:fetch\"",[97,870,458],{"class":114},[97,872,873,876,878,881],{"class":99,"line":214},[97,874,875],{"class":376},"        \"report\"",[97,877,853],{"class":114},[97,879,880],{"class":376},"\"myapp.commands.report:report\"",[97,882,458],{"class":114},[97,884,885],{"class":99,"line":220},[97,886,887],{"class":114},"    },\n",[97,889,890],{"class":99,"line":226},[97,891,694],{"class":114},[97,893,894,896,898,900,902],{"class":99,"line":399},[97,895,187],{"class":110},[97,897,190],{"class":177},[97,899,193],{"class":114},[97,901,197],{"class":196},[97,903,200],{"class":114},[97,905,906],{"class":99,"line":404},[97,907,908],{"class":376},"    \"\"\"myapp — does three heavy things, but starts instantly.\"\"\"\n",[97,910,911],{"class":99,"line":416},[97,912,171],{"emptyLinePlaceholder":170},[97,914,915],{"class":99,"line":422},[97,916,171],{"emptyLinePlaceholder":170},[97,918,919,922,925,928,931],{"class":99,"line":431},[97,920,921],{"class":110},"if",[97,923,924],{"class":196}," __name__",[97,926,927],{"class":110}," ==",[97,929,930],{"class":376}," \"__main__\"",[97,932,200],{"class":114},[97,934,935],{"class":99,"line":461},[97,936,937],{"class":114},"    cli()\n",[10,939,940,941,944],{},"Each command module is written exactly as before — an ordinary ",[14,942,943],{},"@click.command()"," with its heavy imports at the top:",[88,946,948],{"className":90,"code":947,"language":92,"meta":93,"style":93},"# myapp\u002Fcommands\u002Fconvert.py\nimport click\nimport pandas as pd        # stays at module top; only imported when convert runs\n\n\n@click.command()\n@click.argument(\"path\")\ndef convert(path: str) -> None:\n    \"\"\"Convert a CSV to Parquet.\"\"\"\n    df = pd.read_csv(path)\n    df.to_parquet(path.replace(\".csv\", \".parquet\"))\n    click.echo(f\"wrote {path.replace('.csv', '.parquet')}\")\n",[14,949,950,955,961,977,981,985,992,1004,1023,1028,1038,1054],{"__ignoreMap":93},[97,951,952],{"class":99,"line":100},[97,953,954],{"class":103},"# myapp\u002Fcommands\u002Fconvert.py\n",[97,956,957,959],{"class":99,"line":107},[97,958,111],{"class":110},[97,960,115],{"class":114},[97,962,963,965,968,971,974],{"class":99,"line":118},[97,964,111],{"class":110},[97,966,967],{"class":114}," pandas ",[97,969,970],{"class":110},"as",[97,972,973],{"class":114}," pd        ",[97,975,976],{"class":103},"# stays at module top; only imported when convert runs\n",[97,978,979],{"class":99,"line":135},[97,980,171],{"emptyLinePlaceholder":170},[97,982,983],{"class":99,"line":151},[97,984,171],{"emptyLinePlaceholder":170},[97,986,987,990],{"class":99,"line":167},[97,988,989],{"class":177},"@click.command",[97,991,181],{"class":114},[97,993,994,997,999,1002],{"class":99,"line":174},[97,995,996],{"class":177},"@click.argument",[97,998,361],{"class":114},[97,1000,1001],{"class":376},"\"path\"",[97,1003,694],{"class":114},[97,1005,1006,1008,1011,1014,1016,1019,1021],{"class":99,"line":184},[97,1007,187],{"class":110},[97,1009,1010],{"class":177}," convert",[97,1012,1013],{"class":114},"(path: ",[97,1015,437],{"class":196},[97,1017,1018],{"class":114},") -> ",[97,1020,197],{"class":196},[97,1022,200],{"class":114},[97,1024,1025],{"class":99,"line":203},[97,1026,1027],{"class":376},"    \"\"\"Convert a CSV to Parquet.\"\"\"\n",[97,1029,1030,1033,1035],{"class":99,"line":209},[97,1031,1032],{"class":114},"    df ",[97,1034,523],{"class":110},[97,1036,1037],{"class":114}," pd.read_csv(path)\n",[97,1039,1040,1043,1046,1048,1051],{"class":99,"line":214},[97,1041,1042],{"class":114},"    df.to_parquet(path.replace(",[97,1044,1045],{"class":376},"\".csv\"",[97,1047,248],{"class":114},[97,1049,1050],{"class":376},"\".parquet\"",[97,1052,1053],{"class":114},"))\n",[97,1055,1056,1059,1061,1064,1067,1070,1073,1075,1078,1081,1083,1085],{"class":99,"line":220},[97,1057,1058],{"class":114},"    click.echo(",[97,1060,747],{"class":110},[97,1062,1063],{"class":376},"\"wrote ",[97,1065,1066],{"class":196},"{",[97,1068,1069],{"class":114},"path.replace(",[97,1071,1072],{"class":376},"'.csv'",[97,1074,248],{"class":114},[97,1076,1077],{"class":376},"'.parquet'",[97,1079,1080],{"class":114},")",[97,1082,762],{"class":196},[97,1084,750],{"class":376},[97,1086,694],{"class":114},[10,1088,1089,1090,1092,1093,1095,1096,1099,1100,1102,1103,1105,1106,1109,1110,1113,1114,1117,1118,1120],{},"Now ",[14,1091,243],{}," calls ",[14,1094,47],{},", which returns ",[14,1097,1098],{},"[\"convert\", \"fetch\", \"report\"]"," as plain strings — no module is imported, no ",[14,1101,247],{},", no ",[14,1104,255],{},". Only ",[14,1107,1108],{},"mycli convert data.csv"," triggers ",[14,1111,1112],{},"get_command(\"convert\")",", which imports ",[14,1115,1116],{},"myapp.commands.convert"," and its ",[14,1119,247],{}," at that moment. The user pays for exactly the command they ran.",[1122,1123,1125],"h3",{"id":1124},"a-self-contained-version-you-can-run-now","A self-contained version you can run now",[10,1127,1128],{},"To see the behavior without a package, register modules from the standard library and print when each is loaded:",[88,1130,1132],{"className":90,"code":1131,"language":92,"meta":93,"style":93},"import importlib\nimport click\n\n\nclass LazyGroup(click.Group):\n    def __init__(self, *args, lazy_subcommands=None, **kwargs):\n        super().__init__(*args, **kwargs)\n        self._lazy = lazy_subcommands or {}\n\n    def list_commands(self, ctx):\n        return sorted({*super().list_commands(ctx), *self._lazy})\n\n    def get_command(self, ctx, name):\n        if name in self._lazy:\n            module_path, _, attr = self._lazy[name].partition(\":\")\n            print(f\"[lazy] importing {module_path} for '{name}'\")\n            return getattr(importlib.import_module(module_path), attr)\n        return super().get_command(ctx, name)\n\n\n@click.group(cls=LazyGroup, lazy_subcommands={\"hi\": \"_lazy_cmds:hi\"})\ndef cli():\n    ...\n",[14,1133,1134,1140,1146,1150,1154,1170,1195,1213,1228,1232,1241,1261,1265,1274,1286,1301,1335,1344,1352,1356,1360,1392,1401],{"__ignoreMap":93},[97,1135,1136,1138],{"class":99,"line":100},[97,1137,111],{"class":110},[97,1139,336],{"class":114},[97,1141,1142,1144],{"class":99,"line":107},[97,1143,111],{"class":110},[97,1145,115],{"class":114},[97,1147,1148],{"class":99,"line":118},[97,1149,171],{"emptyLinePlaceholder":170},[97,1151,1152],{"class":99,"line":135},[97,1153,171],{"emptyLinePlaceholder":170},[97,1155,1156,1158,1160,1162,1164,1166,1168],{"class":99,"line":151},[97,1157,355],{"class":110},[97,1159,358],{"class":177},[97,1161,361],{"class":114},[97,1163,364],{"class":177},[97,1165,59],{"class":114},[97,1167,16],{"class":177},[97,1169,371],{"class":114},[97,1171,1172,1174,1176,1179,1181,1184,1186,1188,1190,1192],{"class":99,"line":167},[97,1173,407],{"class":110},[97,1175,410],{"class":196},[97,1177,1178],{"class":114},"(self, ",[97,1180,494],{"class":110},[97,1182,1183],{"class":114},"args, lazy_subcommands",[97,1185,523],{"class":110},[97,1187,197],{"class":196},[97,1189,248],{"class":114},[97,1191,500],{"class":110},[97,1193,1194],{"class":114},"kwargs):\n",[97,1196,1197,1199,1201,1203,1205,1207,1209,1211],{"class":99,"line":174},[97,1198,483],{"class":196},[97,1200,486],{"class":114},[97,1202,489],{"class":196},[97,1204,361],{"class":114},[97,1206,494],{"class":110},[97,1208,497],{"class":114},[97,1210,500],{"class":110},[97,1212,503],{"class":114},[97,1214,1215,1217,1220,1222,1224,1226],{"class":99,"line":184},[97,1216,509],{"class":196},[97,1218,1219],{"class":114},"._lazy ",[97,1221,523],{"class":110},[97,1223,526],{"class":114},[97,1225,529],{"class":110},[97,1227,532],{"class":114},[97,1229,1230],{"class":99,"line":203},[97,1231,171],{"emptyLinePlaceholder":170},[97,1233,1234,1236,1238],{"class":99,"line":209},[97,1235,407],{"class":110},[97,1237,545],{"class":177},[97,1239,1240],{"class":114},"(self, ctx):\n",[97,1242,1243,1245,1247,1249,1251,1253,1255,1257,1259],{"class":99,"line":214},[97,1244,565],{"class":110},[97,1246,568],{"class":196},[97,1248,571],{"class":114},[97,1250,494],{"class":110},[97,1252,576],{"class":196},[97,1254,579],{"class":114},[97,1256,494],{"class":110},[97,1258,584],{"class":196},[97,1260,587],{"class":114},[97,1262,1263],{"class":99,"line":220},[97,1264,171],{"emptyLinePlaceholder":170},[97,1266,1267,1269,1271],{"class":99,"line":226},[97,1268,407],{"class":110},[97,1270,600],{"class":177},[97,1272,1273],{"class":114},"(self, ctx, name):\n",[97,1275,1276,1278,1280,1282,1284],{"class":99,"line":399},[97,1277,620],{"class":110},[97,1279,623],{"class":114},[97,1281,626],{"class":110},[97,1283,629],{"class":196},[97,1285,632],{"class":114},[97,1287,1288,1291,1293,1295,1297,1299],{"class":99,"line":404},[97,1289,1290],{"class":114},"            module_path, _, attr ",[97,1292,523],{"class":110},[97,1294,629],{"class":196},[97,1296,688],{"class":114},[97,1298,691],{"class":376},[97,1300,694],{"class":114},[97,1302,1303,1306,1308,1310,1313,1315,1318,1320,1323,1325,1328,1330,1333],{"class":99,"line":416},[97,1304,1305],{"class":196},"            print",[97,1307,361],{"class":114},[97,1309,747],{"class":110},[97,1311,1312],{"class":376},"\"[lazy] importing ",[97,1314,1066],{"class":196},[97,1316,1317],{"class":114},"module_path",[97,1319,762],{"class":196},[97,1321,1322],{"class":376}," for '",[97,1324,1066],{"class":196},[97,1326,1327],{"class":114},"name",[97,1329,762],{"class":196},[97,1331,1332],{"class":376},"'\"",[97,1334,694],{"class":114},[97,1336,1337,1339,1341],{"class":99,"line":422},[97,1338,638],{"class":110},[97,1340,716],{"class":196},[97,1342,1343],{"class":114},"(importlib.import_module(module_path), attr)\n",[97,1345,1346,1348,1350],{"class":99,"line":431},[97,1347,565],{"class":110},[97,1349,651],{"class":196},[97,1351,654],{"class":114},[97,1353,1354],{"class":99,"line":461},[97,1355,171],{"emptyLinePlaceholder":170},[97,1357,1358],{"class":99,"line":470},[97,1359,171],{"emptyLinePlaceholder":170},[97,1361,1362,1364,1366,1369,1371,1374,1377,1379,1381,1384,1386,1389],{"class":99,"line":480},[97,1363,178],{"class":177},[97,1365,361],{"class":114},[97,1367,1368],{"class":829},"cls",[97,1370,523],{"class":110},[97,1372,1373],{"class":114},"LazyGroup, ",[97,1375,1376],{"class":829},"lazy_subcommands",[97,1378,523],{"class":110},[97,1380,1066],{"class":114},[97,1382,1383],{"class":376},"\"hi\"",[97,1385,853],{"class":114},[97,1387,1388],{"class":376},"\"_lazy_cmds:hi\"",[97,1390,1391],{"class":114},"})\n",[97,1393,1394,1396,1398],{"class":99,"line":506},[97,1395,187],{"class":110},[97,1397,190],{"class":177},[97,1399,1400],{"class":114},"():\n",[97,1402,1403],{"class":99,"line":535},[97,1404,206],{"class":196},[10,1406,1407,1408,1411,1412,1415,1416,1419,1420,1423,1424,1427],{},"With a sibling ",[14,1409,1410],{},"_lazy_cmds.py"," defining a ",[14,1413,1414],{},"hi"," command, running ",[14,1417,1418],{},"python -m app --help"," prints the command list with no ",[14,1421,1422],{},"[lazy] importing"," line, while ",[14,1425,1426],{},"python -m app hi"," prints the import line first — proof the module loads only on invocation.",[23,1429,1431],{"id":1430},"the-string-path-registry-pattern","The string-path registry pattern",[10,1433,1434,1435,248,1438,1440,1441,1444,1445,1448,1449,59],{},"The heart of the technique is that a command is registered as a ",[54,1436,1437],{},"string",[14,1439,65],{},", not an imported object. A string can name a target without triggering its import; ",[14,1442,1443],{},"importlib.import_module"," resolves it later. This is the same ",[14,1446,1447],{},"module:attribute"," convention Python uses for console-script entry points, which is no coincidence — see ",[1450,1451,1453],"a",{"href":1452},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fbest-practices-for-python-cli-entry-points\u002F","best practices for Python CLI entry points",[300,1455],{"name":1456},"lazy-registry-tree",[10,1458,1459,1460,1462,1463,1465,1466,1468],{},"Keep the registry in one place — the ",[14,1461,1376],{}," dict on your top-level group — so there is a single readable manifest of every command and where it lives. For a large CLI you can build the dict programmatically (e.g. from a directory listing), but an explicit dict is easier to reason about and, importantly, still imports nothing at construction time. The one rule: never ",[14,1464,111],{}," a command module from ",[14,1467,239],{},". The instant you do, that command is eager again and the string registry buys you nothing.",[23,1470,1472],{"id":1471},"doing-the-same-in-typer","Doing the same in Typer",[10,1474,1475],{},"Typer builds on Click but does not expose a lazy-group option directly. Two workable approaches:",[28,1477,1478,1495],{},[31,1479,1480,1483,1484,1487,1488,1491,1492,1494],{},[54,1481,1482],{},"Reuse the Click LazyGroup."," A ",[14,1485,1486],{},"typer.Typer"," is convertible to a Click object with ",[14,1489,1490],{},"typer.main.get_command(app)",". For a Typer-first app you can define your top-level group as a Click ",[14,1493,58],{}," and mount Typer sub-apps under it, or keep the whole top level in Click and only use Typer inside individual (lazily imported) command modules.",[31,1496,1497,1500,1501,1504,1505,1508,1509,1511],{},[54,1498,1499],{},"Split into deferred sub-apps."," Typer's ",[14,1502,1503],{},"app.add_typer(sub_app, name=...)"," still imports ",[14,1506,1507],{},"sub_app"," at call time, so it is not lazy by itself. Wrap the registration so the sub-app is built by a factory that is only called from a Click ",[14,1510,51],{}," override.",[10,1513,1514,1515,1517,1518,59],{},"If you are choosing between the two frameworks for a startup-sensitive tool, Click's explicit ",[14,1516,16],{}," subclassing makes lazy loading a first-class, well-supported pattern, which is a real point in its favor — weigh it in ",[1450,1519,1521],{"href":1520},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002F","Typer vs Click: when to use each",[23,1523,1525],{"id":1524},"measuring-the-win-with-x-importtime","Measuring the win with -X importtime",[10,1527,1528,1529,1531],{},"Don't take the speedup on faith — prove it. ",[14,1530,75],{}," prints every import and its cost, so you can confirm heavy modules are absent from the help path:",[300,1533],{"name":1534},"eager-vs-lazy-imports",[88,1536,1540],{"className":1537,"code":1538,"language":1539,"meta":93,"style":93},"language-bash shiki shiki-themes github-light github-dark","# Heavy modules should NOT appear here.\n$ python -X importtime -m myapp --help 2>&1 | grep -E \"pandas|matplotlib\" || echo \"no heavy imports on --help\"\nno heavy imports on --help\n\n# They SHOULD appear only when the command runs.\n$ python -X importtime -m myapp convert data.csv 2>&1 | grep -c pandas\n1\n","bash",[14,1541,1542,1547,1594,1611,1615,1620,1651],{"__ignoreMap":93},[97,1543,1544],{"class":99,"line":100},[97,1545,1546],{"class":103},"# Heavy modules should NOT appear here.\n",[97,1548,1549,1552,1555,1558,1561,1564,1567,1570,1573,1576,1579,1582,1585,1588,1591],{"class":99,"line":107},[97,1550,1551],{"class":177},"$",[97,1553,1554],{"class":376}," python",[97,1556,1557],{"class":196}," -X",[97,1559,1560],{"class":376}," importtime",[97,1562,1563],{"class":196}," -m",[97,1565,1566],{"class":376}," myapp",[97,1568,1569],{"class":196}," --help",[97,1571,1572],{"class":110}," 2>&1",[97,1574,1575],{"class":110}," |",[97,1577,1578],{"class":177}," grep",[97,1580,1581],{"class":196}," -E",[97,1583,1584],{"class":376}," \"pandas|matplotlib\"",[97,1586,1587],{"class":110}," ||",[97,1589,1590],{"class":196}," echo",[97,1592,1593],{"class":376}," \"no heavy imports on --help\"\n",[97,1595,1596,1599,1602,1605,1608],{"class":99,"line":118},[97,1597,1598],{"class":177},"no",[97,1600,1601],{"class":376}," heavy",[97,1603,1604],{"class":376}," imports",[97,1606,1607],{"class":376}," on",[97,1609,1610],{"class":196}," --help\n",[97,1612,1613],{"class":99,"line":135},[97,1614,171],{"emptyLinePlaceholder":170},[97,1616,1617],{"class":99,"line":151},[97,1618,1619],{"class":103},"# They SHOULD appear only when the command runs.\n",[97,1621,1622,1624,1626,1628,1630,1632,1634,1636,1639,1641,1643,1645,1648],{"class":99,"line":167},[97,1623,1551],{"class":177},[97,1625,1554],{"class":376},[97,1627,1557],{"class":196},[97,1629,1560],{"class":376},[97,1631,1563],{"class":196},[97,1633,1566],{"class":376},[97,1635,1010],{"class":376},[97,1637,1638],{"class":376}," data.csv",[97,1640,1572],{"class":110},[97,1642,1575],{"class":110},[97,1644,1578],{"class":177},[97,1646,1647],{"class":196}," -c",[97,1649,1650],{"class":376}," pandas\n",[97,1652,1653],{"class":99,"line":174},[97,1654,1655],{"class":177},"1\n",[10,1657,1658,1659,1661,1662,1664,1665,1668,1669,1672,1673,1676,1677,59],{},"The first command confirms ",[14,1660,20],{}," no longer drags in ",[14,1663,247],{},"; the second confirms it loads exactly when ",[14,1666,1667],{},"convert"," runs. For the full profiling workflow — reading the cumulative column, visualizing with ",[14,1670,1671],{},"tuna",", and timing wall-clock with ",[14,1674,1675],{},"hyperfine"," — see ",[1450,1678,1680],{"href":1679},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fprofiling-python-cli-startup-time\u002F","profiling Python CLI startup time",[23,1682,1684],{"id":1683},"production-notes","Production notes",[28,1686,1687,1698,1719,1725,1735],{},[31,1688,1689,1694,1695,1697],{},[54,1690,1691,1693],{},[14,1692,47],{}," must stay cheap."," If you ever compute command names by importing modules and inspecting them, you have reintroduced the eager cost on ",[14,1696,20],{},". Keep names as static strings.",[31,1699,1700,1706,1707,1711,1712,1715,1716,1718],{},[54,1701,1702,1703,1705],{},"Completion calls ",[14,1704,47],{}," too."," Shell completion of subcommand names goes through the same path, so lazy loading keeps ",[1450,1708,1710],{"href":1709},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002F","tab completion"," instant. Completing ",[261,1713,1714],{},"arguments",", however, invokes ",[14,1717,51],{},", so a command whose options need heavy imports will pay on argument completion — keep option definitions light.",[31,1720,1721,1724],{},[54,1722,1723],{},"Import errors surface late."," With eager imports a broken command fails at startup; with lazy loading it fails only when invoked. That is usually what you want (one broken command doesn't down the whole CLI), but add a test that imports every registered module so CI still catches breakage early.",[31,1726,1727,1730,1731,1734],{},[54,1728,1729],{},"Bytecode caching matters in benchmarks."," First run compiles ",[14,1732,1733],{},".pyc"," files; measure a warm run for realistic numbers.",[31,1736,1737,1740,1741,1745,1746,59],{},[54,1738,1739],{},"Structure first."," Per-command lazy loading assumes one module per command. If your CLI is still a monolith, split it following ",[1450,1742,1744],{"href":1743},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fhow-to-structure-a-large-python-cli-project\u002F","how to structure a large Python CLI project"," before adding a ",[14,1747,58],{},[23,1749,1751],{"id":1750},"related","Related",[28,1753,1754,1761,1767,1773,1783],{},[31,1755,1756,1760],{},[1450,1757,1759],{"href":1758},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002F","CLI Startup Performance and Lazy Loading"," — the overview this guide sits under.",[31,1762,1763,1766],{},[1450,1764,1765],{"href":1679},"Profiling Python CLI startup time"," — measure the before and after.",[31,1768,1769,1772],{},[1450,1770,1771],{"href":1743},"How to structure a large Python CLI project"," — the one-module-per-command layout this builds on.",[31,1774,1775,1778,1779,1782],{},[1450,1776,1777],{"href":1452},"Best practices for Python CLI entry points"," — the same ",[14,1780,1781],{},"module:attr"," string convention.",[31,1784,1785,1787,1788,1790],{},[1450,1786,1521],{"href":1520}," — why Click's ",[14,1789,16],{}," subclassing helps here.",[1792,1793,1794],"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 .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}",{"title":93,"searchDepth":107,"depth":107,"links":1796},[1797,1798,1799,1802,1803,1804,1805,1806],{"id":25,"depth":107,"text":26},{"id":82,"depth":107,"text":83},{"id":270,"depth":107,"text":271,"children":1800},[1801],{"id":1124,"depth":118,"text":1125},{"id":1430,"depth":107,"text":1431},{"id":1471,"depth":107,"text":1472},{"id":1524,"depth":107,"text":1525},{"id":1683,"depth":107,"text":1684},{"id":1750,"depth":107,"text":1751},"2026-07-05","Speed up a multi-command Python CLI by lazy-loading subcommands: defer heavy imports until a command runs with a custom Click lazy group.","advanced",false,"md",{},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup",{"title":5,"description":1808},"modern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup\u002Findex",[1817,1818,1819,364,1820],"lazy-loading","startup","performance","typer","dTT_PlNDFrQJu1dK8dei_I-_IGTJl_92nR2Khw_kBPc",[1823,1826,1829,1832,1835,1838,1841,1844,1847,1850,1853,1856,1859,1862,1865,1868,1871,1874,1877,1880,1883,1886,1889,1892,1895,1898,1901,1904,1907,1910,1913,1916,1919,1921,1922,1925,1928,1931,1934,1937,1940,1943,1946,1949,1951,1954,1957,1960,1963,1966,1969,1972,1975,1978,1981,1984,1987,1990,1993,1996,1999,2002,2005,2008,2011,2014,2017,2020,2023,2026,2029,2032,2035,2038,2041,2044,2047,2050,2053,2056,2059,2062,2065],{"path":1824,"title":1825},"\u002Fabout","About Python CLI Toolcraft",{"path":1827,"title":1828},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies","Advanced Argument Validation Strategies",{"path":1830,"title":1831},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fparsing-nested-json-arguments-in-python-clis","Parsing Nested JSON Args in Python CLIs",{"path":1833,"title":1834},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fvalidating-file-and-directory-paths-in-clis","Validating File and Directory Paths in CLIs",{"path":1836,"title":1837},"\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":1839,"title":1840},"\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":1842,"title":1843},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation","CLI Help Output and Documentation",{"path":1845,"title":1846},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fversioning-and-deprecating-cli-flags","Versioning and Deprecating CLI Flags",{"path":1848,"title":1849},"\u002Fadvanced-input-parsing-user-experience\u002Fcli-help-output-and-documentation\u002Fwriting-help-text-users-actually-read","Writing Help Text Users Actually Read",{"path":1851,"title":1852},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fchoosing-exit-codes-for-cli-tools","Choosing Exit Codes for CLI Tools",{"path":1854,"title":1855},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Ffriendly-error-messages-and-tracebacks","Friendly Error Messages and Tracebacks",{"path":1857,"title":1858},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fhandling-keyboard-interrupt-cleanly","Handling Keyboard Interrupt Cleanly",{"path":1860,"title":1861},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes","Error Handling and Exit Codes for CLIs",{"path":1863,"title":1864},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fconfig-precedence-flags-env-files-defaults","Config Precedence: Flags, Env, Files, Defaults",{"path":1866,"title":1867},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars","Handling Config Files and Env Vars in CLIs",{"path":1869,"title":1870},"\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":1872,"title":1873},"\u002Fadvanced-input-parsing-user-experience","Advanced Input Parsing for Python CLIs",{"path":1875,"title":1876},"\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":1878,"title":1879},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich","Interactive Terminal UI with Rich",{"path":1881,"title":1882},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich\u002Frendering-tables-and-json-with-rich","Rendering Tables and JSON with Rich",{"path":1884,"title":1885},"\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":1887,"title":1888},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis","Shell Completion for Python CLIs",{"path":1890,"title":1891},"\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":1893,"title":1894},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-verbose-and-quiet-logging-flags","Adding Verbose and Quiet Logging Flags",{"path":1896,"title":1897},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps","Structured Logging for CLI Apps",{"path":1899,"title":1900},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fstructured-json-logging-in-python-clis","Structured JSON Logging in Python CLIs",{"path":1902,"title":1903},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fdetecting-tty-and-adapting-output","Detecting a TTY and Adapting Output",{"path":1905,"title":1906},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Femitting-json-output-for-scripting","Emitting JSON Output for Scripting",{"path":1908,"title":1909},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Fhandling-broken-pipe-and-sigpipe","Handling Broken Pipe and SIGPIPE",{"path":1911,"title":1912},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes","Working with stdin, stdout and Pipes",{"path":1914,"title":1915},"\u002Fadvanced-input-parsing-user-experience\u002Fworking-with-stdin-stdout-and-pipes\u002Freading-piped-input-in-python-clis","Reading Piped Input in Python CLIs",{"path":1917,"title":1918},"\u002F","Python CLI Toolcraft",{"path":1920,"title":1759},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading",{"path":1813,"title":5},{"path":1923,"title":1924},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fprofiling-python-cli-startup-time","Profiling Python CLI Startup Time",{"path":1926,"title":1927},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Freducing-cli-dependency-weight","Reducing CLI Dependency Weight",{"path":1929,"title":1930},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-subparsers-for-subcommands","argparse Subparsers for Subcommands",{"path":1932,"title":1933},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-vs-click-vs-typer-comparison","argparse vs Click vs Typer Compared",{"path":1935,"title":1936},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse","Command-Line Parsing with argparse",{"path":1938,"title":1939},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmigrating-from-argparse-to-typer","Migrating from argparse to Typer",{"path":1941,"title":1942},"\u002Fmodern-python-cli-frameworks-architecture","Python CLI Frameworks and Architecture",{"path":1944,"title":1945},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis","Plugin Architectures for Extensible CLIs",{"path":1947,"title":1948},"\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":1950,"title":1777},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fbest-practices-for-python-cli-entry-points",{"path":1952,"title":1953},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fdependency-injection-patterns-for-cli-commands","Dependency Injection Patterns for CLI Commands",{"path":1955,"title":1956},"\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":1958,"title":1959},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis","Structuring Multi-Command Python CLIs",{"path":1961,"title":1962},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-state-with-click-context-objects","Sharing State with Click Context Objects",{"path":1964,"title":1965},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications","Testing Python CLI Applications",{"path":1967,"title":1968},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fmeasuring-cli-test-coverage","Measuring CLI Test Coverage",{"path":1970,"title":1971},"\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":1973,"title":1974},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Fsnapshot-testing-cli-output","Snapshot Testing CLI Output",{"path":1976,"title":1977},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-click-commands-with-clirunner","Testing Click Commands with CliRunner",{"path":1979,"title":1980},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftesting-python-cli-applications\u002Ftesting-interactive-prompts-and-stdin","Testing Interactive Prompts and stdin",{"path":1982,"title":1983},"\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":1985,"title":1986},"\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":1988,"title":1989},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each","Typer vs Click: When to Use Each",{"path":1991,"title":1992},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Ftyper-callback-functions-explained","Typer callback functions explained",{"path":1994,"title":1995},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter\u002Fcopier-vs-cookiecutter-for-cli-templates","Copier vs Cookiecutter for CLI Templates",{"path":1997,"title":1998},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter","CLI Project Scaffolding with Cookiecutter",{"path":2000,"title":2001},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbuilding-cross-platform-release-binaries-in-ci","Building Cross-Platform Release Binaries in CI",{"path":2003,"title":2004},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fbundling-a-python-cli-with-pyinstaller","Bundling a Python CLI with PyInstaller",{"path":2006,"title":2007},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries\u002Fhomebrew-and-scoop-packaging-for-python-clis","Homebrew and Scoop Packaging for Python CLIs",{"path":2009,"title":2010},"\u002Fproject-setup-dependency-management\u002Fdistributing-clis-as-standalone-binaries","Distributing CLIs as Standalone Binaries",{"path":2012,"title":2013},"\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":2015,"title":2016},"\u002Fproject-setup-dependency-management","Project Setup & Dependency Management",{"path":2018,"title":2019},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fautomating-changelogs-with-conventional-commits","Automating Changelogs with Conventional Commits",{"path":2021,"title":2022},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fexposing-version-info-and-build-metadata","Exposing Version Info and Build Metadata",{"path":2024,"title":2025},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs","Managing CLI Versioning & Changelogs",{"path":2027,"title":2028},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbuilding-wheels-and-sdists-for-python-clis","Building Wheels and sdists for Python CLIs",{"path":2030,"title":2031},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution","Packaging Python CLIs for Distribution",{"path":2033,"title":2034},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Finstalling-and-distributing-clis-with-pipx","Installing and Distributing CLIs with pipx",{"path":2036,"title":2037},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fpublishing-a-python-cli-to-pypi","Publishing a Python CLI to PyPI",{"path":2039,"title":2040},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development","Poetry Workflows for CLI Development",{"path":2042,"title":2043},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-entry-points-and-scripts-for-clis","Poetry Entry Points and Scripts for CLIs",{"path":2045,"title":2046},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects","Pre-commit Hooks for CLI Projects",{"path":2048,"title":2049},"\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":2051,"title":2052},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management","uv for Python CLI Dependency Management",{"path":2054,"title":2055},"\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":2057,"title":2058},"\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":2060,"title":2061},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices","Python CLI Env Isolation Best Practices",{"path":2063,"title":2064},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fmanaging-virtual-environments-for-cross-platform-clis","Managing Python CLI Virtual Environments",{"path":2066,"title":2067},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fpinning-the-python-version-for-a-cli","Pinning the Python Version for a CLI",1785614690031]