Registry / devops / click
library8.5.0pypypi✓ verified 26d ago

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.

pip install click
INSTALL
IMPORT
SIG · CLICK
C
click
devopspythonv8.5.0
Install
1.7s avg
Import
61ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v8.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.064s · 18.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.058s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

click (namespace)
import click
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.
CliRunner
from click.testing import CliRunner
Testing runner lives in click.testing, not in the top-level namespace.
Command
from click import Command
from click import BaseCommand
BaseCommand is deprecated since 8.2.0; Command is now the base class for all commands.
Group
from click import Group
from click import MultiCommand
MultiCommand is deprecated since 8.2.0; Group is now the base class for all group commands.
get_terminal_size
import shutil; shutil.get_terminal_size()
from click import get_terminal_size
click.get_terminal_size was removed in 8.1.0. Use shutil.get_terminal_size from the stdlib.
shell_complete (parameter)
@click.command() @click.option('--name', shell_complete=my_complete_fn)
@click.command(autocompletion=my_complete_fn)
The 'autocompletion' parameter on Command/Option was renamed to 'shell_complete' in 8.0 and the old name was fully removed.

A minimal Click CLI with a group, a subcommand, options, and a test via CliRunner.

import click from click.testing import CliRunner @click.group() @click.option('--verbose', is_flag=True, default=False, help='Enable verbose output.') @click.pass_context def cli(ctx, verbose): """My CLI tool.""" ctx.ensure_object(dict) ctx.obj['verbose'] = verbose @cli.command() @click.option('--count', default=1, show_default=True, help='Number of greetings.') @click.option('--name', prompt='Your name', help='Person to greet.') @click.pass_context def greet(ctx, count, name): """Greet NAME a number of times.""" for _ in range(count): click.echo(f"Hello, {name}!") if ctx.obj.get('verbose'): click.echo(f"(verbose mode, greeted {count} time(s))") if __name__ == '__main__': # Direct invocation cli() # --- Testing --- def test_greet(): runner = CliRunner() result = runner.invoke(cli, ['greet', '--name', 'World', '--count', '2']) assert result.exit_code == 0, result.output assert result.output.count('Hello, World!') == 2 test_greet() click.echo('Quickstart test passed.')
click --version
Debug
Known issues
breakingPython 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.
fix
Upgrade Python to >=3.10 (required by current 8.3.x) or pin 'click<8.2' if stuck on older Python.
affects: <8.2.0
deprecatedBaseCommand and MultiCommand are deprecated since 8.2.0. Subclassing or isinstance-checking either will emit DeprecationWarnings and will break in a future major release.
fix
Replace BaseCommand subclasses with Command and MultiCommand subclasses/isinstance checks with Group.
affects: >=8.2.0
deprecatedclick.__version__ is deprecated since 8.2.0. Accessing it emits a DeprecationWarning.
fix
Use 'importlib.metadata.version("click")' for runtime version detection.
affects: >=8.2.0
breakingclick.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.
fix
Use 'shutil.get_terminal_size()' from the Python standard library instead.
affects: >=8.1.0
gotchaCliRunner.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.
fix
Pass catch_exceptions=False to CliRunner.invoke() during development, or always assert result.exception is None and result.exit_code == 0 in tests.
affects: all
gotchaCliRunner 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.
fix
Run CliRunner tests sequentially. Use runner.isolated_filesystem() for file-based tests to avoid cross-test contamination.
affects: all
gotchastandalone_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.
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().
affects: all
gotchaClick 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.
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.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'click'
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.
fix
Install the 'click' library using pip: `pip install click`. If using a virtual environment, ensure it is activated before installation.
Error: Missing command.
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`.
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.
TypeError: 'Group' object is not callable
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.
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)`.
Error: Missing argument '<name>'
A required argument for a Click command or option was not provided on the command line.
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`.
Upgrade
Version history
8.5.0latest on PyPI · released Aug 26, 2026
Audit
Dependencies
coloramaoptionalRequired on Windows for ANSI color support in click.echo/secho; auto-installed on Windows
Agent activity
43 hits · last 30 days
node
36
Resources