typer.models

  1import inspect
  2import io
  3from typing import (
  4    TYPE_CHECKING,
  5    Any,
  6    Callable,
  7    Dict,
  8    List,
  9    Optional,
 10    Sequence,
 11    Type,
 12    TypeVar,
 13    Union,
 14)
 15
 16import click
 17import click.shell_completion
 18
 19if TYPE_CHECKING:  # pragma: no cover
 20    from .core import TyperCommand, TyperGroup
 21    from .main import Typer
 22
 23
 24NoneType = type(None)
 25
 26AnyType = Type[Any]
 27
 28Required = ...
 29
 30
 31class Context(click.Context):
 32    pass
 33
 34
 35class FileText(io.TextIOWrapper):
 36    pass
 37
 38
 39class FileTextWrite(FileText):
 40    pass
 41
 42
 43class FileBinaryRead(io.BufferedReader):
 44    pass
 45
 46
 47class FileBinaryWrite(io.BufferedWriter):
 48    pass
 49
 50
 51class CallbackParam(click.Parameter):
 52    pass
 53
 54
 55class DefaultPlaceholder:
 56    """
 57    You shouldn't use this class directly.
 58
 59    It's used internally to recognize when a default value has been overwritten, even
 60    if the new value is `None`.
 61    """
 62
 63    def __init__(self, value: Any):
 64        self.value = value
 65
 66    def __bool__(self) -> bool:
 67        return bool(self.value)
 68
 69
 70DefaultType = TypeVar("DefaultType")
 71
 72CommandFunctionType = TypeVar("CommandFunctionType", bound=Callable[..., Any])
 73
 74
 75def Default(value: DefaultType) -> DefaultType:
 76    """
 77    You shouldn't use this function directly.
 78
 79    It's used internally to recognize when a default value has been overwritten, even
 80    if the new value is `None`.
 81    """
 82    return DefaultPlaceholder(value)  # type: ignore
 83
 84
 85class CommandInfo:
 86    def __init__(
 87        self,
 88        name: Optional[str] = None,
 89        *,
 90        cls: Optional[Type["TyperCommand"]] = None,
 91        context_settings: Optional[Dict[Any, Any]] = None,
 92        callback: Optional[Callable[..., Any]] = None,
 93        help: Optional[str] = None,
 94        epilog: Optional[str] = None,
 95        short_help: Optional[str] = None,
 96        options_metavar: str = "[OPTIONS]",
 97        add_help_option: bool = True,
 98        no_args_is_help: bool = False,
 99        hidden: bool = False,
100        deprecated: bool = False,
101        # Rich settings
102        rich_help_panel: Union[str, None] = None,
103    ):
104        self.name = name
105        self.cls = cls
106        self.context_settings = context_settings
107        self.callback = callback
108        self.help = help
109        self.epilog = epilog
110        self.short_help = short_help
111        self.options_metavar = options_metavar
112        self.add_help_option = add_help_option
113        self.no_args_is_help = no_args_is_help
114        self.hidden = hidden
115        self.deprecated = deprecated
116        # Rich settings
117        self.rich_help_panel = rich_help_panel
118
119
120class TyperInfo:
121    def __init__(
122        self,
123        typer_instance: Optional["Typer"] = Default(None),
124        *,
125        name: Optional[str] = Default(None),
126        cls: Optional[Type["TyperGroup"]] = Default(None),
127        invoke_without_command: bool = Default(False),
128        no_args_is_help: bool = Default(False),
129        subcommand_metavar: Optional[str] = Default(None),
130        chain: bool = Default(False),
131        result_callback: Optional[Callable[..., Any]] = Default(None),
132        # Command
133        context_settings: Optional[Dict[Any, Any]] = Default(None),
134        callback: Optional[Callable[..., Any]] = Default(None),
135        help: Optional[str] = Default(None),
136        epilog: Optional[str] = Default(None),
137        short_help: Optional[str] = Default(None),
138        options_metavar: str = Default("[OPTIONS]"),
139        add_help_option: bool = Default(True),
140        hidden: bool = Default(False),
141        deprecated: bool = Default(False),
142        # Rich settings
143        rich_help_panel: Union[str, None] = Default(None),
144    ):
145        self.typer_instance = typer_instance
146        self.name = name
147        self.cls = cls
148        self.invoke_without_command = invoke_without_command
149        self.no_args_is_help = no_args_is_help
150        self.subcommand_metavar = subcommand_metavar
151        self.chain = chain
152        self.result_callback = result_callback
153        self.context_settings = context_settings
154        self.callback = callback
155        self.help = help
156        self.epilog = epilog
157        self.short_help = short_help
158        self.options_metavar = options_metavar
159        self.add_help_option = add_help_option
160        self.hidden = hidden
161        self.deprecated = deprecated
162        self.rich_help_panel = rich_help_panel
163
164
165class ParameterInfo:
166    def __init__(
167        self,
168        *,
169        default: Optional[Any] = None,
170        param_decls: Optional[Sequence[str]] = None,
171        callback: Optional[Callable[..., Any]] = None,
172        metavar: Optional[str] = None,
173        expose_value: bool = True,
174        is_eager: bool = False,
175        envvar: Optional[Union[str, List[str]]] = None,
176        shell_complete: Optional[
177            Callable[
178                [click.Context, click.Parameter, str],
179                Union[List["click.shell_completion.CompletionItem"], List[str]],
180            ]
181        ] = None,
182        autocompletion: Optional[Callable[..., Any]] = None,
183        default_factory: Optional[Callable[[], Any]] = None,
184        # Custom type
185        parser: Optional[Callable[[str], Any]] = None,
186        click_type: Optional[click.ParamType] = None,
187        # TyperArgument
188        show_default: Union[bool, str] = True,
189        show_choices: bool = True,
190        show_envvar: bool = True,
191        help: Optional[str] = None,
192        hidden: bool = False,
193        # Choice
194        case_sensitive: bool = True,
195        # Numbers
196        min: Optional[Union[int, float]] = None,
197        max: Optional[Union[int, float]] = None,
198        clamp: bool = False,
199        # DateTime
200        formats: Optional[List[str]] = None,
201        # File
202        mode: Optional[str] = None,
203        encoding: Optional[str] = None,
204        errors: Optional[str] = "strict",
205        lazy: Optional[bool] = None,
206        atomic: bool = False,
207        # Path
208        exists: bool = False,
209        file_okay: bool = True,
210        dir_okay: bool = True,
211        writable: bool = False,
212        readable: bool = True,
213        resolve_path: bool = False,
214        allow_dash: bool = False,
215        path_type: Union[None, Type[str], Type[bytes]] = None,
216        # Rich settings
217        rich_help_panel: Union[str, None] = None,
218    ):
219        # Check if user has provided multiple custom parsers
220        if parser and click_type:
221            raise ValueError(
222                "Multiple custom type parsers provided. "
223                "`parser` and `click_type` may not both be provided."
224            )
225
226        self.default = default
227        self.param_decls = param_decls
228        self.callback = callback
229        self.metavar = metavar
230        self.expose_value = expose_value
231        self.is_eager = is_eager
232        self.envvar = envvar
233        self.shell_complete = shell_complete
234        self.autocompletion = autocompletion
235        self.default_factory = default_factory
236        # Custom type
237        self.parser = parser
238        self.click_type = click_type
239        # TyperArgument
240        self.show_default = show_default
241        self.show_choices = show_choices
242        self.show_envvar = show_envvar
243        self.help = help
244        self.hidden = hidden
245        # Choice
246        self.case_sensitive = case_sensitive
247        # Numbers
248        self.min = min
249        self.max = max
250        self.clamp = clamp
251        # DateTime
252        self.formats = formats
253        # File
254        self.mode = mode
255        self.encoding = encoding
256        self.errors = errors
257        self.lazy = lazy
258        self.atomic = atomic
259        # Path
260        self.exists = exists
261        self.file_okay = file_okay
262        self.dir_okay = dir_okay
263        self.writable = writable
264        self.readable = readable
265        self.resolve_path = resolve_path
266        self.allow_dash = allow_dash
267        self.path_type = path_type
268        # Rich settings
269        self.rich_help_panel = rich_help_panel
270
271
272class OptionInfo(ParameterInfo):
273    def __init__(
274        self,
275        *,
276        # ParameterInfo
277        default: Optional[Any] = None,
278        param_decls: Optional[Sequence[str]] = None,
279        callback: Optional[Callable[..., Any]] = None,
280        metavar: Optional[str] = None,
281        expose_value: bool = True,
282        is_eager: bool = False,
283        envvar: Optional[Union[str, List[str]]] = None,
284        shell_complete: Optional[
285            Callable[
286                [click.Context, click.Parameter, str],
287                Union[List["click.shell_completion.CompletionItem"], List[str]],
288            ]
289        ] = None,
290        autocompletion: Optional[Callable[..., Any]] = None,
291        default_factory: Optional[Callable[[], Any]] = None,
292        # Custom type
293        parser: Optional[Callable[[str], Any]] = None,
294        click_type: Optional[click.ParamType] = None,
295        # Option
296        show_default: Union[bool, str] = True,
297        prompt: Union[bool, str] = False,
298        confirmation_prompt: bool = False,
299        prompt_required: bool = True,
300        hide_input: bool = False,
301        # TODO: remove is_flag and flag_value in a future release
302        is_flag: Optional[bool] = None,
303        flag_value: Optional[Any] = None,
304        count: bool = False,
305        allow_from_autoenv: bool = True,
306        help: Optional[str] = None,
307        hidden: bool = False,
308        show_choices: bool = True,
309        show_envvar: bool = True,
310        # Choice
311        case_sensitive: bool = True,
312        # Numbers
313        min: Optional[Union[int, float]] = None,
314        max: Optional[Union[int, float]] = None,
315        clamp: bool = False,
316        # DateTime
317        formats: Optional[List[str]] = None,
318        # File
319        mode: Optional[str] = None,
320        encoding: Optional[str] = None,
321        errors: Optional[str] = "strict",
322        lazy: Optional[bool] = None,
323        atomic: bool = False,
324        # Path
325        exists: bool = False,
326        file_okay: bool = True,
327        dir_okay: bool = True,
328        writable: bool = False,
329        readable: bool = True,
330        resolve_path: bool = False,
331        allow_dash: bool = False,
332        path_type: Union[None, Type[str], Type[bytes]] = None,
333        # Rich settings
334        rich_help_panel: Union[str, None] = None,
335    ):
336        super().__init__(
337            default=default,
338            param_decls=param_decls,
339            callback=callback,
340            metavar=metavar,
341            expose_value=expose_value,
342            is_eager=is_eager,
343            envvar=envvar,
344            shell_complete=shell_complete,
345            autocompletion=autocompletion,
346            default_factory=default_factory,
347            # Custom type
348            parser=parser,
349            click_type=click_type,
350            # TyperArgument
351            show_default=show_default,
352            show_choices=show_choices,
353            show_envvar=show_envvar,
354            help=help,
355            hidden=hidden,
356            # Choice
357            case_sensitive=case_sensitive,
358            # Numbers
359            min=min,
360            max=max,
361            clamp=clamp,
362            # DateTime
363            formats=formats,
364            # File
365            mode=mode,
366            encoding=encoding,
367            errors=errors,
368            lazy=lazy,
369            atomic=atomic,
370            # Path
371            exists=exists,
372            file_okay=file_okay,
373            dir_okay=dir_okay,
374            writable=writable,
375            readable=readable,
376            resolve_path=resolve_path,
377            allow_dash=allow_dash,
378            path_type=path_type,
379            # Rich settings
380            rich_help_panel=rich_help_panel,
381        )
382        if is_flag is not None or flag_value is not None:
383            import warnings
384
385            warnings.warn(
386                "The 'is_flag' and 'flag_value' parameters are not supported by Typer "
387                "and will be removed entirely in a future release.",
388                DeprecationWarning,
389                stacklevel=2,
390            )
391        self.prompt = prompt
392        self.confirmation_prompt = confirmation_prompt
393        self.prompt_required = prompt_required
394        self.hide_input = hide_input
395        self.count = count
396        self.allow_from_autoenv = allow_from_autoenv
397
398
399class ArgumentInfo(ParameterInfo):
400    def __init__(
401        self,
402        *,
403        # ParameterInfo
404        default: Optional[Any] = None,
405        param_decls: Optional[Sequence[str]] = None,
406        callback: Optional[Callable[..., Any]] = None,
407        metavar: Optional[str] = None,
408        expose_value: bool = True,
409        is_eager: bool = False,
410        envvar: Optional[Union[str, List[str]]] = None,
411        shell_complete: Optional[
412            Callable[
413                [click.Context, click.Parameter, str],
414                Union[List["click.shell_completion.CompletionItem"], List[str]],
415            ]
416        ] = None,
417        autocompletion: Optional[Callable[..., Any]] = None,
418        default_factory: Optional[Callable[[], Any]] = None,
419        # Custom type
420        parser: Optional[Callable[[str], Any]] = None,
421        click_type: Optional[click.ParamType] = None,
422        # TyperArgument
423        show_default: Union[bool, str] = True,
424        show_choices: bool = True,
425        show_envvar: bool = True,
426        help: Optional[str] = None,
427        hidden: bool = False,
428        # Choice
429        case_sensitive: bool = True,
430        # Numbers
431        min: Optional[Union[int, float]] = None,
432        max: Optional[Union[int, float]] = None,
433        clamp: bool = False,
434        # DateTime
435        formats: Optional[List[str]] = None,
436        # File
437        mode: Optional[str] = None,
438        encoding: Optional[str] = None,
439        errors: Optional[str] = "strict",
440        lazy: Optional[bool] = None,
441        atomic: bool = False,
442        # Path
443        exists: bool = False,
444        file_okay: bool = True,
445        dir_okay: bool = True,
446        writable: bool = False,
447        readable: bool = True,
448        resolve_path: bool = False,
449        allow_dash: bool = False,
450        path_type: Union[None, Type[str], Type[bytes]] = None,
451        # Rich settings
452        rich_help_panel: Union[str, None] = None,
453    ):
454        super().__init__(
455            default=default,
456            param_decls=param_decls,
457            callback=callback,
458            metavar=metavar,
459            expose_value=expose_value,
460            is_eager=is_eager,
461            envvar=envvar,
462            shell_complete=shell_complete,
463            autocompletion=autocompletion,
464            default_factory=default_factory,
465            # Custom type
466            parser=parser,
467            click_type=click_type,
468            # TyperArgument
469            show_default=show_default,
470            show_choices=show_choices,
471            show_envvar=show_envvar,
472            help=help,
473            hidden=hidden,
474            # Choice
475            case_sensitive=case_sensitive,
476            # Numbers
477            min=min,
478            max=max,
479            clamp=clamp,
480            # DateTime
481            formats=formats,
482            # File
483            mode=mode,
484            encoding=encoding,
485            errors=errors,
486            lazy=lazy,
487            atomic=atomic,
488            # Path
489            exists=exists,
490            file_okay=file_okay,
491            dir_okay=dir_okay,
492            writable=writable,
493            readable=readable,
494            resolve_path=resolve_path,
495            allow_dash=allow_dash,
496            path_type=path_type,
497            # Rich settings
498            rich_help_panel=rich_help_panel,
499        )
500
501
502class ParamMeta:
503    empty = inspect.Parameter.empty
504
505    def __init__(
506        self,
507        *,
508        name: str,
509        default: Any = inspect.Parameter.empty,
510        annotation: Any = inspect.Parameter.empty,
511    ) -> None:
512        self.name = name
513        self.default = default
514        self.annotation = annotation
515
516
517class DeveloperExceptionConfig:
518    def __init__(
519        self,
520        *,
521        pretty_exceptions_enable: bool = True,
522        pretty_exceptions_show_locals: bool = True,
523        pretty_exceptions_short: bool = True,
524    ) -> None:
525        self.pretty_exceptions_enable = pretty_exceptions_enable
526        self.pretty_exceptions_show_locals = pretty_exceptions_show_locals
527        self.pretty_exceptions_short = pretty_exceptions_short
class NoneType:
AnyType = typing.Type[typing.Any]
Required = Ellipsis
class Context(click.core.Context):
32class Context(click.Context):
33    pass

