Click — The Cleanest Way to Build Python CLI Tools
How a decorator-based CLI framework works internally
Internals
@click.command() wraps the function in a Command object. @click.option() adds Option objects to the function's __click_params__ list.
On hello() call: Command.main() → parse sys.argv → map to function args → type conversion + validation → call original function.
Groups for Subcommands
Click internally routes subcommands via MultiCommand.invoke().
Relationship with Typer
Typer (by FastAPI's creator) layers type hints on top of Click. Same philosophy as FastAPI — define args via function signature type hints instead of decorators.
Key Points
@click.command() wraps function in Command object
@click.option() adds Option objects to __click_params__
On execution: parse sys.argv → type conversion → call function
@click.group() for subcommand structure (like git init, deploy)