click API reference
95 public APIs from click (pallets/click) — 19 classes, 19 functions, 57 methods. Signatures extracted by static analysis of the actual source.
Repository: pallets/click
| Kind | Count |
|---|---|
| Classes | 19 |
| Functions | 19 |
| Methods | 57 |
API list
func
src.click._compat.get_best_encoding(stream:t.IO[t.Any]) -> strReturns the default stream encoding if not found.
func
src.click._compat.is_ascii_encoding(encoding:str) -> boolChecks if a given encoding is ascii.
func
src.click._termui_impl.get_pager_file(color:bool | None=None) -> t.Generator[t.TextIO, None, None]Context manager.
class
src.click._utils.SentinelEnum used to define sentinel values.
class
src.click.core.ArgumentArguments are positional parameters to a command.
method
src.click.core.Command.format_arguments(ctx:Context, formatter:HelpFormatter) -> NoneWrites the arguments that have a help record into the formatter.
method
src.click.core.Command.format_epilog(ctx:Context, formatter:HelpFormatter) -> NoneWrites the epilog into the formatter if it exists.
method
src.click.core.Command.format_help(ctx:Context, formatter:HelpFormatter) -> NoneWrites the help into the formatter if it exists.
method
src.click.core.Command.format_help_text(ctx:Context, formatter:HelpFormatter) -> NoneWrites the help text to the formatter if it exists.
method
src.click.core.Command.format_options(ctx:Context, formatter:HelpFormatter) -> NoneWrites all the options into the formatter if they exist.
method
src.click.core.Command.format_usage(ctx:Context, formatter:HelpFormatter) -> NoneWrites the usage line into the formatter.
method
src.click.core.Command.get_help(ctx:Context) -> strFormats the help into a string and returns it.
method
src.click.core.Command.get_help_option(ctx:Context) -> Option | NoneReturns the help option object.
method
src.click.core.Command.get_help_option_names(ctx:Context) -> list[str]Returns the names for the help option.
method
src.click.core.Command.get_usage(ctx:Context) -> strFormats the usage line into a string and returns it.
method
src.click.core.Command.make_parser(ctx:Context) -> _OptionParserCreates the underlying option parser for this command.
method
src.click.core.Command.shell_complete(ctx:Context, incomplete:str) -> list[CompletionItem]Return a list of completions for the incomplete value.
class
src.click.core.CommandCollectionA :class:`Group` that looks up subcommands on other groups.
method
src.click.core.CommandCollection.add_source(group:Group) -> NoneAdd a group as a source of commands.
method
src.click.core.Context.abort() -> t.NoReturnAborts the script.
method
src.click.core.Context.call_on_close(f:t.Callable[..., t.Any]) -> t.Callable[..., t.Any]Register a function to be called when the context tears down.
method
src.click.core.Context.command_path() -> strThe computed command path.
method
src.click.core.Context.exit(code:int=0) -> t.NoReturnExits the application with a given exit code.
method
src.click.core.Context.fail(message:str) -> t.NoReturnAborts the execution of the program with a specific error message.
method
src.click.core.Context.find_object(object_type:type[V]) -> V | NoneFinds the closest object of a given type.
method
src.click.core.Context.find_root() -> ContextFinds the outermost context.
method
src.click.core.Context.get_parameter_source(name:str) -> ParameterSource | NoneGet the source of a parameter.
method
src.click.core.Context.set_parameter_source(name:str, source:ParameterSource) -> NoneSet the source of a parameter.
method
src.click.core.Context.with_resource(context_manager:AbstractContextManager[V]) -> VRegister a resource as if it were used in a ``with`` statement.
class
src.click.core.GroupA group is a command that nests other commands (or more groups).
method
src.click.core.Group.add_command(cmd:Command, name:str | None=None) -> NoneRegisters another :class:`Command` with this group.
method
src.click.core.Group.list_commands(ctx:Context) -> list[str]Returns a list of subcommand names in the order they should appear.
method
src.click.core.Group.result_callback(replace:bool=False) -> t.Callable[[F], F]Adds a result callback to the command.
method
src.click.core.Group.shell_complete(ctx:Context, incomplete:str) -> list[CompletionItem]Return a list of completions for the incomplete value.
method
src.click.core.Option.get_default(ctx:Context, call:bool=True) -> t.Any | t.Callable[[], t.Any] | NoneReturn the default value for this option.
method
src.click.core.Option.is_bool_flag() -> bool``True`` when this option is a flag with a boolean type.
method
src.click.core.Option.to_info_dict() -> dict[str, t.Any]..
method
src.click.core.Parameter.consume_value(ctx:Context, opts:cabc.Mapping[str, t.Any]) -> tuple[t.Any, ParameterSource]Returns the parameter value produced by the parser.
method
src.click.core.Parameter.human_readable_name() -> strReturns the human readable name of this parameter.
method
src.click.core.Parameter.process_value(ctx:Context, value:t.Any) -> t.AnyProcess the value of this parameter: 1.
method
src.click.core.Parameter.shell_complete(ctx:Context, incomplete:str) -> list[CompletionItem]Return a list of completions for the incomplete value.
method
src.click.core.Parameter.value_from_envvar(ctx:Context) -> str | cabc.Sequence[str] | NoneProcess the raw environment variable string for this parameter.
func
src.click.decorators.argument(*cls:type[Argument] | None=None, *param_decls:str, **attrs:t.Any) -> t.Callable[[FC], FC]Attaches an argument to the command.
func
src.click.decorators.option(*cls:type[Option] | None=None, *param_decls:str, **attrs:t.Any) -> t.Callable[[FC], FC]Attaches an option to the command.
func
src.click.decorators.show_help(ctx:Context, param:Parameter, value:bool) -> NoneCallback that print the help page on ``<stdout>`` and exits.
class
src.click.exceptions.AbortAn internal signalling exception that signals Click to abort.
class
src.click.exceptions.ClickExceptionAn exception that Click can handle and show to the user.
class
src.click.exceptions.FileErrorRaised if a file cannot be opened.
class
src.click.exceptions.UsageErrorAn internal exception that signals a usage error.
class
src.click.formatting.HelpFormatterThis class helps with formatting text-based help pages.
method
src.click.formatting.HelpFormatter.dedent() -> NoneDecreases the indentation.
method
src.click.formatting.HelpFormatter.getvalue() -> strReturns the buffer contents.
method
src.click.formatting.HelpFormatter.indent() -> NoneIncreases the indentation.
method
src.click.formatting.HelpFormatter.indentation() -> cabc.Generator[None]A context manager that increases the indentation.
method
src.click.formatting.HelpFormatter.write(string:str) -> NoneWrites a unicode string into the internal buffer.
method
src.click.formatting.HelpFormatter.write_dl(rows:cabc.Iterable[tuple[str, str]], col_max:int=30, col_spacing:int=2) -> NoneWrites a definition list into the buffer.
method
src.click.formatting.HelpFormatter.write_heading(heading:str) -> NoneWrites a heading into the buffer.
method
src.click.formatting.HelpFormatter.write_paragraph() -> NoneWrites a paragraph into the buffer.
method
src.click.formatting.HelpFormatter.write_text(text:str) -> NoneWrites re-indented text into the buffer.
method
src.click.formatting.HelpFormatter.write_usage(prog:str, args:str='', prefix:str | None=None) -> NoneWrites a usage line into the buffer.
func
src.click.formatting.wrap_text(text:str, width:int=78, initial_indent:str='', subsequent_indent:str='', preserve_paragraphs:bool=False) -> strA helper function that intelligently wraps text.
func
src.click.globals.pop_context() -> NoneRemoves the top level from the stack.
func
src.click.globals.push_context(ctx:Context) -> NonePushes a new context to the current stack.
func
src.click.globals.resolve_color_default(color:bool | None=None) -> bool | NoneInternal helper to get the default value of the color flag.
class
src.click.shell_completion.BashCompleteShell completion for Bash.
class
src.click.shell_completion.CompletionItemRepresents a completion value and metadata about the value.
class
src.click.shell_completion.FishCompleteShell completion for Fish.
method
src.click.shell_completion.FishComplete.format_completion(item:CompletionItem[str]) -> str..
class
src.click.shell_completion.ShellCompleteBase class for providing shell completion support.
method
src.click.shell_completion.ShellComplete.complete() -> strProduce the completion data to send back to the shell.
method
src.click.shell_completion.ShellComplete.source_vars() -> _SourceVarsDictVars for formatting :attr:`source_template`.
class
src.click.shell_completion.ZshCompleteShell completion for Zsh.
func
src.click.termui.clear() -> NoneClears the terminal screen.
func
src.click.termui.confirm(text:str, default:bool | None=False, abort:bool=False, prompt_suffix:str=': ', show_default:bool=True, err:bool=False) -> boolPrompts for confirmation (yes/no question).
func
src.click.termui.get_pager_file(color:bool | None=None) -> t.ContextManager[t.TextIO]Context manager.
func
src.click.termui.getchar(echo:bool=False) -> strFetches a single character from the terminal and returns it.
func
src.click.termui.unstyle(text:str) -> strRemoves ANSI styling information from a string.
class
src.click.testing.ResultHolds the captured result of an invoked CLI script.
method
src.click.testing.Result.stderr() -> strThe standard error as unicode string.
method
src.click.testing.Result.stdout() -> strThe standard output as unicode string.
class
src.click.testing.StreamMixerMixes `<stdout>` and `<stderr>` streams.
method
src.click.types.Choice.get_invalid_choice_message(value:t.Any, ctx:Context | None) -> strGet the error message when the given choice is invalid.
method
src.click.types.Choice.get_missing_message(param:Parameter, ctx:Context | None) -> strMessage shown when no choice is passed.
method
src.click.types.Choice.normalize_choice(choice:object, ctx:Context | None) -> strNormalize a choice value, used to map a passed string to a choice.
method
src.click.types.Choice.shell_complete(ctx:Context, param:Parameter, incomplete:str) -> list[CompletionItem]Complete choices that start with the incomplete value.
class
src.click.types.DateTimeThe DateTime type converts date strings into `datetime` objects.
class
src.click.types.FileDeclares a parameter to be a file for reading or writing.
class
src.click.types.ParamTypeRepresents the type of a parameter.
method
src.click.types.ParamType.convert(value:_InputT_contra, param:Parameter | None, ctx:Context | None) -> _ValueT_coConvert the value to the correct type.
method
src.click.types.ParamType.fail(message:str, param:Parameter | None=None, ctx:Context | None=None) -> t.NoReturnHelper method to fail with an invalid value message.
method
src.click.types.ParamType.get_metavar(param:Parameter, ctx:Context) -> str | NoneReturns the metavar default for this param if it provides one.
func
src.click.utils.echo(message:object=None, file:t.IO[t.Any] | None=None, nl:bool=True, err:bool=False, color:bool | None=None) -> NonePrint a message and newline to stdout or a file.
func
src.click.utils.format_filename(filename:str | bytes | os.PathLike[str] | os.PathLike[bytes], shorten:bool=False) -> strFormat a filename as a string for display.
func
src.click.utils.get_app_dir(app_name:str, roaming:bool=True, force_posix:bool=False) -> strReturns the config folder for the application.
func
src.click.utils.make_str(value:t.Any) -> strConverts a value into a valid string.
About this data
These signatures were extracted from the public source of pallets/click
using Python's ast module. Argument names, default values,
type annotations and return types are taken verbatim from the code.
Implementation bodies are never stored. See
how it works for details.