[{"data":1,"prerenderedAt":1962},["ShallowReactive",2],{"page-\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup\u002F":3,"content-directory":1812},{"id":4,"title":5,"body":6,"date":1797,"description":1798,"difficulty":1799,"draft":1800,"extension":1801,"meta":1802,"navigation":170,"path":1803,"seo":1804,"stem":1805,"tags":1806,"updated":1797,"__hash__":1811},"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":1785},"minimark",[9,22,27,80,84,87,230,257,268,272,299,772,779,934,941,1083,1117,1122,1125,1401,1424,1428,1450,1462,1466,1469,1505,1515,1519,1525,1646,1671,1675,1738,1742,1781],[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.",[88,300,302],{"className":90,"code":301,"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,303,304,309,322,326,333,339,343,347,368,374,378,383,388,393,398,410,416,425,455,464,474,500,529,534,550,556,584,589,611,629,640,651,656,672,691,702,716,730,764],{"__ignoreMap":93},[97,305,306],{"class":99,"line":100},[97,307,308],{"class":103},"# lazy_group.py\n",[97,310,311,313,316,319],{"class":99,"line":107},[97,312,121],{"class":110},[97,314,315],{"class":196}," __future__",[97,317,318],{"class":110}," import",[97,320,321],{"class":114}," annotations\n",[97,323,324],{"class":99,"line":118},[97,325,171],{"emptyLinePlaceholder":170},[97,327,328,330],{"class":99,"line":135},[97,329,111],{"class":110},[97,331,332],{"class":114}," importlib\n",[97,334,335,337],{"class":99,"line":151},[97,336,111],{"class":110},[97,338,115],{"class":114},[97,340,341],{"class":99,"line":167},[97,342,171],{"emptyLinePlaceholder":170},[97,344,345],{"class":99,"line":174},[97,346,171],{"emptyLinePlaceholder":170},[97,348,349,352,355,358,361,363,365],{"class":99,"line":184},[97,350,351],{"class":110},"class",[97,353,354],{"class":177}," LazyGroup",[97,356,357],{"class":114},"(",[97,359,360],{"class":177},"click",[97,362,59],{"class":114},[97,364,16],{"class":177},[97,366,367],{"class":114},"):\n",[97,369,370],{"class":99,"line":203},[97,371,373],{"class":372},"sZZnC","    \"\"\"A click.Group whose subcommands are imported on first use.\n",[97,375,376],{"class":99,"line":209},[97,377,171],{"emptyLinePlaceholder":170},[97,379,380],{"class":99,"line":214},[97,381,382],{"class":372},"    lazy_subcommands maps a command name to a \"module.path:attribute\"\n",[97,384,385],{"class":99,"line":220},[97,386,387],{"class":372},"    string. The module is imported only when that command is invoked.\n",[97,389,390],{"class":99,"line":226},[97,391,392],{"class":372},"    \"\"\"\n",[97,394,396],{"class":99,"line":395},14,[97,397,171],{"emptyLinePlaceholder":170},[97,399,401,404,407],{"class":99,"line":400},15,[97,402,403],{"class":110},"    def",[97,405,406],{"class":196}," __init__",[97,408,409],{"class":114},"(\n",[97,411,413],{"class":99,"line":412},16,[97,414,415],{"class":114},"        self,\n",[97,417,419,422],{"class":99,"line":418},17,[97,420,421],{"class":110},"        *",[97,423,424],{"class":114},"args,\n",[97,426,428,431,434,436,438,441,444,447,450,452],{"class":99,"line":427},18,[97,429,430],{"class":114},"        lazy_subcommands: dict[",[97,432,433],{"class":196},"str",[97,435,248],{"class":114},[97,437,433],{"class":196},[97,439,440],{"class":114},"] ",[97,442,443],{"class":110},"|",[97,445,446],{"class":196}," None",[97,448,449],{"class":110}," =",[97,451,446],{"class":196},[97,453,454],{"class":114},",\n",[97,456,458,461],{"class":99,"line":457},19,[97,459,460],{"class":110},"        **",[97,462,463],{"class":114},"kwargs,\n",[97,465,467,470,472],{"class":99,"line":466},20,[97,468,469],{"class":114},"    ) -> ",[97,471,197],{"class":196},[97,473,200],{"class":114},[97,475,477,480,483,486,488,491,494,497],{"class":99,"line":476},21,[97,478,479],{"class":196},"        super",[97,481,482],{"class":114},"().",[97,484,485],{"class":196},"__init__",[97,487,357],{"class":114},[97,489,490],{"class":110},"*",[97,492,493],{"class":114},"args, ",[97,495,496],{"class":110},"**",[97,498,499],{"class":114},"kwargs)\n",[97,501,503,506,509,511,513,515,517,520,523,526],{"class":99,"line":502},22,[97,504,505],{"class":196},"        self",[97,507,508],{"class":114},"._lazy: dict[",[97,510,433],{"class":196},[97,512,248],{"class":114},[97,514,433],{"class":196},[97,516,440],{"class":114},[97,518,519],{"class":110},"=",[97,521,522],{"class":114}," lazy_subcommands ",[97,524,525],{"class":110},"or",[97,527,528],{"class":114}," {}\n",[97,530,532],{"class":99,"line":531},23,[97,533,171],{"emptyLinePlaceholder":170},[97,535,537,539,542,545,547],{"class":99,"line":536},24,[97,538,403],{"class":110},[97,540,541],{"class":177}," list_commands",[97,543,544],{"class":114},"(self, ctx: click.Context) -> list[",[97,546,433],{"class":196},[97,548,549],{"class":114},"]:\n",[97,551,553],{"class":99,"line":552},25,[97,554,555],{"class":103},"        # Eagerly-added commands + lazy names, without importing anything.\n",[97,557,559,562,565,568,570,573,576,578,581],{"class":99,"line":558},26,[97,560,561],{"class":110},"        return",[97,563,564],{"class":196}," sorted",[97,566,567],{"class":114},"({",[97,569,490],{"class":110},[97,571,572],{"class":196},"super",[97,574,575],{"class":114},"().list_commands(ctx), ",[97,577,490],{"class":110},[97,579,580],{"class":196},"self",[97,582,583],{"class":114},"._lazy})\n",[97,585,587],{"class":99,"line":586},27,[97,588,171],{"emptyLinePlaceholder":170},[97,590,592,594,597,600,602,605,607,609],{"class":99,"line":591},28,[97,593,403],{"class":110},[97,595,596],{"class":177}," get_command",[97,598,599],{"class":114},"(self, ctx: click.Context, name: ",[97,601,433],{"class":196},[97,603,604],{"class":114},") -> click.Command ",[97,606,443],{"class":110},[97,608,446],{"class":196},[97,610,200],{"class":114},[97,612,614,617,620,623,626],{"class":99,"line":613},29,[97,615,616],{"class":110},"        if",[97,618,619],{"class":114}," name ",[97,621,622],{"class":110},"in",[97,624,625],{"class":196}," self",[97,627,628],{"class":114},"._lazy:\n",[97,630,632,635,637],{"class":99,"line":631},30,[97,633,634],{"class":110},"            return",[97,636,625],{"class":196},[97,638,639],{"class":114},"._load(name)\n",[97,641,643,645,648],{"class":99,"line":642},31,[97,644,561],{"class":110},[97,646,647],{"class":196}," super",[97,649,650],{"class":114},"().get_command(ctx, name)\n",[97,652,654],{"class":99,"line":653},32,[97,655,171],{"emptyLinePlaceholder":170},[97,657,659,661,664,667,669],{"class":99,"line":658},33,[97,660,403],{"class":110},[97,662,663],{"class":177}," _load",[97,665,666],{"class":114},"(self, name: ",[97,668,433],{"class":196},[97,670,671],{"class":114},") -> click.Command:\n",[97,673,675,678,680,682,685,688],{"class":99,"line":674},34,[97,676,677],{"class":114},"        module_path, _, attr ",[97,679,519],{"class":110},[97,681,625],{"class":196},[97,683,684],{"class":114},"._lazy[name].partition(",[97,686,687],{"class":372},"\":\"",[97,689,690],{"class":114},")\n",[97,692,694,697,699],{"class":99,"line":693},35,[97,695,696],{"class":114},"        module ",[97,698,519],{"class":110},[97,700,701],{"class":114}," importlib.import_module(module_path)\n",[97,703,705,708,710,713],{"class":99,"line":704},36,[97,706,707],{"class":114},"        cmd ",[97,709,519],{"class":110},[97,711,712],{"class":196}," getattr",[97,714,715],{"class":114},"(module, attr)\n",[97,717,719,721,724,727],{"class":99,"line":718},37,[97,720,616],{"class":110},[97,722,723],{"class":110}," not",[97,725,726],{"class":196}," isinstance",[97,728,729],{"class":114},"(cmd, click.Command):\n",[97,731,733,736,739,741,744,747,750,753,756,759,762],{"class":99,"line":732},38,[97,734,735],{"class":110},"            raise",[97,737,738],{"class":196}," TypeError",[97,740,357],{"class":114},[97,742,743],{"class":110},"f",[97,745,746],{"class":372},"\"",[97,748,749],{"class":196},"{self",[97,751,752],{"class":114},"._lazy[name]",[97,754,755],{"class":110},"!r",[97,757,758],{"class":196},"}",[97,760,761],{"class":372}," is not a click.Command\"",[97,763,690],{"class":114},[97,765,767,769],{"class":99,"line":766},39,[97,768,561],{"class":110},[97,770,771],{"class":114}," cmd\n",[10,773,774,775,778],{},"Wiring the CLI to use it means passing the class and a registry of string paths — and crucially, ",[261,776,777],{},"not"," importing the command modules:",[88,780,782],{"className":90,"code":781,"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,783,784,789,795,807,811,815,821,832,842,855,867,879,884,888,900,905,909,913,929],{"__ignoreMap":93},[97,785,786],{"class":99,"line":100},[97,787,788],{"class":103},"# cli.py — the lazy version. Note: no `from .commands... import ...`\n",[97,790,791,793],{"class":99,"line":107},[97,792,111],{"class":110},[97,794,115],{"class":114},[97,796,797,799,802,804],{"class":99,"line":118},[97,798,121],{"class":110},[97,800,801],{"class":114}," .lazy_group ",[97,803,111],{"class":110},[97,805,806],{"class":114}," LazyGroup\n",[97,808,809],{"class":99,"line":135},[97,810,171],{"emptyLinePlaceholder":170},[97,812,813],{"class":99,"line":151},[97,814,171],{"emptyLinePlaceholder":170},[97,816,817,819],{"class":99,"line":167},[97,818,178],{"class":177},[97,820,409],{"class":114},[97,822,823,827,829],{"class":99,"line":174},[97,824,826],{"class":825},"s4XuR","    cls",[97,828,519],{"class":110},[97,830,831],{"class":114},"LazyGroup,\n",[97,833,834,837,839],{"class":99,"line":184},[97,835,836],{"class":825},"    lazy_subcommands",[97,838,519],{"class":110},[97,840,841],{"class":114},"{\n",[97,843,844,847,850,853],{"class":99,"line":203},[97,845,846],{"class":372},"        \"convert\"",[97,848,849],{"class":114},": ",[97,851,852],{"class":372},"\"myapp.commands.convert:convert\"",[97,854,454],{"class":114},[97,856,857,860,862,865],{"class":99,"line":209},[97,858,859],{"class":372},"        \"fetch\"",[97,861,849],{"class":114},[97,863,864],{"class":372},"\"myapp.commands.fetch:fetch\"",[97,866,454],{"class":114},[97,868,869,872,874,877],{"class":99,"line":214},[97,870,871],{"class":372},"        \"report\"",[97,873,849],{"class":114},[97,875,876],{"class":372},"\"myapp.commands.report:report\"",[97,878,454],{"class":114},[97,880,881],{"class":99,"line":220},[97,882,883],{"class":114},"    },\n",[97,885,886],{"class":99,"line":226},[97,887,690],{"class":114},[97,889,890,892,894,896,898],{"class":99,"line":395},[97,891,187],{"class":110},[97,893,190],{"class":177},[97,895,193],{"class":114},[97,897,197],{"class":196},[97,899,200],{"class":114},[97,901,902],{"class":99,"line":400},[97,903,904],{"class":372},"    \"\"\"myapp — does three heavy things, but starts instantly.\"\"\"\n",[97,906,907],{"class":99,"line":412},[97,908,171],{"emptyLinePlaceholder":170},[97,910,911],{"class":99,"line":418},[97,912,171],{"emptyLinePlaceholder":170},[97,914,915,918,921,924,927],{"class":99,"line":427},[97,916,917],{"class":110},"if",[97,919,920],{"class":196}," __name__",[97,922,923],{"class":110}," ==",[97,925,926],{"class":372}," \"__main__\"",[97,928,200],{"class":114},[97,930,931],{"class":99,"line":457},[97,932,933],{"class":114},"    cli()\n",[10,935,936,937,940],{},"Each command module is written exactly as before — an ordinary ",[14,938,939],{},"@click.command()"," with its heavy imports at the top:",[88,942,944],{"className":90,"code":943,"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,945,946,951,957,973,977,981,988,1000,1019,1024,1034,1050],{"__ignoreMap":93},[97,947,948],{"class":99,"line":100},[97,949,950],{"class":103},"# myapp\u002Fcommands\u002Fconvert.py\n",[97,952,953,955],{"class":99,"line":107},[97,954,111],{"class":110},[97,956,115],{"class":114},[97,958,959,961,964,967,970],{"class":99,"line":118},[97,960,111],{"class":110},[97,962,963],{"class":114}," pandas ",[97,965,966],{"class":110},"as",[97,968,969],{"class":114}," pd        ",[97,971,972],{"class":103},"# stays at module top; only imported when convert runs\n",[97,974,975],{"class":99,"line":135},[97,976,171],{"emptyLinePlaceholder":170},[97,978,979],{"class":99,"line":151},[97,980,171],{"emptyLinePlaceholder":170},[97,982,983,986],{"class":99,"line":167},[97,984,985],{"class":177},"@click.command",[97,987,181],{"class":114},[97,989,990,993,995,998],{"class":99,"line":174},[97,991,992],{"class":177},"@click.argument",[97,994,357],{"class":114},[97,996,997],{"class":372},"\"path\"",[97,999,690],{"class":114},[97,1001,1002,1004,1007,1010,1012,1015,1017],{"class":99,"line":184},[97,1003,187],{"class":110},[97,1005,1006],{"class":177}," convert",[97,1008,1009],{"class":114},"(path: ",[97,1011,433],{"class":196},[97,1013,1014],{"class":114},") -> ",[97,1016,197],{"class":196},[97,1018,200],{"class":114},[97,1020,1021],{"class":99,"line":203},[97,1022,1023],{"class":372},"    \"\"\"Convert a CSV to Parquet.\"\"\"\n",[97,1025,1026,1029,1031],{"class":99,"line":209},[97,1027,1028],{"class":114},"    df ",[97,1030,519],{"class":110},[97,1032,1033],{"class":114}," pd.read_csv(path)\n",[97,1035,1036,1039,1042,1044,1047],{"class":99,"line":214},[97,1037,1038],{"class":114},"    df.to_parquet(path.replace(",[97,1040,1041],{"class":372},"\".csv\"",[97,1043,248],{"class":114},[97,1045,1046],{"class":372},"\".parquet\"",[97,1048,1049],{"class":114},"))\n",[97,1051,1052,1055,1057,1060,1063,1066,1069,1071,1074,1077,1079,1081],{"class":99,"line":220},[97,1053,1054],{"class":114},"    click.echo(",[97,1056,743],{"class":110},[97,1058,1059],{"class":372},"\"wrote ",[97,1061,1062],{"class":196},"{",[97,1064,1065],{"class":114},"path.replace(",[97,1067,1068],{"class":372},"'.csv'",[97,1070,248],{"class":114},[97,1072,1073],{"class":372},"'.parquet'",[97,1075,1076],{"class":114},")",[97,1078,758],{"class":196},[97,1080,746],{"class":372},[97,1082,690],{"class":114},[10,1084,1085,1086,1088,1089,1091,1092,1095,1096,1098,1099,1101,1102,1105,1106,1109,1110,1113,1114,1116],{},"Now ",[14,1087,243],{}," calls ",[14,1090,47],{},", which returns ",[14,1093,1094],{},"[\"convert\", \"fetch\", \"report\"]"," as plain strings — no module is imported, no ",[14,1097,247],{},", no ",[14,1100,255],{},". Only ",[14,1103,1104],{},"mycli convert data.csv"," triggers ",[14,1107,1108],{},"get_command(\"convert\")",", which imports ",[14,1111,1112],{},"myapp.commands.convert"," and its ",[14,1115,247],{}," at that moment. The user pays for exactly the command they ran.",[1118,1119,1121],"h3",{"id":1120},"a-self-contained-version-you-can-run-now","A self-contained version you can run now",[10,1123,1124],{},"To see the behavior without a package, register modules from the standard library and print when each is loaded:",[88,1126,1128],{"className":90,"code":1127,"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,1129,1130,1136,1142,1146,1150,1166,1191,1209,1224,1228,1237,1257,1261,1270,1282,1297,1331,1340,1348,1352,1356,1388,1397],{"__ignoreMap":93},[97,1131,1132,1134],{"class":99,"line":100},[97,1133,111],{"class":110},[97,1135,332],{"class":114},[97,1137,1138,1140],{"class":99,"line":107},[97,1139,111],{"class":110},[97,1141,115],{"class":114},[97,1143,1144],{"class":99,"line":118},[97,1145,171],{"emptyLinePlaceholder":170},[97,1147,1148],{"class":99,"line":135},[97,1149,171],{"emptyLinePlaceholder":170},[97,1151,1152,1154,1156,1158,1160,1162,1164],{"class":99,"line":151},[97,1153,351],{"class":110},[97,1155,354],{"class":177},[97,1157,357],{"class":114},[97,1159,360],{"class":177},[97,1161,59],{"class":114},[97,1163,16],{"class":177},[97,1165,367],{"class":114},[97,1167,1168,1170,1172,1175,1177,1180,1182,1184,1186,1188],{"class":99,"line":167},[97,1169,403],{"class":110},[97,1171,406],{"class":196},[97,1173,1174],{"class":114},"(self, ",[97,1176,490],{"class":110},[97,1178,1179],{"class":114},"args, lazy_subcommands",[97,1181,519],{"class":110},[97,1183,197],{"class":196},[97,1185,248],{"class":114},[97,1187,496],{"class":110},[97,1189,1190],{"class":114},"kwargs):\n",[97,1192,1193,1195,1197,1199,1201,1203,1205,1207],{"class":99,"line":174},[97,1194,479],{"class":196},[97,1196,482],{"class":114},[97,1198,485],{"class":196},[97,1200,357],{"class":114},[97,1202,490],{"class":110},[97,1204,493],{"class":114},[97,1206,496],{"class":110},[97,1208,499],{"class":114},[97,1210,1211,1213,1216,1218,1220,1222],{"class":99,"line":184},[97,1212,505],{"class":196},[97,1214,1215],{"class":114},"._lazy ",[97,1217,519],{"class":110},[97,1219,522],{"class":114},[97,1221,525],{"class":110},[97,1223,528],{"class":114},[97,1225,1226],{"class":99,"line":203},[97,1227,171],{"emptyLinePlaceholder":170},[97,1229,1230,1232,1234],{"class":99,"line":209},[97,1231,403],{"class":110},[97,1233,541],{"class":177},[97,1235,1236],{"class":114},"(self, ctx):\n",[97,1238,1239,1241,1243,1245,1247,1249,1251,1253,1255],{"class":99,"line":214},[97,1240,561],{"class":110},[97,1242,564],{"class":196},[97,1244,567],{"class":114},[97,1246,490],{"class":110},[97,1248,572],{"class":196},[97,1250,575],{"class":114},[97,1252,490],{"class":110},[97,1254,580],{"class":196},[97,1256,583],{"class":114},[97,1258,1259],{"class":99,"line":220},[97,1260,171],{"emptyLinePlaceholder":170},[97,1262,1263,1265,1267],{"class":99,"line":226},[97,1264,403],{"class":110},[97,1266,596],{"class":177},[97,1268,1269],{"class":114},"(self, ctx, name):\n",[97,1271,1272,1274,1276,1278,1280],{"class":99,"line":395},[97,1273,616],{"class":110},[97,1275,619],{"class":114},[97,1277,622],{"class":110},[97,1279,625],{"class":196},[97,1281,628],{"class":114},[97,1283,1284,1287,1289,1291,1293,1295],{"class":99,"line":400},[97,1285,1286],{"class":114},"            module_path, _, attr ",[97,1288,519],{"class":110},[97,1290,625],{"class":196},[97,1292,684],{"class":114},[97,1294,687],{"class":372},[97,1296,690],{"class":114},[97,1298,1299,1302,1304,1306,1309,1311,1314,1316,1319,1321,1324,1326,1329],{"class":99,"line":412},[97,1300,1301],{"class":196},"            print",[97,1303,357],{"class":114},[97,1305,743],{"class":110},[97,1307,1308],{"class":372},"\"[lazy] importing ",[97,1310,1062],{"class":196},[97,1312,1313],{"class":114},"module_path",[97,1315,758],{"class":196},[97,1317,1318],{"class":372}," for '",[97,1320,1062],{"class":196},[97,1322,1323],{"class":114},"name",[97,1325,758],{"class":196},[97,1327,1328],{"class":372},"'\"",[97,1330,690],{"class":114},[97,1332,1333,1335,1337],{"class":99,"line":418},[97,1334,634],{"class":110},[97,1336,712],{"class":196},[97,1338,1339],{"class":114},"(importlib.import_module(module_path), attr)\n",[97,1341,1342,1344,1346],{"class":99,"line":427},[97,1343,561],{"class":110},[97,1345,647],{"class":196},[97,1347,650],{"class":114},[97,1349,1350],{"class":99,"line":457},[97,1351,171],{"emptyLinePlaceholder":170},[97,1353,1354],{"class":99,"line":466},[97,1355,171],{"emptyLinePlaceholder":170},[97,1357,1358,1360,1362,1365,1367,1370,1373,1375,1377,1380,1382,1385],{"class":99,"line":476},[97,1359,178],{"class":177},[97,1361,357],{"class":114},[97,1363,1364],{"class":825},"cls",[97,1366,519],{"class":110},[97,1368,1369],{"class":114},"LazyGroup, ",[97,1371,1372],{"class":825},"lazy_subcommands",[97,1374,519],{"class":110},[97,1376,1062],{"class":114},[97,1378,1379],{"class":372},"\"hi\"",[97,1381,849],{"class":114},[97,1383,1384],{"class":372},"\"_lazy_cmds:hi\"",[97,1386,1387],{"class":114},"})\n",[97,1389,1390,1392,1394],{"class":99,"line":502},[97,1391,187],{"class":110},[97,1393,190],{"class":177},[97,1395,1396],{"class":114},"():\n",[97,1398,1399],{"class":99,"line":531},[97,1400,206],{"class":196},[10,1402,1403,1404,1407,1408,1411,1412,1415,1416,1419,1420,1423],{},"With a sibling ",[14,1405,1406],{},"_lazy_cmds.py"," defining a ",[14,1409,1410],{},"hi"," command, running ",[14,1413,1414],{},"python -m app --help"," prints the command list with no ",[14,1417,1418],{},"[lazy] importing"," line, while ",[14,1421,1422],{},"python -m app hi"," prints the import line first — proof the module loads only on invocation.",[23,1425,1427],{"id":1426},"the-string-path-registry-pattern","The string-path registry pattern",[10,1429,1430,1431,248,1434,1436,1437,1440,1441,1444,1445,59],{},"The heart of the technique is that a command is registered as a ",[54,1432,1433],{},"string",[14,1435,65],{},", not an imported object. A string can name a target without triggering its import; ",[14,1438,1439],{},"importlib.import_module"," resolves it later. This is the same ",[14,1442,1443],{},"module:attribute"," convention Python uses for console-script entry points, which is no coincidence — see ",[1446,1447,1449],"a",{"href":1448},"\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",[10,1451,1452,1453,1455,1456,1458,1459,1461],{},"Keep the registry in one place — the ",[14,1454,1372],{}," 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,1457,111],{}," a command module from ",[14,1460,239],{},". The instant you do, that command is eager again and the string registry buys you nothing.",[23,1463,1465],{"id":1464},"doing-the-same-in-typer","Doing the same in Typer",[10,1467,1468],{},"Typer builds on Click but does not expose a lazy-group option directly. Two workable approaches:",[28,1470,1471,1488],{},[31,1472,1473,1476,1477,1480,1481,1484,1485,1487],{},[54,1474,1475],{},"Reuse the Click LazyGroup."," A ",[14,1478,1479],{},"typer.Typer"," is convertible to a Click object with ",[14,1482,1483],{},"typer.main.get_command(app)",". For a Typer-first app you can define your top-level group as a Click ",[14,1486,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,1489,1490,1493,1494,1497,1498,1501,1502,1504],{},[54,1491,1492],{},"Split into deferred sub-apps."," Typer's ",[14,1495,1496],{},"app.add_typer(sub_app, name=...)"," still imports ",[14,1499,1500],{},"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,1503,51],{}," override.",[10,1506,1507,1508,1510,1511,59],{},"If you are choosing between the two frameworks for a startup-sensitive tool, Click's explicit ",[14,1509,16],{}," subclassing makes lazy loading a first-class, well-supported pattern, which is a real point in its favor — weigh it in ",[1446,1512,1514],{"href":1513},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002F","Typer vs Click: when to use each",[23,1516,1518],{"id":1517},"measuring-the-win-with-x-importtime","Measuring the win with -X importtime",[10,1520,1521,1522,1524],{},"Don't take the speedup on faith — prove it. ",[14,1523,75],{}," prints every import and its cost, so you can confirm heavy modules are absent from the help path:",[88,1526,1530],{"className":1527,"code":1528,"language":1529,"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,1531,1532,1537,1584,1601,1605,1610,1641],{"__ignoreMap":93},[97,1533,1534],{"class":99,"line":100},[97,1535,1536],{"class":103},"# Heavy modules should NOT appear here.\n",[97,1538,1539,1542,1545,1548,1551,1554,1557,1560,1563,1566,1569,1572,1575,1578,1581],{"class":99,"line":107},[97,1540,1541],{"class":177},"$",[97,1543,1544],{"class":372}," python",[97,1546,1547],{"class":196}," -X",[97,1549,1550],{"class":372}," importtime",[97,1552,1553],{"class":196}," -m",[97,1555,1556],{"class":372}," myapp",[97,1558,1559],{"class":196}," --help",[97,1561,1562],{"class":110}," 2>&1",[97,1564,1565],{"class":110}," |",[97,1567,1568],{"class":177}," grep",[97,1570,1571],{"class":196}," -E",[97,1573,1574],{"class":372}," \"pandas|matplotlib\"",[97,1576,1577],{"class":110}," ||",[97,1579,1580],{"class":196}," echo",[97,1582,1583],{"class":372}," \"no heavy imports on --help\"\n",[97,1585,1586,1589,1592,1595,1598],{"class":99,"line":118},[97,1587,1588],{"class":177},"no",[97,1590,1591],{"class":372}," heavy",[97,1593,1594],{"class":372}," imports",[97,1596,1597],{"class":372}," on",[97,1599,1600],{"class":196}," --help\n",[97,1602,1603],{"class":99,"line":135},[97,1604,171],{"emptyLinePlaceholder":170},[97,1606,1607],{"class":99,"line":151},[97,1608,1609],{"class":103},"# They SHOULD appear only when the command runs.\n",[97,1611,1612,1614,1616,1618,1620,1622,1624,1626,1629,1631,1633,1635,1638],{"class":99,"line":167},[97,1613,1541],{"class":177},[97,1615,1544],{"class":372},[97,1617,1547],{"class":196},[97,1619,1550],{"class":372},[97,1621,1553],{"class":196},[97,1623,1556],{"class":372},[97,1625,1006],{"class":372},[97,1627,1628],{"class":372}," data.csv",[97,1630,1562],{"class":110},[97,1632,1565],{"class":110},[97,1634,1568],{"class":177},[97,1636,1637],{"class":196}," -c",[97,1639,1640],{"class":372}," pandas\n",[97,1642,1643],{"class":99,"line":174},[97,1644,1645],{"class":177},"1\n",[10,1647,1648,1649,1651,1652,1654,1655,1658,1659,1662,1663,1666,1667,59],{},"The first command confirms ",[14,1650,20],{}," no longer drags in ",[14,1653,247],{},"; the second confirms it loads exactly when ",[14,1656,1657],{},"convert"," runs. For the full profiling workflow — reading the cumulative column, visualizing with ",[14,1660,1661],{},"tuna",", and timing wall-clock with ",[14,1664,1665],{},"hyperfine"," — see ",[1446,1668,1670],{"href":1669},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fprofiling-python-cli-startup-time\u002F","profiling Python CLI startup time",[23,1672,1674],{"id":1673},"production-notes","Production notes",[28,1676,1677,1688,1709,1715,1725],{},[31,1678,1679,1684,1685,1687],{},[54,1680,1681,1683],{},[14,1682,47],{}," must stay cheap."," If you ever compute command names by importing modules and inspecting them, you have reintroduced the eager cost on ",[14,1686,20],{},". Keep names as static strings.",[31,1689,1690,1696,1697,1701,1702,1705,1706,1708],{},[54,1691,1692,1693,1695],{},"Completion calls ",[14,1694,47],{}," too."," Shell completion of subcommand names goes through the same path, so lazy loading keeps ",[1446,1698,1700],{"href":1699},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis\u002F","tab completion"," instant. Completing ",[261,1703,1704],{},"arguments",", however, invokes ",[14,1707,51],{},", so a command whose options need heavy imports will pay on argument completion — keep option definitions light.",[31,1710,1711,1714],{},[54,1712,1713],{},"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,1716,1717,1720,1721,1724],{},[54,1718,1719],{},"Bytecode caching matters in benchmarks."," First run compiles ",[14,1722,1723],{},".pyc"," files; measure a warm run for realistic numbers.",[31,1726,1727,1730,1731,1735,1736,59],{},[54,1728,1729],{},"Structure first."," Per-command lazy loading assumes one module per command. If your CLI is still a monolith, split it following ",[1446,1732,1734],{"href":1733},"\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,1737,58],{},[23,1739,1741],{"id":1740},"related","Related",[28,1743,1744,1751,1757,1763,1773],{},[31,1745,1746,1750],{},[1446,1747,1749],{"href":1748},"\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,1752,1753,1756],{},[1446,1754,1755],{"href":1669},"Profiling Python CLI startup time"," — measure the before and after.",[31,1758,1759,1762],{},[1446,1760,1761],{"href":1733},"How to structure a large Python CLI project"," — the one-module-per-command layout this builds on.",[31,1764,1765,1768,1769,1772],{},[1446,1766,1767],{"href":1448},"Best practices for Python CLI entry points"," — the same ",[14,1770,1771],{},"module:attr"," string convention.",[31,1774,1775,1777,1778,1780],{},[1446,1776,1514],{"href":1513}," — why Click's ",[14,1779,16],{}," subclassing helps here.",[1782,1783,1784],"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":1786},[1787,1788,1789,1792,1793,1794,1795,1796],{"id":25,"depth":107,"text":26},{"id":82,"depth":107,"text":83},{"id":270,"depth":107,"text":271,"children":1790},[1791],{"id":1120,"depth":118,"text":1121},{"id":1426,"depth":107,"text":1427},{"id":1464,"depth":107,"text":1465},{"id":1517,"depth":107,"text":1518},{"id":1673,"depth":107,"text":1674},{"id":1740,"depth":107,"text":1741},"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":1798},"modern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Flazy-loading-subcommands-for-faster-startup\u002Findex",[1807,1808,1809,360,1810],"lazy-loading","startup","performance","typer","INjFG3Xe8R_1oRGery5G520qRu4ZNuYdA0AL3JgDk24",[1813,1816,1819,1822,1825,1828,1831,1834,1837,1840,1843,1846,1849,1852,1855,1858,1861,1864,1867,1870,1872,1873,1876,1879,1882,1885,1888,1891,1893,1896,1899,1902,1905,1908,1911,1914,1917,1920,1923,1926,1929,1932,1935,1938,1941,1944,1947,1950,1953,1956,1959],{"path":1814,"title":1815},"\u002Fabout","About Python CLI Toolcraft",{"path":1817,"title":1818},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies","Advanced Argument Validation Strategies",{"path":1820,"title":1821},"\u002Fadvanced-input-parsing-user-experience\u002Fadvanced-argument-validation-strategies\u002Fparsing-nested-json-arguments-in-python-clis","Parsing Nested JSON Args in Python CLIs",{"path":1823,"title":1824},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Fchoosing-exit-codes-for-cli-tools","Choosing Exit Codes for CLI Tools",{"path":1826,"title":1827},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes\u002Ffriendly-error-messages-and-tracebacks","Friendly Error Messages and Tracebacks",{"path":1829,"title":1830},"\u002Fadvanced-input-parsing-user-experience\u002Ferror-handling-and-exit-codes","Error Handling and Exit Codes for CLIs",{"path":1832,"title":1833},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars\u002Fconfig-precedence-flags-env-files-defaults","Config Precedence: Flags, Env, Files, Defaults",{"path":1835,"title":1836},"\u002Fadvanced-input-parsing-user-experience\u002Fhandling-configuration-files-env-vars","Handling Config Files and Env Vars in CLIs",{"path":1838,"title":1839},"\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":1841,"title":1842},"\u002Fadvanced-input-parsing-user-experience","Advanced Input Parsing for Python CLIs",{"path":1844,"title":1845},"\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":1847,"title":1848},"\u002Fadvanced-input-parsing-user-experience\u002Finteractive-terminal-ui-with-rich","Interactive Terminal UI with Rich",{"path":1850,"title":1851},"\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":1853,"title":1854},"\u002Fadvanced-input-parsing-user-experience\u002Fshell-completion-for-python-clis","Shell Completion for Python CLIs",{"path":1856,"title":1857},"\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":1859,"title":1860},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fadding-verbose-and-quiet-logging-flags","Adding Verbose and Quiet Logging Flags",{"path":1862,"title":1863},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps","Structured Logging for CLI Apps",{"path":1865,"title":1866},"\u002Fadvanced-input-parsing-user-experience\u002Fstructured-logging-for-cli-apps\u002Fstructured-json-logging-in-python-clis","Structured JSON Logging in Python CLIs",{"path":1868,"title":1869},"\u002F","Python CLI Toolcraft",{"path":1871,"title":1749},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading",{"path":1803,"title":5},{"path":1874,"title":1875},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcli-startup-performance-and-lazy-loading\u002Fprofiling-python-cli-startup-time","Profiling Python CLI Startup Time",{"path":1877,"title":1878},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fargparse-subparsers-for-subcommands","argparse Subparsers for Subcommands",{"path":1880,"title":1881},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse","Command-Line Parsing with argparse",{"path":1883,"title":1884},"\u002Fmodern-python-cli-frameworks-architecture\u002Fcommand-line-parsing-with-argparse\u002Fmigrating-from-argparse-to-typer","Migrating from argparse to Typer",{"path":1886,"title":1887},"\u002Fmodern-python-cli-frameworks-architecture","Python CLI Frameworks and Architecture",{"path":1889,"title":1890},"\u002Fmodern-python-cli-frameworks-architecture\u002Fplugin-architectures-for-extensible-clis","Plugin Architectures for Extensible CLIs",{"path":1892,"title":1767},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fbest-practices-for-python-cli-entry-points",{"path":1894,"title":1895},"\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":1897,"title":1898},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis","Structuring Multi-Command Python CLIs",{"path":1900,"title":1901},"\u002Fmodern-python-cli-frameworks-architecture\u002Fstructuring-multi-command-python-clis\u002Fsharing-state-with-click-context-objects","Sharing State with Click Context Objects",{"path":1903,"title":1904},"\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":1906,"title":1907},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each","Typer vs Click: When to Use Each",{"path":1909,"title":1910},"\u002Fmodern-python-cli-frameworks-architecture\u002Ftyper-vs-click-when-to-use-each\u002Ftyper-callback-functions-explained","Typer callback functions explained",{"path":1912,"title":1913},"\u002Fproject-setup-dependency-management\u002Fcli-project-scaffolding-with-cookiecutter","CLI Project Scaffolding with Cookiecutter",{"path":1915,"title":1916},"\u002Fproject-setup-dependency-management","Project Setup & Dependency Management",{"path":1918,"title":1919},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs\u002Fautomating-changelogs-with-conventional-commits","Automating Changelogs with Conventional Commits",{"path":1921,"title":1922},"\u002Fproject-setup-dependency-management\u002Fmanaging-cli-versioning-changelogs","Managing CLI Versioning & Changelogs",{"path":1924,"title":1925},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fbuilding-wheels-and-sdists-for-python-clis","Building Wheels and sdists for Python CLIs",{"path":1927,"title":1928},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution","Packaging Python CLIs for Distribution",{"path":1930,"title":1931},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Finstalling-and-distributing-clis-with-pipx","Installing and Distributing CLIs with pipx",{"path":1933,"title":1934},"\u002Fproject-setup-dependency-management\u002Fpackaging-python-clis-for-distribution\u002Fpublishing-a-python-cli-to-pypi","Publishing a Python CLI to PyPI",{"path":1936,"title":1937},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development","Poetry Workflows for CLI Development",{"path":1939,"title":1940},"\u002Fproject-setup-dependency-management\u002Fpoetry-workflows-for-cli-development\u002Fpoetry-entry-points-and-scripts-for-clis","Poetry Entry Points and Scripts for CLIs",{"path":1942,"title":1943},"\u002Fproject-setup-dependency-management\u002Fpre-commit-hooks-for-cli-projects","Pre-commit Hooks for CLI Projects",{"path":1945,"title":1946},"\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":1948,"title":1949},"\u002Fproject-setup-dependency-management\u002Fuv-for-python-cli-dependency-management","uv for Python CLI Dependency Management",{"path":1951,"title":1952},"\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":1954,"title":1955},"\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":1957,"title":1958},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices","Python CLI Env Isolation Best Practices",{"path":1960,"title":1961},"\u002Fproject-setup-dependency-management\u002Fvirtual-environments-isolation-best-practices\u002Fmanaging-virtual-environments-for-cross-platform-clis","Managing Python CLI Virtual Environments",1783281867197]