The context is a special internal object that holds state relevant for the script execution at every single level. It's normally invisible to commands unless they opt-in to getting access to it.

The context is useful as it can pass internal objects around and can control special execution features such as reading data from environment variables.

A context can be used as context manager in which case it will call close() on teardown.

Parameters
  • command: the command class for this context.
  • parent: the parent context.
  • info_name: the info name for this invocation. Generally this is the most descriptive name for the script or command. For the toplevel script it is usually the name of the script, for commands below it it's the name of the script.
  • obj: an arbitrary object of user data.
  • auto_envvar_prefix: the prefix to use for automatic environment variables. If this is None then reading from environment variables is disabled. This does not affect manually set environment variables which are always read.
  • default_map: a dictionary (like object) with default values for parameters.
  • terminal_width: the width of the terminal. The default is inherit from parent context. If no context defines the terminal width then auto detection will be applied.
  • max_content_width: the maximum width for content rendered by Click (this currently only affects help pages). This defaults to 80 characters if not overridden. In other words: even if the terminal is larger than that, Click will not format things wider than 80 characters by default. In addition to that, formatters might add some safety mapping on the right.
  • resilient_parsing: if this flag is enabled then Click will parse without any interactivity or callback invocation. Default values will also be ignored. This is useful for implementing things such as completion support.
  • allow_extra_args: if this is set to True then extra arguments at the end will not raise an error and will be kept on the context. The default is to inherit from the command.
  • allow_interspersed_args: if this is set to False then options and arguments cannot be mixed. The default is to inherit from the command.
  • ignore_unknown_options: instructs click to ignore options it does not know and keeps them for later processing.
  • help_option_names: optionally a list of strings that define how the default help parameter is named. The default is ['--help'].
  • token_normalize_func: an optional function that is used to normalize tokens (options, choices, etc.). This for instance can be used to implement case insensitive behavior.
  • color: controls if the terminal supports ANSI colors or not. The default is autodetection. This is only needed if ANSI codes are used in texts that Click prints which is by default not the case. This for instance would affect help output.
  • show_default: Show the default value for commands. If this value is not set, it defaults to the value from the parent context. Command.show_default overrides this default for the specific command.

