Skip to main content

Option

A CLI Option is a parameter to your command line application that is called with a single or double dash, something like --verbose or -v.

def Option(
default: Any | None = ...,
param_decls: str,
callback: Callable[..., Any] | None = None,
metavar: str | None = None,
expose_value: bool = True,
is_eager: bool = False,
envvar: str | list[str] | None = None,
shell_complete: Callable | None = None,
autocompletion: Callable[..., Any] | None = None,
default_factory: Callable[[], Any] | None = None,
parser: Callable[[str], Any] | None = None,
click_type: click.ParamType | None = None,
show_default: bool | str = True,
prompt: bool | str = False,
confirmation_prompt: bool = False,
prompt_required: bool = True,
hide_input: bool = False,
is_flag: bool | None = None,
flag_value: Any | None = None,
count: bool = False,
allow_from_autoenv: bool = True,
help: str | None = None,
hidden: bool = False,
show_choices: bool = True,
show_envvar: bool = True,
case_sensitive: bool = True,
min: int | float | None = None,
max: int | float | None = None,
clamp: bool = False,
formats: list[str] | None = None,
mode: str | None = None,
encoding: str | None = None,
errors: str | None = "strict",
lazy: bool | None = 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: None | type[str] | type[bytes] = None,
rich_help_panel: str | None = None
) - > OptionInfo

A CLI Option is a parameter to your command line application that is called with a single or double dash, something like --verbose or -v.

Parameters

NameTypeDescription
default`AnyNone` = ...
param_declsstrOne or multiple aliases (e.g., '--user', '-u') defining how the option is called on the command line.
callback`Callable[..., Any]None` = None
metavar`strNone` = None
expose_valuebool = TrueWhether to pass the value to the command callback and store it on the context.
is_eagerbool = FalseIf True, processes this option before other parameters to handle early-exit logic like version flags.
envvar`strlist[str]
shell_complete`CallableNone` = None
autocompletion`Callable[..., Any]None` = None
default_factory`Callable[[], Any]None` = None
parser`Callable[[str], Any]None` = None
click_type`click.ParamTypeNone` = None
show_default`boolstr` = True
prompt`boolstr` = False
confirmation_promptbool = FalseWhether to ask the user to type the value twice for confirmation (e.g., for passwords).
prompt_requiredbool = TrueIf False, only prompts if the option flag is provided without an accompanying value.
hide_inputbool = FalseWhether to mask user input during a prompt, typically used for sensitive data.
is_flag`boolNone` = None
flag_value`AnyNone` = None
countbool = FalseWhether to treat the option as a counter that increments with each occurrence (e.g., -vvv).
allow_from_autoenvbool = TrueWhether to allow pulling values from environment variables based on a context prefix.
help`strNone` = None
hiddenbool = FalseWhether to hide this option from the help output entirely.
show_choicesbool = TrueWhether to display valid Enum choices inline during an interactive prompt.
show_envvarbool = TrueWhether to display the associated environment variable name in the help text.
case_sensitivebool = TrueWhether Enum choice matching should respect character casing.
min`intfloat
max`intfloat
clampbool = FalseWhether to force out-of-bounds numeric input to the nearest min/max boundary instead of erroring.
formats`list[str]None` = None
mode`strNone` = None
encoding`strNone` = None
errors`strNone` = "strict"
lazy`boolNone` = None
atomicbool = FalseWhether to perform file writes using a temporary file to ensure atomic updates.
existsbool = FalseWhether to validate that the provided Path exists on the filesystem.
file_okaybool = TrueWhether the Path is allowed to be a file.
dir_okaybool = TrueWhether the Path is allowed to be a directory.
writablebool = FalseWhether to check if the Path is writable by the current user.
readablebool = TrueWhether to check if the Path is readable by the current user.
resolve_pathbool = FalseWhether to convert the Path to an absolute path and resolve all symlinks.
allow_dashbool = FalseWhether to allow '-' as a path value to represent stdin/stdout.
path_type`Nonetype[str]
rich_help_panel`strNone` = None

Returns

TypeDescription
OptionInfoAn object containing the configuration metadata for a Typer CLI option.