While the configuration
documentation contains all available options in detail, this page shows them in conjunction to provide different examples on how to display pydantic models and settings.
This example shows the default out-of-the-box configuration of autodoc_pydantic. In contrast, it also shows how standard sphinx autodoc displays the same example code.
rendered output pydantic
rendered output sphinx
python
target.example_setting
reST
.. autopydantic_settings:: target.example_setting.ExampleSettings
This example represents a rendered output for which all features are enabled. It deviates from the default configuration above because it contains redundant information which is most likely not required. However, for demonstration purposes, this scenario covers all available display options for pydantic models/settings.
rendered output
reST
.. autopydantic_settings:: target.example_setting.ExampleSettings
:noindex:
:settings-show-config-member: True
:validator-list-fields: True
python
target.example_setting
In this scenario everything is hidden except actual pydantic fields. Validators and model/setting config is hidden.
rendered output
reST
.. autopydantic_settings:: target.example_setting.ExampleSettings
:settings-show-json: False
:settings-show-config-member: False
:settings-show-config-summary: False
:settings-show-validator-members: False
:settings-show-validator-summary: False
:field-list-validators: False
python
target.example_setting
This example highlights how asterisk (@validator('*')
) and root validators (@root_validator
) are represented. Since they validate all fields, their corresponding field reference is replaced with a simple all fields
marker which hyperlinks to the related model itself.
rendered output
reST
.. autopydantic_model:: target.example_validators.ExampleValidators
python
target.example_validators
Note
By default the function signature of validators is replaced with hyperlinks to validated fields by autodoc_pydantic. You can disable this behaviour via validator-replace-signature <autodoc_pydantic_validator_replace_signature>
.