Changed in version 8.1: The show_default parameter is overridden by Command.show_default, instead of the other way around.

Changed in version 8.0: The show_default parameter defaults to the value from the parent context.

Changed in version 7.1: Added the show_default parameter.

Changed in version 4.0: Added the color, ignore_unknown_options, and max_content_width parameters.

Changed in version 3.0: Added the allow_extra_args and allow_interspersed_args parameters.

Changed in version 2.0: Added the resilient_parsing, help_option_names, and token_normalize_func parameters.

Inherited Members
click.core.Context
Context
formatter_class
parent
command
info_name
params
args
protected_args
obj
default_map
invoked_subcommand
terminal_width
max_content_width
allow_extra_args
allow_interspersed_args
ignore_unknown_options
help_option_names
token_normalize_func
resilient_parsing
auto_envvar_prefix
color
show_default
to_info_dict
scope
meta
make_formatter
with_resource
call_on_close
close
command_path
find_root
find_object
ensure_object
lookup_default
fail
abort
exit
get_usage
get_help
invoke
forward
set_parameter_source
get_parameter_source
class FileText(_io.TextIOWrapper):
36class FileText(io.TextIOWrapper):
37    pass

Character and line based layer over a BufferedIOBase object, buffer.

encoding gives the name of the encoding that the stream will be decoded or encoded with. It defaults to locale.getencoding().

errors determines the strictness of encoding and decoding (see help(codecs.Codec) or the documentation for codecs.register) and defaults to "strict".

newline controls how line endings are handled. It can be None, '', '\n', '\r', and '\r\n'. It works as follows:

  • On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in '\n', '\r', or '\r\n', and these are translated into '\n' before being returned to the caller. If it is '', universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.

  • On output, if newline is None, any '\n' characters written are translated to the system default line separator, os.linesep. If newline is '' or '\n', no translation takes place. If newline is any of the other legal values, any '\n' characters written are translated to the given string.

If line_buffering is True, a call to flush is implied when a call to write contains a newline character.

Inherited Members
_io.TextIOWrapper
TextIOWrapper
detach
reconfigure
write
read
readline
flush
close
fileno
seekable
readable
writable
isatty
seek
tell
truncate
encoding
buffer
line_buffering
write_through
name
closed
newlines
errors
_io._IOBase
readlines
writelines
class FileTextWrite(FileText):
40class FileTextWrite(FileText):
41    pass

Character and line based layer over a BufferedIOBase object, buffer.

encoding gives the name of the encoding that the stream will be decoded or encoded with. It defaults to locale.getencoding().

errors determines the strictness of encoding and decoding (see help(codecs.Codec) or the documentation for codecs.register) and defaults to "strict".

newline controls how line endings are handled. It can be None, '', '\n', '\r', and '\r\n'. It works as follows:

  • On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in '\n', '\r', or '\r\n', and these are translated into '\n' before being returned to the caller. If it is '', universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.

  • On output, if newline is None, any '\n' characters written are translated to the system default line separator, os.linesep. If newline is '' or '\n', no translation takes place. If newline is any of the other legal values, any '\n' characters written are translated to the given string.

If line_buffering is True, a call to flush is implied when a call to write contains a newline character.

Inherited Members
_io.TextIOWrapper
TextIOWrapper
detach
reconfigure
write
read
readline
flush
close
fileno
seekable
readable
writable
isatty
seek
tell
truncate
encoding
buffer
line_buffering
write_through
name
closed
newlines
errors
_io._IOBase
readlines
writelines
class FileBinaryRead(_io.BufferedReader):
44class FileBinaryRead(io.BufferedReader):
45    pass

Create a new buffered reader using the given readable raw IO object.

Inherited Members
_io.BufferedReader
BufferedReader
detach
flush
close
seekable
readable
fileno
isatty
read
peek
read1
readinto
readinto1
readline
seek
tell
truncate
raw
closed
name
mode
_io._BufferedIOBase
write
_io._IOBase
writable
readlines
writelines
class FileBinaryWrite(_io.BufferedWriter):
48class FileBinaryWrite(io.BufferedWriter):
49    pass

A buffer for a writeable sequential RawIO object.

The constructor creates a BufferedWriter for the given writeable raw stream. If the buffer_size is not given, it defaults to DEFAULT_BUFFER_SIZE.

Inherited Members
_io.BufferedWriter
BufferedWriter
close
detach
seekable
writable
fileno
isatty
write
truncate
flush
seek
tell
raw
closed
name
mode
_io._BufferedIOBase
read
read1
readinto
readinto1
_io._IOBase
readable
readline
readlines
writelines
class CallbackParam(click.core.Parameter):
52class CallbackParam(click.Parameter):
53    pass

A parameter to a command comes in two versions: they are either Option\s or Argument\s. Other subclasses are currently not supported by design as some of the internals for parsing are intentionally not finalized.

Some settings are supported by both options and arguments.

