API Reference
from_pydantic ¶
from_pydantic(
__var_or_model: Union[str, type[BaseModel]],
model: Optional[type[BaseModel]] = None,
*,
exclude: Sequence[str] = (),
rename: Optional[dict[str, str]] = None,
shorten: Optional[dict[str, str]] = None,
prefix: Optional[str] = None,
parse_docstring: bool = True,
docstring_style: Literal[
"google", "numpy", "sphinx"
] = "google",
extra_options: Optional[
dict[str, _ParameterKwargs]
] = None,
ignore_unsupported: Optional[bool] = False,
unpack_list: bool = False
) -> Callable[[Callable[..., T]], Callable[..., T]]
Decorator to add fields from a Pydantic model as options to a Click command.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__var_or_model
|
Union[str, type[BaseModel]]
|
name of the variable that will receive the Pydantic model in the decorated function |
required |
model
|
Optional[type[BaseModel]]
|
Pydantic model |
None
|
exclude
|
Sequence[str]
|
field names that won't be added to the command |
()
|
rename
|
Optional[dict[str, str]]
|
a mapping from field names to command line option names (this will override any prefix). Option names must start with two dashes |
None
|
shorten
|
Optional[dict[str, str]]
|
a mapping from field names to short command line option names. Option names must start with one dash |
None
|
prefix
|
Optional[str]
|
a prefix to add to option names (without any dash) |
None
|
parse_docstring
|
bool
|
if True and |
True
|
docstring_style
|
Literal['google', 'numpy', 'sphinx']
|
style of the docstring ( |
'google'
|
extra_options
|
Optional[dict[str, _ParameterKwargs]]
|
a mapping from field names to a dictionary of options passed to the |
None
|
ignore_unsupported
|
Optional[bool]
|
ignore unsupported model fields instead of raising |
False
|
unpack_list
|
bool
|
if True, a list of nested models (e.g. |
False
|
Returns:
Type | Description |
---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
a decorator that adds options to a function |
options: show_root_heading: false show_root_members_full_path: true show_root_full_path: true