{"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"}],"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,"last_verified":"2026-05-12T12:21:30.772Z","next_check":"2026-06-25T00:00:00.000Z","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,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":2.5,"disk_size":"18.5M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":2.5,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.8,"disk_size":"20.5M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":2.8,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.6,"disk_size":"12.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.6,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":2.8,"disk_size":"12.0M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":2.6,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":2.5,"disk_size":"18.0M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":2.5,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":2},{"runtime":"python:3.10-slim","exit_code":2},{"runtime":"python:3.11-alpine","exit_code":2},{"runtime":"python:3.11-slim","exit_code":2},{"runtime":"python:3.12-alpine","exit_code":2},{"runtime":"python:3.12-slim","exit_code":2},{"runtime":"python:3.13-alpine","exit_code":2},{"runtime":"python:3.13-slim","exit_code":2},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}