Skip to content

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
) -> 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 griffe is installed, parse the docstring of the Pydantic model and pass argument documentation to the Click help option

True
docstring_style Literal['google', 'numpy', 'sphinx']

style of the docstring (google, numpy or sphinx). Ignored if parse_docstring is False

'google'
extra_options Optional[Dict[str, _ParameterKwargs]]

a mapping from field names to a dictionary of options passed to the click.option() function

None

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