Typing stubs for click - a command line interface creation kit for Python
npx @tessl/cli install tessl/pypi-types-click@7.1.0Typing stubs for click - a command line interface creation kit for Python. These type stubs enable static type checking with tools like mypy, PyCharm, and pytype when using the click library, providing better IDE support and helping catch type-related errors during development.
pip install types-clickimport clickCommon decorator imports:
from click import command, group, option, argument, pass_context, pass_objCore classes and utilities:
from click import Context, Command, Group, echo, style, prompt, confirmParameter types:
from click import Choice, Path, IntRange, FloatRange, File, DateTime
# Or use type constants
from click import BOOL, INT, FLOAT, STRING, UUIDException handling:
from click import ClickException, UsageError, BadParameter, AbortTesting support:
from click.testing import CliRunnerAdvanced imports:
# Special decorators
from click import version_option, help_option, confirmation_option, password_option
# Terminal UI functions
from click import progressbar, clear, pause, edit, launch, get_terminal_size
# File and stream utilities
from click import get_binary_stream, get_text_stream, open_file, get_app_dir
# Formatting utilities
from click.formatting import HelpFormatter, wrap_text
# Global context access
from click import get_current_contextimport click
@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name', help='The person to greet.')
def hello(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
for _ in range(count):
click.echo(f'Hello, {name}!')
if __name__ == '__main__':
hello()Group example:
import click
@click.group()
def cli():
"""A CLI tool with multiple commands."""
pass
@cli.command()
@click.argument('name')
def greet(name):
"""Greet someone."""
click.echo(f'Hello {name}!')
@cli.command()
@click.option('--format', type=click.Choice(['json', 'plain']))
def status(format):
"""Show status."""
if format == 'json':
click.echo('{"status": "ok"}')
else:
click.echo('Status: OK')
if __name__ == '__main__':
cli()Click follows a decorator-based design pattern built around several key concepts:
@command decorator@group decorator@option) and arguments (@argument) that define command inputsThis architecture enables building complex CLI applications with hierarchical commands, rich parameter validation, interactive prompts, and comprehensive help generation.
Core decorators for defining CLI commands and organizing them into groups. Commands are the fundamental building blocks of CLI applications, while groups enable hierarchical command structures.
def command(name: str | None = ..., **kwargs) -> Callable[[Callable], Command]: ...
def group(name: str | None = ..., **kwargs) -> Callable[[Callable], Group]: ...Decorators for defining command-line options and arguments with rich type validation, default values, prompts, and help text. These provide the interface between users and command functionality.
def option(*param_decls: str, **kwargs) -> Callable: ...
def argument(*param_decls: str, **kwargs) -> Callable: ...Rich type system for validating and converting command-line inputs including built-in types for common patterns like file paths, choices, numeric ranges, and custom type creation.
class Choice(ParamType):
def __init__(self, choices: Iterable[str], case_sensitive: bool = ...) -> None: ...
class Path(ParamType):
def __init__(self, exists: bool = ..., file_okay: bool = ..., dir_okay: bool = ..., **kwargs) -> None: ...
class IntRange(IntParamType):
def __init__(self, min: int | None = ..., max: int | None = ..., clamp: bool = ...) -> None: ...Context objects that maintain state and configuration throughout command execution, enabling communication between commands and providing access to execution metadata.
class Context:
def __init__(self, command: Command, **kwargs) -> None: ...
def fail(self, message: str) -> NoReturn: ...
def abort(self) -> NoReturn: ...
def invoke(self, callback: Command | Callable, *args, **kwargs) -> Any: ...
def pass_context(f: Callable) -> Callable: ...
def get_current_context(silent: bool = ...) -> Context: ...Interactive CLI elements including prompts, confirmation dialogs, progress bars, styled output, and terminal utilities for building rich command-line experiences.
def prompt(text: str, **kwargs) -> Any: ...
def confirm(text: str, default: bool = ..., **kwargs) -> bool: ...
def progressbar(iterable=..., **kwargs): ...
def echo(message=..., **kwargs) -> None: ...
def style(text, fg=..., bg=..., bold=..., **kwargs) -> str: ...Comprehensive exception hierarchy for handling CLI errors with proper error messages, exit codes, and user feedback. Includes parameter validation errors and usage errors.
class ClickException(Exception):
def __init__(self, message: str) -> None: ...
class UsageError(ClickException):
def __init__(self, message: str, ctx: Context | None = ...) -> None: ...
class BadParameter(UsageError):
def __init__(self, message: str, ctx: Context | None = ..., param: Parameter | None = ...) -> None: ...Built-in testing framework with CLI runner, result objects, and utilities for testing CLI applications in isolation with controlled input/output.
class CliRunner:
def __init__(self, charset: str | None = ..., **kwargs) -> None: ...
def invoke(self, cli: BaseCommand, args=..., **kwargs) -> Result: ...
class Result:
exit_code: int
output: str
exception: AnyText formatting utilities for creating well-structured help output, text wrapping, and table formatting. These functions are primarily used internally by Click but can be useful for custom help formatting.
class HelpFormatter:
def __init__(self, indent_increment: int = ..., width: int | None = ..., max_width: int | None = ...) -> None: ...
def write_dl(self, rows: Iterable[Iterable[str]], col_max: int = ..., col_spacing: int = ...) -> None: ...
def section(self, name: str) -> ContextManager[None]: ...
def wrap_text(text: str, width: int = ..., **kwargs) -> str: ...
def measure_table(rows: Iterable[Iterable[str]]) -> tuple[int, ...]: ...class Command(BaseCommand):
def __init__(self, name: str, callback: Callable | None = ..., **kwargs) -> None: ...
class Group(MultiCommand):
def __init__(self, name: str | None = ..., commands: dict[str, Command] | None = ..., **kwargs) -> None: ...
def add_command(self, cmd: Command, name: str | None = ...) -> None: ...
class Parameter:
def __init__(self, param_decls: Iterable[str] | None = ..., **kwargs) -> None: ...
class Option(Parameter):
def __init__(self, param_decls: Iterable[str] | None = ..., **kwargs) -> None: ...
class Argument(Parameter):
def __init__(self, param_decls: Iterable[str] | None = ..., **kwargs) -> None: ...Click module-level constants and attributes for configuration and introspection.
disable_unicode_literals_warning: bool
"""
Controls if click should emit warnings about unicode literals usage.
Set to True to suppress warnings in environments with unicode literal issues.
Usage:
import click
click.disable_unicode_literals_warning = True
"""
__version__: str
"""
Current version of the click library.
Usage:
import click
print(f"Click version: {click.__version__}")
"""