{"id":251,"library":"click","title":"Click","description":"Click ('Command Line Interface Creation Kit') is a Python package for creating composable, beautiful command-line interfaces with minimal boilerplate. It uses a decorator-based API to turn functions into CLI commands with automatic help page generation, argument/option parsing, type coercion, and shell completion. Current version is 8.3.1 (latest stable); the project follows a feature-release / fix-release cadence under the Pallets organization, with feature releases (e.g. 8.2.0, 8.3.0) potentially introducing deprecations or breaking changes and patch releases (e.g. 8.3.1) being safe upgrades.","status":"active","version":"8.3.1","language":"python","source_language":"en","source_url":"https://github.com/pallets/click/","tags":["cli","command-line","argparse-alternative","decorators","pallets","terminal","shell-completion"],"install":[{"cmd":"pip install click","lang":"bash","label":"pip"},{"cmd":"apt install click"}],"dependencies":[{"reason":"Required on Windows for ANSI color support in click.echo/secho; auto-installed on Windows","package":"colorama","optional":true}],"imports":[{"note":"All public symbols (command, group, option, argument, echo, pass_context, etc.) are accessed via the top-level 'click' namespace. Do not import from sub-modules like click.core or click.termui directly — these are private and have changed between versions.","symbol":"click (namespace)","correct":"import click"},{"note":"Testing runner lives in click.testing, not in the top-level namespace.","symbol":"CliRunner","correct":"from click.testing import CliRunner"},{"note":"BaseCommand is deprecated since 8.2.0; Command is now the base class for all commands.","wrong":"from click import BaseCommand","symbol":"Command","correct":"from click import Command"},{"note":"MultiCommand is deprecated since 8.2.0; Group is now the base class for all group commands.","wrong":"from click import MultiCommand","symbol":"Group","correct":"from click import Group"},{"note":"click.get_terminal_size was removed in 8.1.0. Use shutil.get_terminal_size from the stdlib.","wrong":"from click import get_terminal_size","symbol":"get_terminal_size","correct":"import shutil; shutil.get_terminal_size()"},{"note":"The 'autocompletion' parameter on Command/Option was renamed to 'shell_complete' in 8.0 and the old name was fully removed.","wrong":"@click.command(autocompletion=my_complete_fn)","symbol":"shell_complete (parameter)","correct":"@click.command()\n@click.option('--name', shell_complete=my_complete_fn)"}],"quickstart":{"code":"import click\nfrom click.testing import CliRunner\n\n@click.group()\n@click.option('--verbose', is_flag=True, default=False, help='Enable verbose output.')\n@click.pass_context\ndef cli(ctx, verbose):\n    \"\"\"My CLI tool.\"\"\"\n    ctx.ensure_object(dict)\n    ctx.obj['verbose'] = verbose\n\n@cli.command()\n@click.option('--count', default=1, show_default=True, help='Number of greetings.')\n@click.option('--name', prompt='Your name', help='Person to greet.')\n@click.pass_context\ndef greet(ctx, count, name):\n    \"\"\"Greet NAME a number of times.\"\"\"\n    for _ in range(count):\n        click.echo(f\"Hello, {name}!\")\n    if ctx.obj.get('verbose'):\n        click.echo(f\"(verbose mode, greeted {count} time(s))\")\n\nif __name__ == '__main__':\n    # Direct invocation\n    cli()\n\n# --- Testing ---\ndef test_greet():\n    runner = CliRunner()\n    result = runner.invoke(cli, ['greet', '--name', 'World', '--count', '2'])\n    assert result.exit_code == 0, result.output\n    assert result.output.count('Hello, World!') == 2\n\ntest_greet()\nclick.echo('Quickstart test passed.')\n","lang":"python","description":"A minimal Click CLI with a group, a subcommand, options, and a test via CliRunner."},"warnings":[{"fix":"Upgrade Python to >=3.10 (required by current 8.3.x) or pin 'click<8.2' if stuck on older Python.","message":"Python 3.7, 3.8, and 3.9 support was dropped in Click 8.2.0. Projects running on those versions must pin to click<8.2.","severity":"breaking","affected_versions":"<8.2.0"},{"fix":"Replace BaseCommand subclasses with Command and MultiCommand subclasses/isinstance checks with Group.","message":"BaseCommand and MultiCommand are deprecated since 8.2.0. Subclassing or isinstance-checking either will emit DeprecationWarnings and will break in a future major release.","severity":"deprecated","affected_versions":">=8.2.0"},{"fix":"Use 'importlib.metadata.version(\"click\")' for runtime version detection.","message":"click.__version__ is deprecated since 8.2.0. Accessing it emits a DeprecationWarning.","severity":"deprecated","affected_versions":">=8.2.0"},{"fix":"Use 'shutil.get_terminal_size()' from the Python standard library instead.","message":"click.get_terminal_size was removed in 8.1.0. Any code importing it from click will raise ImportError. Third-party packages that imported it (e.g. older spaCy) broke on upgrade.","severity":"breaking","affected_versions":">=8.1.0"},{"fix":"Pass catch_exceptions=False to CliRunner.invoke() during development, or always assert result.exception is None and result.exit_code == 0 in tests.","message":"CliRunner.invoke() catches ALL exceptions by default (catch_exceptions=True), silently swallowing bugs. Tests may pass with exit_code != 0 if result.exception is not inspected.","severity":"gotcha","affected_versions":"all"},{"fix":"Run CliRunner tests sequentially. Use runner.isolated_filesystem() for file-based tests to avoid cross-test contamination.","message":"CliRunner is not thread-safe and mutates global interpreter state (sys.stdout, sys.stdin). Do not use it in threaded or async test suites without isolation.","severity":"gotcha","affected_versions":"all"},{"fix":"Invoke programmatically with standalone_mode=False: result = my_command.main(args=[], standalone_mode=False) to get the return value instead of a sys.exit().","message":"standalone_mode=True (the default) means Click calls sys.exit() after command execution, converting return values to exit codes. Calling a click command directly in application code without standalone_mode=False will terminate the process.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure the script is invoked with the intended command and arguments. If the application should perform an action without an explicit command, configure a default command or handle argument parsing explicitly.","message":"Click applications display the usage and help message when invoked without a specific command or with invalid arguments. This is expected behavior but can be unexpected if the intention was to execute a command, and no default command is configured.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'8.2.0':73 '8.3.0':74 '8.3.1':51,85 'altern':95 'api':29 'argpars':94 'argparse-altern':93 'argument/option':41 'automat':37 'base':28 'beauti':15 'boilerpl':22 'break':79 'cadenc':64 'chang':80 'cli':34,89 'click':1,2 'coercion':44 'command':3,17,35,91 'command-lin':16,90 'complet':47,101 'compos':14 'creat':13 'creation':6 'current':48 'decor':27,96 'decorator-bas':26 'deprec':77 'e.g':72,84 'featur':59,70 'feature-releas':58 'fix':62 'fix-releas':61 'follow':56 'function':32 'generat':40 'help':38 'interfac':5,19 'introduc':76 'kit':7 'latest':52 'line':4,18,92 'minim':21 'organ':68 'packag':11 'page':39 'pallet':67,97 'pars':42 'patch':82 'potenti':75 'project':55 'python':10 'releas':60,63,71,83 'safe':87 'shell':46,100 'shell-complet':99 'stabl':53 'termin':98 'turn':31 'type':43 'upgrad':88 'use':24 'version':49","created_at":"2026-03-28T03:56:08.689178+00:00","updated_at":"2026-04-16T02:25:21.902976+00:00","problems":[{"fix":"Install the 'click' library using pip: `pip install click`. If using a virtual environment, ensure it is activated before installation.","cause":"The 'click' library is not installed in the Python environment being used, or the Python interpreter running the script is not the one where 'click' is installed.","error":"ModuleNotFoundError: No module named 'click'"},{"fix":"Provide the expected subcommand as an argument (e.g., `your_script.py subcommand`), or add `invoke_without_command=True` to your `@click.group()` decorator if the group should run its callback even without a subcommand. Consult the help page with `your_script.py --help` to see available commands.","cause":"A required subcommand was not provided when executing a Click group, or the group was invoked without any arguments and `invoke_without_command` is not set to `True`.","error":"Error: Missing command."},{"fix":"Ensure that your top-level command or group is executed via `if __name__ == '__main__': your_cli_function()`. If you need to invoke a subcommand from within another command's callback, use `ctx.invoke(subcommand_callback, ...)` or `group_object.invoke(ctx)`.","cause":"A `click.Group` or `click.Command` object is being directly called like a regular Python function, instead of allowing Click's internal dispatch mechanism (via `main()` or `invoke()`) to handle its execution.","error":"TypeError: 'Group' object is not callable"},{"fix":"Supply the missing argument when running the command (e.g., `your_script.py <value_for_name>`). Review the command's expected arguments and options using `your_script.py --help`.","cause":"A required argument for a Click command or option was not provided on the command line.","error":"Error: Missing argument '<name>'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"8.5.0","cli_name":"click","cli_version":"sh: 1: click: not found","type":"library","homepage":null,"github":"https://github.com/pallets/click","docs":"https://click.palletsprojects.com/","changelog":"https://click.palletsprojects.com/page/changes/","pypi":"https://pypi.org/project/click/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-27","last_verified":"2026-08-27","next_check":"2026-07-27","install_tag":"verified"}}