Parameters
  • param_decls: the parameter declarations for this option or argument. This is a list of flags or argument names.
  • type: the type that should be used. Either a ParamType or a Python type. The latter is converted into the former automatically if supported.
  • required: controls if this is optional or not.
  • default: the default value if omitted. This can also be a callable, in which case it's invoked when the default is needed without any arguments.
  • callback: A function to further process or validate the value after type conversion. It is called as f(ctx, param, value) and must return the value. It is called for all sources, including prompts.
  • nargs: the number of arguments to match. If not 1 the return value is a tuple instead of single value. The default for nargs is 1 (except if the type is a tuple, then it's the arity of the tuple). If nargs=-1, all remaining parameters are collected.
  • metavar: how the value is represented in the help page.
  • expose_value: if this is True then the value is passed onwards to the command callback and stored on the context, otherwise it's skipped.
  • is_eager: eager values are processed before non eager ones. This should not be set for arguments or it will inverse the order of processing.
  • envvar: a string or list of strings that are environment variables that should be checked.
  • shell_complete: A function that returns custom shell completions. Used instead of the param's type completion if given. Takes ctx, param, incomplete and must return a list of ~click.shell_completion.CompletionItem or a list of strings.

Changed in version 8.0: process_value validates required parameters and bounded nargs, and invokes the parameter callback before returning the value. This allows the callback to validate prompts. full_process_value is removed.

Changed in version 8.0: autocompletion is renamed to shell_complete and has new semantics described above. The old name is deprecated and will be removed in 8.1, until then it will be wrapped to match the new requirements.

Changed in version 8.0: For multiple=True, nargs>1, the default must be a list of tuples.

Changed in version 8.0: Setting a default is no longer required for nargs>1, it will default to None. multiple=True or nargs=-1 will default to ().

Changed in version 7.1: Empty environment variables are ignored rather than taking the empty string value. This makes it possible for scripts to clear variables if they can't unset them.

Changed in version 2.0: Changed signature for parameter callback to also be passed the parameter. The old callback format will still work, but it will raise a warning to give you a chance to migrate the code easier.

Inherited Members
click.core.Parameter
Parameter
param_type_name
name
opts
secondary_opts
type
required
callback
nargs
multiple
expose_value
default
is_eager
metavar
envvar
to_info_dict
human_readable_name
make_metavar
get_default
add_to_parser
consume_value
type_cast_value
value_is_missing
process_value
resolve_envvar_value
value_from_envvar
handle_parse_result
get_help_record
get_usage_pieces
get_error_hint
shell_complete
class DefaultPlaceholder:
56class DefaultPlaceholder:
57    """
58    You shouldn't use this class directly.
59
60    It's used internally to recognize when a default value has been overwritten, even
61    if the new value is `None`.
62    """
63
64    def __init__(self, value: Any):
65        self.value = value
66
67    def __bool__(self) -> bool:
68        return bool(self.value)

You shouldn't use this class directly.

It's used internally to recognize when a default value has been overwritten, even if the new value is None.

DefaultPlaceholder(value: Any)
64    def __init__(self, value: Any):
65        self.value = value
value
def Default(value: ~DefaultType) -> ~DefaultType:
76def Default(value: DefaultType) -> DefaultType:
77    """
78    You shouldn't use this function directly.
79
80    It's used internally to recognize when a default value has been overwritten, even
81    if the new value is `None`.
82    """
83    return DefaultPlaceholder(value)  # type: ignore

You shouldn't use this function directly.

It's used internally to recognize when a default value has been overwritten, even if the new value is None.

class CommandInfo:
 86class CommandInfo:
 87    def __init__(
 88        self,
 89        name: Optional[str] = None,
 90        *,
 91        cls: Optional[Type["TyperCommand"]] = None,
 92        context_settings: Optional[Dict[Any, Any]] = None,
 93        callback: Optional[Callable[..., Any]] = None,
 94        help: Optional[str] = None,
 95        epilog: Optional[str] = None,
 96        short_help: Optional[str] = None,
 97        options_metavar: str = "[OPTIONS]",
 98        add_help_option: bool = True,
 99        no_args_is_help: bool = False,
100        hidden: bool = False,
101        deprecated: bool = False,
102        # Rich settings
103        rich_help_panel: Union[str, None] = None,
104    ):
105        self.name = name
106        self.cls = cls
107        self.context_settings = context_settings
108        self.callback = callback
109        self.help = help
110        self.epilog = epilog
111        self.short_help = short_help
112        self.options_metavar = options_metavar
113        self.add_help_option = add_help_option
114        self.no_args_is_help = no_args_is_help
115        self.hidden = hidden
116        self.deprecated = deprecated
117        # Rich settings
118        self.rich_help_panel = rich_help_panel
CommandInfo( name: Optional[str] = None, *, cls: Optional[Type[typer.core.TyperCommand]] = None, context_settings: Optional[Dict[Any, Any]] = None, callback: Optional[Callable[..., Any]] = None, help: Optional[str] = None, epilog: Optional[str] = None, short_help: Optional[str] = None, options_metavar: str = '[OPTIONS]', add_help_option: bool = True, no_args_is_help: bool = False, hidden: bool = False, deprecated: bool = False, rich_help_panel: Optional[str] = None)
 87    def __init__(
 88        self,
 89        name: Optional[str] = None,
 90        *,
 91        cls: Optional[Type["TyperCommand"]] = None,
 92        context_settings: Optional[Dict[Any, Any]] = None,
 93        callback: Optional[Callable[..., Any]] = None,
 94        help: Optional[str] = None,
 95        epilog: Optional[str] = None,
 96        short_help: Optional[str] = None,
 97        options_metavar: str = "[OPTIONS]",
 98        add_help_option: bool = True,
 99        no_args_is_help: bool = False,
100        hidden: bool = False,
101        deprecated: bool = False,
102        # Rich settings
103        rich_help_panel: Union[str, None] = None,
104    ):
105        self.name = name
106        self.cls = cls
107        self.context_settings = context_settings
108        self.callback = callback
109        self.help = help
110        self.epilog = epilog
111        self.short_help = short_help
112        self.options_metavar = options_metavar
113        self.add_help_option = add_help_option
114        self.no_args_is_help = no_args_is_help
115        self.hidden = hidden
116        self.deprecated = deprecated
117        # Rich settings
118        self.rich_help_panel = rich_help_panel
name
cls
context_settings
callback
help
epilog
short_help
options_metavar
add_help_option
no_args_is_help
hidden
deprecated
rich_help_panel
class TyperInfo:
121class TyperInfo:
122    def __init__(
123        self,
124        typer_instance: Optional["Typer"] = Default(None),
125        *,
126        name: Optional[str] = Default(None),
127        cls: Optional[Type["TyperGroup"]] = Default(None),
128        invoke_without_command: bool = Default(False),
129        no_args_is_help: bool = Default(False),
130        subcommand_metavar: Optional[str] = Default(None),
131        chain: bool = Default(False),
132        result_callback: Optional[Callable[..., Any]] = Default(None),
133        # Command
134        context_settings: Optional[Dict[Any, Any]] = Default(None),
135        callback: Optional[Callable[..., Any]] = Default(None),
136        help: Optional[str] = Default(None),
137        epilog: Optional[str] = Default(None),
138        short_help: Optional[str] = Default(None),
139        options_metavar: str = Default("[OPTIONS]"),
140        add_help_option: bool = Default(True),
141        hidden: bool = Default(False),
142        deprecated: bool = Default(False),
143        # Rich settings
144        rich_help_panel: Union[str, None] = Default(None),
145    ):
146        self.typer_instance = typer_instance
147        self.name = name
148        self.cls = cls
149        self.invoke_without_command = invoke_without_command
150        self.no_args_is_help = no_args_is_help
151        self.subcommand_metavar = subcommand_metavar
152        self.chain = chain
153        self.result_callback = result_callback
154        self.context_settings = context_settings
155        self.callback = callback
156        self.help = help
157        self.epilog = epilog
158        self.short_help = short_help
159        self.options_metavar = options_metavar
160        self.add_help_option = add_help_option
161        self.hidden = hidden
162        self.deprecated = deprecated
163        self.rich_help_panel = rich_help_panel
TyperInfo( typer_instance: Optional[typer.main.Typer] = <DefaultPlaceholder object>, *, name: Optional[str] = <DefaultPlaceholder object>, cls: Optional[Type[typer.core.TyperGroup]] = <DefaultPlaceholder object>, invoke_without_command: bool = <DefaultPlaceholder object>, no_args_is_help: bool = <DefaultPlaceholder object>, subcommand_metavar: Optional[str] = <DefaultPlaceholder object>, chain: bool = <DefaultPlaceholder object>, result_callback: Optional[Callable[..., Any]] = <DefaultPlaceholder object>, context_settings: Optional[Dict[Any, Any]] = <DefaultPlaceholder object>, callback: Optional[Callable[..., Any]] = <DefaultPlaceholder object>, help: Optional[str] = <DefaultPlaceholder object>, epilog: Optional[str] = <DefaultPlaceholder object>, short_help: Optional[str] = <DefaultPlaceholder object>, options_metavar: str = <DefaultPlaceholder object>, add_help_option: bool = <DefaultPlaceholder object>, hidden: bool = <DefaultPlaceholder object>, deprecated: bool = <DefaultPlaceholder object>, rich_help_panel: Optional[str] = <DefaultPlaceholder object>)
122    def __init__(
123        self,
124        typer_instance: Optional["Typer"] = Default(None),
125        *,
126        name: Optional[str] = Default(None),
127        cls: Optional[Type["TyperGroup"]] = Default(None),
128        invoke_without_command: bool = Default(False),
129        no_args_is_help: bool = Default(False),
130        subcommand_metavar: Optional[str] = Default(None),
131        chain: bool = Default(False),
132        result_callback: Optional[Callable[..., Any]] = Default(None),
133        # Command
134        context_settings: Optional[Dict[Any, Any]] = Default(None),
135        callback: Optional[Callable[..., Any]] = Default(None),
136        help: Optional[str] = Default(None),
137        epilog: Optional[str] = Default(None),
138        short_help: Optional[str] = Default(None),
139        options_metavar: str = Default("[OPTIONS]"),
140        add_help_option: bool = Default(True),
141        hidden: bool = Default(False),
142        deprecated: bool = Default(False),
143        # Rich settings
144        rich_help_panel: Union[str, None] = Default(None),
145    ):
146        self.typer_instance = typer_instance
147        self.name = name
148        self.cls = cls
149        self.invoke_without_command = invoke_without_command
150        self.no_args_is_help = no_args_is_help
151        self.subcommand_metavar = subcommand_metavar
152        self.chain = chain
153        self.result_callback = result_callback
154        self.context_settings = context_settings
155        self.callback = callback
156        self.help = help
157        self.epilog = epilog
158        self.short_help = short_help
159        self.options_metavar = options_metavar
160        self.add_help_option = add_help_option
161        self.hidden = hidden
162        self.deprecated = deprecated
163        self.rich_help_panel = rich_help_panel
typer_instance
name
cls
invoke_without_command
no_args_is_help
subcommand_metavar
chain
result_callback
context_settings
callback
help
epilog
short_help
options_metavar
add_help_option
hidden
deprecated
rich_help_panel
class ParameterInfo:
166class ParameterInfo:
167    def __init__(
168        self,
169        *,
170        default: Optional[Any] = None,
171        param_decls: Optional[Sequence[str]] = None,
172        callback: Optional[Callable[..., Any]] = None,
173        metavar: Optional[str] = None,
174        expose_value: bool = True,
175        is_eager: bool = False,
176        envvar: Optional[Union[str, List[str]]] = None,
177        shell_complete: Optional[
178            Callable[
179                [click.Context, click.Parameter, str],
180                Union[List["click.shell_completion.CompletionItem"], List[str]],
181            ]
182        ] = None,
183        autocompletion: Optional[Callable[..., Any]] = None,
184        default_factory: Optional[Callable[[], Any]] = None,
185        # Custom type
186        parser: Optional[Callable[[str], Any]] = None,
187        click_type: Optional[click.ParamType] = None,
188        # TyperArgument
189        show_default: Union[bool, str] = True,
190        show_choices: bool = True,
191        show_envvar: bool = True,
192        help: Optional[str] = None,
193        hidden: bool = False,
194        # Choice
195        case_sensitive: bool = True,
196        # Numbers
197        min: Optional[Union[int, float]] = None,
198        max: Optional[Union[int, float]] = None,
199        clamp: bool = False,
200        # DateTime
201        formats: Optional[List[str]] = None,
202        # File
203        mode: Optional[str] = None,
204        encoding: Optional[str] = None,
205        errors: Optional[str] = "strict",
206        lazy: Optional[bool] = None,
207        atomic: bool = False,
208        # Path
209        exists: bool = False,
210        file_okay: bool = True,
211        dir_okay: bool = True,
212        writable: bool = False,
213        readable: bool = True,
214        resolve_path: bool = False,
215        allow_dash: bool = False,
216        path_type: Union[None, Type[str], Type[bytes]] = None,
217        # Rich settings
218        rich_help_panel: Union[str, None] = None,
219    ):
220        # Check if user has provided multiple custom parsers
221        if parser and click_type:
222            raise ValueError(
223                "Multiple custom type parsers provided. "
224                "`parser` and `click_type` may not both be provided."
225            )
226
227        self.default = default
228        self.param_decls = param_decls
229        self.callback = callback
230        self.metavar = metavar
231        self.expose_value = expose_value
232        self.is_eager = is_eager
233        self.envvar = envvar
234        self.shell_complete = shell_complete
235        self.autocompletion = autocompletion
236        self.default_factory = default_factory
237        # Custom type
238        self.parser = parser
239        self.click_type = click_type
240        # TyperArgument
241        self.show_default = show_default
242        self.show_choices = show_choices
243        self.show_envvar = show_envvar
244        self.help = help
245        self.hidden = hidden
246        # Choice
247        self.case_sensitive = case_sensitive
248        # Numbers
249        self.min = min
250        self.max = max
251        self.clamp = clamp
252        # DateTime
253        self.formats = formats
254        # File
255        self.mode = mode
256        self.encoding = encoding
257        self.errors = errors
258        self.lazy = lazy
259        self.atomic = atomic
260        # Path
261        self.exists = exists
262        self.file_okay = file_okay
263        self.dir_okay = dir_okay
264        self.writable = writable
265        self.readable = readable
266        self.resolve_path = resolve_path
267        self.allow_dash = allow_dash
268        self.path_type = path_type
269        # Rich settings
270        self.rich_help_panel = rich_help_panel
ParameterInfo( *, default: Optional[Any] = None, param_decls: Optional[Sequence[str]] = None, callback: Optional[Callable[..., Any]] = None, metavar: Optional[str] = None, expose_value: bool = True, is_eager: bool = False, envvar: Union[str, List[str], NoneType] = None, shell_complete: Optional[Callable[[click.core.Context, click.core.Parameter, str], Union[List[click.shell_completion.CompletionItem], List[str]]]] = None, autocompletion: Optional[Callable[..., Any]] = None, default_factory: Optional[Callable[[], Any]] = None, parser: Optional[Callable[[str], Any]] = None, click_type: Optional[click.types.ParamType] = None, show_default: Union[bool, str] = True, show_choices: bool = True, show_envvar: bool = True, help: Optional[str] = None, hidden: bool = False, case_sensitive: bool = True, min: Union[int, float, NoneType] = None, max: Union[int, float, NoneType] = None, clamp: bool = False, formats: Optional[List[str]] = None, mode: Optional[str] = None, encoding: Optional[str] = None, errors: Optional[str] = 'strict', lazy: Optional[bool] = None, atomic: bool = False, exists: bool = False, file_okay: bool = True, dir_okay: bool = True, writable: bool = False, readable: bool = True, resolve_path: bool = False, allow_dash: bool = False, path_type: Union[NoneType, Type[str], Type[bytes]] = None, rich_help_panel: Optional[str] = None)
167    def __init__(
168        self,
169        *,
170        default: Optional[Any] = None,
171        param_decls: Optional[Sequence[str]] = None,
172        callback: Optional[Callable[..., Any]] = None,
173        metavar: Optional[str] = None,
174        expose_value: bool = True,
175        is_eager: bool = False,
176        envvar: Optional[Union[str, List[str]]] = None,
177        shell_complete: Optional[
178            Callable[
179                [click.Context, click.Parameter, str],
180                Union[List["click.shell_completion.CompletionItem"], List[str]],
181            ]
182        ] = None,
183        autocompletion: Optional[Callable[..., Any]] = None,
184        default_factory: Optional[Callable[[], Any]] = None,
185        # Custom type
186        parser: Optional[Callable[[str], Any]] = None,
187        click_type: Optional[click.ParamType] = None,
188        # TyperArgument
189        show_default: Union[bool, str] = True,
190        show_choices: bool = True,
191        show_envvar: bool = True,
192        help: Optional[str] = None,
193        hidden: bool = False,
194        # Choice
195        case_sensitive: bool = True,
196        # Numbers
197        min: Optional[Union[int, float]] = None,
198        max: Optional[Union[int, float]] = None,
199        clamp: bool = False,
200        # DateTime
201        formats: Optional[List[str]] = None,
202        # File
203        mode: Optional[str] = None,
204        encoding: Optional[str] = None,
205        errors: Optional[str] = "strict",
206        lazy: Optional[bool] = None,
207        atomic: bool = False,
208        # Path
209        exists: bool = False,
210        file_okay: bool = True,
211        dir_okay: bool = True,
212        writable: bool = False,
213        readable: bool = True,
214        resolve_path: bool = False,
215        allow_dash: bool = False,
216        path_type: Union[None, Type[str], Type[bytes]] = None,
217        # Rich settings
218        rich_help_panel: Union[str, None] = None,
219    ):
220        # Check if user has provided multiple custom parsers
221        if parser and click_type:
222            raise ValueError(
223                "Multiple custom type parsers provided. "
224                "`parser` and `click_type` may not both be provided."
225            )
226
227        self.default = default
228        self.param_decls = param_decls
229        self.callback = callback
230        self.metavar = metavar
231        self.expose_value = expose_value
232        self.is_eager = is_eager
233        self.envvar = envvar
234        self.shell_complete = shell_complete
235        self.autocompletion = autocompletion
236        self.default_factory = default_factory
237        # Custom type
238        self.parser = parser
239        self.click_type = click_type
240        # TyperArgument
241        self.show_default = show_default
242        self.show_choices = show_choices
243        self.show_envvar = show_envvar
244        self.help = help
245        self.hidden = hidden
246        # Choice
247        self.case_sensitive = case_sensitive
248        # Numbers
249        self.min = min
250        self.max = max
251        self.clamp = clamp
252        # DateTime
253        self.formats = formats
254        # File
255        self.mode = mode
256        self.encoding = encoding
257        self.errors = errors
258        self.lazy = lazy
259        self.atomic = atomic
260        # Path
261        self.exists = exists
262        self.file_okay = file_okay
263        self.dir_okay = dir_okay
264        self.writable = writable
265        self.readable = readable
266        self.resolve_path = resolve_path
267        self.allow_dash = allow_dash
268        self.path_type = path_type
269        # Rich settings
270        self.rich_help_panel = rich_help_panel
default
param_decls
callback
metavar
expose_value
is_eager
envvar
shell_complete
autocompletion
default_factory
parser
click_type
show_default
show_choices
show_envvar
help
hidden
case_sensitive
min
max
clamp
formats
mode
encoding
errors
lazy
atomic
exists
file_okay
dir_okay
writable
readable
resolve_path
allow_dash
path_type
rich_help_panel
class OptionInfo(ParameterInfo):
273class OptionInfo(ParameterInfo):
274    def __init__(
275        self,
276        *,
277        # ParameterInfo
278        default: Optional[Any] = None,
279        param_decls: Optional[Sequence[str]] = None,
280        callback: Optional[Callable[..., Any]] = None,
281        metavar: Optional[str] = None,
282        expose_value: bool = True,
283        is_eager: bool = False,
284        envvar: Optional[Union[str, List[str]]] = None,
285        shell_complete: Optional[
286            Callable[
287                [click.Context, click.Parameter, str],
288                Union[List["click.shell_completion.CompletionItem"], List[str]],
289            ]
290        ] = None,
291        autocompletion: Optional[Callable[..., Any]] = None,
292        default_factory: Optional[Callable[[], Any]] = None,
293        # Custom type
294        parser: Optional[Callable[[str], Any]] = None,
295        click_type: Optional[click.ParamType] = None,
296        # Option
297        show_default: Union[bool, str] = True,
298        prompt: Union[bool, str] = False,
299        confirmation_prompt: bool = False,
300        prompt_required: bool = True,
301        hide_input: bool = False,
302        # TODO: remove is_flag and flag_value in a future release
303        is_flag: Optional[bool] = None,
304        flag_value: Optional[Any] = None,
305        count: bool = False,
306        allow_from_autoenv: bool = True,
307        help: Optional[str] = None,
308        hidden: bool = False,
309        show_choices: bool = True,
310        show_envvar: bool = True,
311        # Choice
312        case_sensitive: bool = True,
313        # Numbers
314        min: Optional[Union[int, float]] = None,
315        max: Optional[Union[int, float]] = None,
316        clamp: bool = False,
317        # DateTime
318        formats: Optional[List[str]] = None,
319        # File
320        mode: Optional[str] = None,
321        encoding: Optional[str] = None,
322        errors: Optional[str] = "strict",
323        lazy: Optional[bool] = None,
324        atomic: bool = False,
325        # Path
326        exists: bool = False,
327        file_okay: bool = True,
328        dir_okay: bool = True,
329        writable: bool = False,
330        readable: bool = True,
331        resolve_path: bool = False,
332        allow_dash: bool = False,
333        path_type: Union[None, Type[str], Type[bytes]] = None,
334        # Rich settings
335        rich_help_panel: Union[str, None] = None,
336    ):
337        super().__init__(
338            default=default,
339            param_decls=param_decls,
340            callback=callback,
341            metavar=metavar,
342            expose_value=expose_value,
343            is_eager=is_eager,
344            envvar=envvar,
345            shell_complete=shell_complete,
346            autocompletion=autocompletion,
347            default_factory=default_factory,
348            # Custom type
349            parser=parser,
350            click_type=click_type,
351            # TyperArgument
352            show_default=show_default,
353            show_choices=show_choices,
354            show_envvar=show_envvar,
355            help=help,
356            hidden=hidden,
357            # Choice
358            case_sensitive=case_sensitive,
359            # Numbers
360            min=min,
361            max=max,
362            clamp=clamp,
363            # DateTime
364            formats=formats,
365            # File
366            mode=mode,
367            encoding=encoding,
368            errors=errors,
369            lazy=lazy,
370            atomic=atomic,
371            # Path
372            exists=exists,
373            file_okay=file_okay,
374            dir_okay=dir_okay,
375            writable=writable,
376            readable=readable,
377            resolve_path=resolve_path,
378            allow_dash=allow_dash,
379            path_type=path_type,
380            # Rich settings
381            rich_help_panel=rich_help_panel,
382        )
383        if is_flag is not None or flag_value is not None:
384            import warnings
385
386            warnings.warn(
387                "The 'is_flag' and 'flag_value' parameters are not supported by Typer "
388                "and will be removed entirely in a future release.",
389                DeprecationWarning,
390                stacklevel=2,
391            )
392        self.prompt = prompt
393        self.confirmation_prompt = confirmation_prompt
394        self.prompt_required = prompt_required
395        self.hide_input = hide_input
396        self.count = count
397        self.allow_from_autoenv = allow_from_autoenv
OptionInfo( *, default: Optional[Any] = None, param_decls: Optional[Sequence[str]] = None, callback: Optional[Callable[..., Any]] = None, metavar: Optional[str] = None, expose_value: bool = True, is_eager: bool = False, envvar: Union[str, List[str], NoneType] = None, shell_complete: Optional[Callable[[click.core.Context, click.core.Parameter, str], Union[List[click.shell_completion.CompletionItem], List[str]]]] = None, autocompletion: Optional[Callable[..., Any]] = None, default_factory: Optional[Callable[[], Any]] = None, parser: Optional[Callable[[str], Any]] = None, click_type: Optional[click.types.ParamType] = None, show_default: Union[bool, str] = True, prompt: Union[bool, str] = False, confirmation_prompt: bool = False, prompt_required: bool = True, hide_input: bool = False, is_flag: Optional[bool] = None, flag_value: Optional[Any] = None, count: bool = False, allow_from_autoenv: bool = True, help: Optional[str] = None, hidden: bool = False, show_choices: bool = True, show_envvar: bool = True, case_sensitive: bool = True, min: Union[int, float, NoneType] = None, max: Union[int, float, NoneType] = None, clamp: bool = False, formats: Optional[List[str]] = None, mode: Optional[str] = None, encoding: Optional[str] = None, errors: Optional[str] = 'strict', lazy: Optional[bool] = None, atomic: bool = False, exists: bool = False, file_okay: bool = True, dir_okay: bool = True, writable: bool = False, readable: bool = True, resolve_path: bool = False, allow_dash: bool = False, path_type: Union[NoneType, Type[str], Type[bytes]] = None, rich_help_panel: Optional[str] = None)
274    def __init__(
275        self,
276        *,
277        # ParameterInfo
278        default: Optional[Any] = None,
279        param_decls: Optional[Sequence[str]] = None,
280        callback: Optional[Callable[..., Any]] = None,
281        metavar: Optional[str] = None,
282        expose_value: bool = True,
283        is_eager: bool = False,
284        envvar: Optional[Union[str, List[str]]] = None,
285        shell_complete: Optional[
286            Callable[
287                [click.Context, click.Parameter, str],
288                Union[List["click.shell_completion.CompletionItem"], List[str]],
289            ]
290        ] = None,
291        autocompletion: Optional[Callable[..., Any]] = None,
292        default_factory: Optional[Callable[[], Any]] = None,
293        # Custom type
294        parser: Optional[Callable[[str], Any]] = None,
295        click_type: Optional[click.ParamType] = None,
296        # Option
297        show_default: Union[bool, str] = True,
298        prompt: Union[bool, str] = False,
299        confirmation_prompt: bool = False,
300        prompt_required: bool = True,
301        hide_input: bool = False,
302        # TODO: remove is_flag and flag_value in a future release
303        is_flag: Optional[bool] = None,
304        flag_value: Optional[Any] = None,
305        count: bool = False,
306        allow_from_autoenv: bool = True,
307        help: Optional[str] = None,
308        hidden: bool = False,
309        show_choices: bool = True,
310        show_envvar: bool = True,
311        # Choice
312        case_sensitive: bool = True,
313        # Numbers
314        min: Optional[Union[int, float]] = None,
315        max: Optional[Union[int, float]] = None,
316        clamp: bool = False,
317        # DateTime
318        formats: Optional[List[str]] = None,
319        # File
320        mode: Optional[str] = None,
321        encoding: Optional[str] = None,
322        errors: Optional[str] = "strict",
323        lazy: Optional[bool] = None,
324        atomic: bool = False,
325        # Path
326        exists: bool = False,
327        file_okay: bool = True,
328        dir_okay: bool = True,
329        writable: bool = False,
330        readable: bool = True,
331        resolve_path: bool = False,
332        allow_dash: bool = False,
333        path_type: Union[None, Type[str], Type[bytes]] = None,
334        # Rich settings
335        rich_help_panel: Union[str, None] = None,
336    ):
337        super().__init__(
338            default=default,
339            param_decls=param_decls,
340            callback=callback,
341            metavar=metavar,
342            expose_value=expose_value,
343            is_eager=is_eager,
344            envvar=envvar,
345            shell_complete=shell_complete,
346            autocompletion=autocompletion,
347            default_factory=default_factory,
348            # Custom type
349            parser=parser,
350            click_type=click_type,
351            # TyperArgument
352            show_default=show_default,
353            show_choices=show_choices,
354            show_envvar=show_envvar,
355            help=help,
356            hidden=hidden,
357            # Choice
358            case_sensitive=case_sensitive,
359            # Numbers
360            min=min,
361            max=max,
362            clamp=clamp,
363            # DateTime
364            formats=formats,
365            # File
366            mode=mode,
367            encoding=encoding,
368            errors=errors,
369            lazy=lazy,
370            atomic=atomic,
371            # Path
372            exists=exists,
373            file_okay=file_okay,
374            dir_okay=dir_okay,
375            writable=writable,
376            readable=readable,
377            resolve_path=resolve_path,
378            allow_dash=allow_dash,
379            path_type=path_type,
380            # Rich settings
381            rich_help_panel=rich_help_panel,
382        )
383        if is_flag is not None or flag_value is not None:
384            import warnings
385
386            warnings.warn(
387                "The 'is_flag' and 'flag_value' parameters are not supported by Typer "
388                "and will be removed entirely in a future release.",
389                DeprecationWarning,
390                stacklevel=2,
391            )
392        self.prompt = prompt
393        self.confirmation_prompt = confirmation_prompt
394        self.prompt_required = prompt_required
395        self.hide_input = hide_input
396        self.count = count
397        self.allow_from_autoenv = allow_from_autoenv
prompt
confirmation_prompt
prompt_required
hide_input
count
allow_from_autoenv
class ArgumentInfo(ParameterInfo):
400class ArgumentInfo(ParameterInfo):
401    def __init__(
402        self,
403        *,
404        # ParameterInfo
405        default: Optional[Any] = None,
406        param_decls: Optional[Sequence[str]] = None,
407        callback: Optional[Callable[..., Any]] = None,
408        metavar: Optional[str] = None,
409        expose_value: bool = True,
410        is_eager: bool = False,
411        envvar: Optional[Union[str, List[str]]] = None,
412        shell_complete: Optional[
413            Callable[
414                [click.Context, click.Parameter, str],
415                Union[List["click.shell_completion.CompletionItem"], List[str]],
416            ]
417        ] = None,
418        autocompletion: Optional[Callable[..., Any]] = None,
419        default_factory: Optional[Callable[[], Any]] = None,
420        # Custom type
421        parser: Optional[Callable[[str], Any]] = None,
422        click_type: Optional[click.ParamType] = None,
423        # TyperArgument
424        show_default: Union[bool, str] = True,
425        show_choices: bool = True,
426        show_envvar: bool = True,
427        help: Optional[str] = None,
428        hidden: bool = False,
429        # Choice
430        case_sensitive: bool = True,
431        # Numbers
432        min: Optional[Union[int, float]] = None,
433        max: Optional[Union[int, float]] = None,
434        clamp: bool = False,
435        # DateTime
436        formats: Optional[List[str]] = None,
437        # File
438        mode: Optional[str] = None,
439        encoding: Optional[str] = None,
440        errors: Optional[str] = "strict",
441        lazy: Optional[bool] = None,
442        atomic: bool = False,
443        # Path
444        exists: bool = False,
445        file_okay: bool = True,
446        dir_okay: bool = True,
447        writable: bool = False,
448        readable: bool = True,
449        resolve_path: bool = False,
450        allow_dash: bool = False,
451        path_type: Union[None, Type[str], Type[bytes]] = None,
452        # Rich settings
453        rich_help_panel: Union[str, None] = None,
454    ):
455        super().__init__(
456            default=default,
457            param_decls=param_decls,
458            callback=callback,
459            metavar=metavar,
460            expose_value=expose_value,
461            is_eager=is_eager,
462            envvar=envvar,
463            shell_complete=shell_complete,
464            autocompletion=autocompletion,
465            default_factory=default_factory,
466            # Custom type
467            parser=parser,
468            click_type=click_type,
469            # TyperArgument
470            show_default=show_default,
471            show_choices=show_choices,
472            show_envvar=show_envvar,
473            help=help,
474            hidden=hidden,
475            # Choice
476            case_sensitive=case_sensitive,
477            # Numbers
478            min=min,
479            max=max,
480            clamp=clamp,
481            # DateTime
482            formats=formats,
483            # File
484            mode=mode,
485            encoding=encoding,
486            errors=errors,
487            lazy=lazy,
488            atomic=atomic,
489            # Path
490            exists=exists,
491            file_okay=file_okay,
492            dir_okay=dir_okay,
493            writable=writable,
494            readable=readable,
495            resolve_path=resolve_path,
496            allow_dash=allow_dash,
497            path_type=path_type,
498            # Rich settings
499            rich_help_panel=rich_help_panel,
500        )
ArgumentInfo( *, default: Optional[Any] = None, param_decls: Optional[Sequence[str]] = None, callback: Optional[Callable[..., Any]] = None, metavar: Optional[str] = None, expose_value: bool = True, is_eager: bool = False, envvar: Union[str, List[str], NoneType] = None, shell_complete: Optional[Callable[[click.core.Context, click.core.Parameter, str], Union[List[click.shell_completion.CompletionItem], List[str]]]] = None, autocompletion: Optional[Callable[..., Any]] = None, default_factory: Optional[Callable[[], Any]] = None, parser: Optional[Callable[[str], Any]] = None, click_type: Optional[click.types.ParamType] = None, show_default: Union[bool, str] = True, show_choices: bool = True, show_envvar: bool = True, help: Optional[str] = None, hidden: bool = False, case_sensitive: bool = True, min: Union[int, float, NoneType] = None, max: Union[int, float, NoneType] = None, clamp: bool = False, formats: Optional[List[str]] = None, mode: Optional[str] = None, encoding: Optional[str] = None, errors: Optional[str] = 'strict', lazy: Optional[bool] = None, atomic: bool = False, exists: bool = False, file_okay: bool = True, dir_okay: bool = True, writable: bool = False, readable: bool = True, resolve_path: bool = False, allow_dash: bool = False, path_type: Union[NoneType, Type[str], Type[bytes]] = None, rich_help_panel: Optional[str] = None)
401    def __init__(
402        self,
403        *,
404        # ParameterInfo
405        default: Optional[Any] = None,
406        param_decls: Optional[Sequence[str]] = None,
407        callback: Optional[Callable[..., Any]] = None,
408        metavar: Optional[str] = None,
409        expose_value: bool = True,
410        is_eager: bool = False,
411        envvar: Optional[Union[str, List[str]]] = None,
412        shell_complete: Optional[
413            Callable[
414                [click.Context, click.Parameter, str],
415                Union[List["click.shell_completion.CompletionItem"], List[str]],
416            ]
417        ] = None,
418        autocompletion: Optional[Callable[..., Any]] = None,
419        default_factory: Optional[Callable[[], Any]] = None,
420        # Custom type
421        parser: Optional[Callable[[str], Any]] = None,
422        click_type: Optional[click.ParamType] = None,
423        # TyperArgument
424        show_default: Union[bool, str] = True,
425        show_choices: bool = True,
426        show_envvar: bool = True,
427        help: Optional[str] = None,
428        hidden: bool = False,
429        # Choice
430        case_sensitive: bool = True,
431        # Numbers
432        min: Optional[Union[int, float]] = None,
433        max: Optional[Union[int, float]] = None,
434        clamp: bool = False,
435        # DateTime
436        formats: Optional[List[str]] = None,
437        # File
438        mode: Optional[str] = None,
439        encoding: Optional[str] = None,
440        errors: Optional[str] = "strict",
441        lazy: Optional[bool] = None,
442        atomic: bool = False,
443        # Path
444        exists: bool = False,
445        file_okay: bool = True,
446        dir_okay: bool = True,
447        writable: bool = False,
448        readable: bool = True,
449        resolve_path: bool = False,
450        allow_dash: bool = False,
451        path_type: Union[None, Type[str], Type[bytes]] = None,
452        # Rich settings
453        rich_help_panel: Union[str, None] = None,
454    ):
455        super().__init__(
456            default=default,
457            param_decls=param_decls,
458            callback=callback,
459            metavar=metavar,
460            expose_value=expose_value,
461            is_eager=is_eager,
462            envvar=envvar,
463            shell_complete=shell_complete,
464            autocompletion=autocompletion,
465            default_factory=default_factory,
466            # Custom type
467            parser=parser,
468            click_type=click_type,
469            # TyperArgument
470            show_default=show_default,
471            show_choices=show_choices,
472            show_envvar=show_envvar,
473            help=help,
474            hidden=hidden,
475            # Choice
476            case_sensitive=case_sensitive,
477            # Numbers
478            min=min,
479            max=max,
480            clamp=clamp,
481            # DateTime
482            formats=formats,
483            # File
484            mode=mode,
485            encoding=encoding,
486            errors=errors,
487            lazy=lazy,
488            atomic=atomic,
489            # Path
490            exists=exists,
491            file_okay=file_okay,
492            dir_okay=dir_okay,
493            writable=writable,
494            readable=readable,
495            resolve_path=resolve_path,
496            allow_dash=allow_dash,
497            path_type=path_type,
498            # Rich settings
499            rich_help_panel=rich_help_panel,
500        )
class ParamMeta:
503class ParamMeta:
504    empty = inspect.Parameter.empty
505
506    def __init__(
507        self,
508        *,
509        name: str,
510        default: Any = inspect.Parameter.empty,
511        annotation: Any = inspect.Parameter.empty,
512    ) -> None:
513        self.name = name
514        self.default = default
515        self.annotation = annotation
ParamMeta(*, name: str, default: Any, annotation: Any)
506    def __init__(
507        self,
508        *,
509        name: str,
510        default: Any = inspect.Parameter.empty,
511        annotation: Any = inspect.Parameter.empty,
512    ) -> None:
513        self.name = name
514        self.default = default
515        self.annotation = annotation
empty
name
default
annotation
class DeveloperExceptionConfig:
518class DeveloperExceptionConfig:
519    def __init__(
520        self,
521        *,
522        pretty_exceptions_enable: bool = True,
523        pretty_exceptions_show_locals: bool = True,
524        pretty_exceptions_short: bool = True,
525    ) -> None:
526        self.pretty_exceptions_enable = pretty_exceptions_enable
527        self.pretty_exceptions_show_locals = pretty_exceptions_show_locals
528        self.pretty_exceptions_short = pretty_exceptions_short
DeveloperExceptionConfig( *, pretty_exceptions_enable: bool = True, pretty_exceptions_show_locals: bool = True, pretty_exceptions_short: bool = True)
519    def __init__(
520        self,
521        *,
522        pretty_exceptions_enable: bool = True,
523        pretty_exceptions_show_locals: bool = True,
524        pretty_exceptions_short: bool = True,
525    ) -> None:
526        self.pretty_exceptions_enable = pretty_exceptions_enable
527        self.pretty_exceptions_show_locals = pretty_exceptions_show_locals
528        self.pretty_exceptions_short = pretty_exceptions_short
pretty_exceptions_enable
pretty_exceptions_show_locals
pretty_exceptions_short