or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

commands-groups.mdcontext-management.mdexception-handling.mdformatting.mdindex.mdparameter-types.mdparameters.mdterminal-ui.mdtesting-support.md
tile.json

tessl/pypi-types-click

Typing stubs for click - a command line interface creation kit for Python

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/types-click@7.1.x

To install, run

npx @tessl/cli install tessl/pypi-types-click@7.1.0

index.mddocs/

types-click

Typing 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.

Package Information

  • Package Name: types-click
  • Language: Python (Type Stubs)
  • Installation: pip install types-click
  • Described Package: click 7.1.x
  • Purpose: Provides comprehensive typing stubs for the click library

Core Imports

import click

Common decorator imports:

from click import command, group, option, argument, pass_context, pass_obj

Core classes and utilities:

from click import Context, Command, Group, echo, style, prompt, confirm

Parameter types:

from click import Choice, Path, IntRange, FloatRange, File, DateTime
# Or use type constants
from click import BOOL, INT, FLOAT, STRING, UUID

Exception handling:

from click import ClickException, UsageError, BadParameter, Abort

Testing support:

from click.testing import CliRunner

Advanced 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_context

Basic Usage

import 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()

Architecture

Click follows a decorator-based design pattern built around several key concepts:

  • Commands: Individual CLI commands defined with @command decorator
  • Groups: Collections of commands using @group decorator
  • Parameters: Options (@option) and arguments (@argument) that define command inputs
  • Context: Execution context passed between commands containing state and configuration
  • Types: Rich parameter validation and conversion system
  • Testing: Built-in CLI testing framework for automated testing

This architecture enables building complex CLI applications with hierarchical commands, rich parameter validation, interactive prompts, and comprehensive help generation.

Capabilities

Command and Group Creation

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]: ...

Commands and Groups

Parameter Definition

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: ...

Parameters

Parameter Types

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: ...

Parameter Types

Context Management

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: ...

Context Management

Terminal User Interface

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: ...

Terminal UI

Exception Handling

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: ...

Exception Handling

Testing Support

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: Any

Testing Support

Text Formatting

Text 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, ...]: ...

Text Formatting

Types

Core Classes

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: ...

Module Constants

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__}")
"""