Configuration

One major strength of autodoc_pydantic is that every feature is completely configurable to allow maximum customization. There are two ways to configure how pydantic objects are displayed:

  • conf.py: Globally define the default configuration via conf.py which takes effect for all pydantic objects like:

    autodoc_pydantic_model_show_json = True
    autodoc_pydantic_model_show_config = False
    
  • directive: Locally define specific configurations via directive options. This overrides global configuration settings:

    .. autopydantic_model:: module.Model
       :model-show-json: True
       :model-show-config: False
    

Note

The following sections describe all available configurations in separation. Each configuration is activated in isolation while the remaining are disabled to highlight actual difference.

BaseModel

Contains all modifications for pydantic BaseModel.

Show Config Summary

Show model config summary within the class doc string. It may be meaningful when the class configuration carries some relevant information and you don’t want to show the entire config class as an explicit member (see model-show-config-member).

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_model_show_config_summary

directive

model-show-config-summary

Available values with rendered examples

class ModelShowConfigSummary[source]

ModelShowConfigSummary.

Config
  • allow_mutation: bool = True

  • title: str = FooBar

Show Config Member

Show pydantic config class. It can be hidden if it is irrelevant or if replaced with model-show-config-summary.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_model_show_config_member

directive

model-show-config-member

Available values with rendered examples

class ModelShowConfigMember(*, field: int = 1)[source]

ModelShowConfigMember.

class Config[source]

Config.

allow_mutation = True
attribute field: int

Field.

Show Validator Summary

Show all validators along with corresponding fields within the class doc string. Hyperlinks are automatically created for validators and fields. This is especially useful when dealing with large models having a lot of validators. Please note, the sort order of summary items can be configured via model-summary-list-order.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_model_show_validator_summary

directive

model-show-validator-summary

Available values with rendered examples

class ModelShowValidatorsSummary(*, field: int = 1)[source]

ModelShowValidatorsSummary.

Validators
  • check » field

Show Validator Members

Show pydantic validator methods. They can be hidden if they are irrelevant.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_model_show_validator_members

directive

model-show-validator-members

Available values with rendered examples

class ModelShowValidatorMembers(*, field: int = 1)[source]

ModelShowValidatorMembers.

classmethod dummy(v) str[source]

Check.

attribute field: int

Field.

Show Field Summary

Show all fields within the class doc string. Hyperlinks are automatically created. This is especially useful when dealing with large models having a lot of fields. Please note, the sort order of summary items can be configured via model-summary-list-order.

Configuration (added in version 1.2.0)

conf.py

autodoc_pydantic_model_show_field_summary

directive

model-show-field-summary

Available values with rendered examples

class ModelShowFieldSummary(*, field1: int = 5, field2: str = 'FooBar')[source]

ModelShowFieldSummary.

Fields
  • field1 (int)

  • field2 (str)

Summary List Order

Define the sort order within validator and field summaries (which can be activated via model-show-validator-summary and model-show-field-summary, respectively).

Configuration (added in version 1.5.0)

conf.py

autodoc_pydantic_model_summary_list_order

directive

model-summary-list-order

Available values with rendered examples

class ModelSummaryListOrder(*, field_b: int = 1, field_a: int = 1)[source]

ModelSummaryListOrder.

Fields
  • field_a (int)

  • field_b (int)

Validators
  • validate_a » field_a

  • validate_b » field_b

Show Undoc Members

Show undocumented members. By default, undocumented members are hidden for standard auto directives. For pydantic models, this is overwritten if enabled.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_model_undoc_members

directive

undoc-members

Available values with rendered examples

class ModelUndocMembers(*, field1: int = 5, field2: str = 'FooBar')[source]

ModelUndocMembers.

attribute field1: int
attribute field2: str

Note

In order to show any members at all, you need to enable autodoc_pydantic_model_members or set :members:.

Show Members

Show members. By default, members are hidden for standard auto directives. For pydantic models, this is overwritten if enabled.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_model_members

directive

members

Available values with rendered examples

class ModelMembers(*, field1: int = 5, field2: str = 'FooBar')[source]

ModelMembers.

attribute field1: int

Doc field 1

attribute field2: str

Doc field 2

Member Order

Order members groupwise by default in the following order: fields, validators and config.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_model_member_order

directive

member-order

Available values with rendered examples

class ModelMemberOrder(*, field: int = 1)[source]

ModelMemberOrder.

attribute field: int

Field.

classmethod dummy(v) str[source]

Check.

class Config[source]

Config.

allow_mutation = True

Hide ParamList

Hide parameter list within class signature which usually becomes rather overloaded once a lot fields are present. Additionally, it is redundant since fields are documented anyway.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_model_hide_paramlist

directive

model-hide-paramlist

Available values with rendered examples

class ModelHideParamList[source]

ModelHideParamList.

Signature Prefix

Define the signature prefix for pydantic models.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_model_signature_prefix

directive

model-signature-prefix

Available values with rendered examples

pydantic model ModelSignaturePrefix[source]

ModelSignaturePrefix.

Show Schema JSON

Show the schema json representation of a pydantic model within in the class doc string as a collapsable code block.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_model_show_json

directive

model-show-json

Available values with rendered examples

class ModelShowJson[source]

ModelShowJson.

Show JSON schema
{
   "title": "ModelShowJson",
   "description": "ModelShowJson.",
   "type": "object",
   "properties": {}
}

Warning

Fields containing custom objects may not be JSON serializable. This will break the schema generation by default. However, it can be handled via Show Schema JSON Error Strategy.

Show Schema JSON Error Strategy

Define error handling in case a pydantic field breaks pydantic model schema generation. This occurs if a pydantic field is not JSON serializable.

Configuration (added in version 1.4.0)

conf.py

autodoc_pydantic_model_show_json_error_strategy

directive_option

model-show-json-error-strategy

Available values:

  • coerce: Keep violating fields in resulting schema but only show the title. Do not provide a warning during doc building process.

  • warn (default): Keep violating fields in resulting schema but only show the title. Provide a warning during the doc building process.

  • raise: Raises an sphinx.errors.ExtensionError during building process.

BaseSettings

Contains all modifications for pydantic BaseSettings.

Show Config Summary

Show model config summary within the class doc string. It may be meaningful when the class configuration carries some relevant information and you don’t want to show the entire config class as an explicit member (see settings-show-config-member).

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_settings_show_config_summary

directive

settings-show-config-summary

Available values with rendered examples

class SettingsShowConfigSummary(_env_file: Optional[Union[pathlib.Path, str]] = '<object object>', _env_file_encoding: Optional[str] = None, _secrets_dir: Optional[Union[pathlib.Path, str]] = None)[source]

SettingsShowConfigSummary.

Config
  • allow_mutation: bool = True

  • title: str = FooBar

Show Config Member

Show pydantic config class. It can be hidden if it is irrelevant or if replaced with settings-show-config-summary.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_settings_show_config_member

directive

settings-show-config-member

Available values with rendered examples

class SettingsShowConfigMember(_env_file: Optional[Union[pathlib.Path, str]] = '<object object>', _env_file_encoding: Optional[str] = None, _secrets_dir: Optional[Union[pathlib.Path, str]] = None, *, field: int = 1)[source]

SettingsShowConfigMember.

class Config[source]

Config.

allow_mutation = True
attribute field: int

Field.

Show Validator Summary

Show all validators along with corresponding fields within the class doc string. Hyperlinks are automatically created for validators and fields. This is especially useful when dealing with large models having a lot of validators. Please note, the sort order of summary items can be configured via settings-summary-list-order.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_settings_show_validator_summary

directive

settings-show-validator-summary

Available values with rendered examples

class SettingsShowValidatorsSummary(_env_file: Optional[Union[pathlib.Path, str]] = '<object object>', _env_file_encoding: Optional[str] = None, _secrets_dir: Optional[Union[pathlib.Path, str]] = None, *, field: int = 1)[source]

SettingsShowValidatorsSummary.

Validators
  • check » field

Show Validator Members

Show pydantic validator methods. They can be hidden if they are irrelevant.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_settings_show_validator_members

directive

settings-show-validator-members

Available values with rendered examples

class SettingsShowValidatorMembers(_env_file: Optional[Union[pathlib.Path, str]] = '<object object>', _env_file_encoding: Optional[str] = None, _secrets_dir: Optional[Union[pathlib.Path, str]] = None, *, field: int = 1)[source]

SettingsShowValidatorMembers.

classmethod dummy(v) str[source]

Check.

attribute field: int

Field.

Show Field Summary

Show all fields within the class doc string. Hyperlinks are automatically created. This is especially useful when dealing with large models having a lot of fields. Please note, the sort order of summary items can be configured via settings-summary-list-order.

Configuration (added in version 1.2.0)

conf.py

autodoc_pydantic_settings_show_field_summary

directive

settings-show-field-summary

Available values with rendered examples

class SettingsShowFieldSummary(_env_file: Optional[Union[pathlib.Path, str]] = '<object object>', _env_file_encoding: Optional[str] = None, _secrets_dir: Optional[Union[pathlib.Path, str]] = None, *, field1: int = 5, field2: str = 'FooBar')[source]

SettingsShowFieldSummary.

Fields
  • field1 (int)

  • field2 (str)

attribute field1: int

Field1.

attribute field2: str

Field2.

Summary List Order

Define the sort order within validator and field summaries (which can be activated via settings-show-validator-summary and settings-show-field-summary, respectively).

Configuration (added in version 1.5.0)

conf.py

autodoc_pydantic_settings_summary_list_order

directive

settings-summary-list-order

Available values with rendered examples

class SettingsSummaryListOrder(_env_file: Optional[Union[pathlib.Path, str]] = '<object object>', _env_file_encoding: Optional[str] = None, _secrets_dir: Optional[Union[pathlib.Path, str]] = None, *, field_b: int = 1, field_a: int = 1)[source]

SettingsSummaryListOrder.

Fields
  • field_a (int)

  • field_b (int)

Validators
  • validate_a » field_a

  • validate_b » field_b

Show Undoc Members

Show undocumented members. By default, undocumented members are hidden for standard auto directives. For pydantic settings, this is overwritten if enabled.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_settings_undoc_members

directive

undoc-members

Available values with rendered examples

class SettingsUndocMembers(_env_file: Optional[Union[pathlib.Path, str]] = '<object object>', _env_file_encoding: Optional[str] = None, _secrets_dir: Optional[Union[pathlib.Path, str]] = None, *, field1: int = 5, field2: str = 'FooBar')[source]

SettingsUndocMembers.

attribute field1: int
attribute field2: str

Note

In order to show any members at all, you need to enable autodoc_pydantic_settings_members or set :members:.

Show Members

Show members. By default, members are hidden for standard auto directives. For pydantic settingss, this is overwritten if enabled.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_settings_members

directive

members

Available values with rendered examples

class SettingsMembers(_env_file: Optional[Union[pathlib.Path, str]] = '<object object>', _env_file_encoding: Optional[str] = None, _secrets_dir: Optional[Union[pathlib.Path, str]] = None, *, field1: int = 5, field2: str = 'FooBar')[source]

SettingsMembers.

attribute field1: int

Doc field 1

attribute field2: str

Doc field 2

Member Order

Order members groupwise by default in the following order: fields, validators and config.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_settings_member_order

directive

member-order

Available values with rendered examples

class SettingsMemberOrder(_env_file: Optional[Union[pathlib.Path, str]] = '<object object>', _env_file_encoding: Optional[str] = None, _secrets_dir: Optional[Union[pathlib.Path, str]] = None, *, field: int = 1)[source]

SettingsMemberOrder.

attribute field: int

Field.

classmethod dummy(v) str[source]

Check.

class Config[source]

Config.

allow_mutation = True

Hide ParamList

Hide parameter list within class signature which usually becomes rather overloaded once a lot fields are present. Additionally, it is redundant since fields are documented anyway.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_settings_hide_paramlist

directive

settings-hide-paramlist

Available values with rendered examples

class SettingsHideParamList[source]

SettingsHideParamList.

Signature Prefix

Define the signature prefix for pydantic settings.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_settings_signature_prefix

directive

settings-signature-prefix

Available values with rendered examples

pydantic settings SettingsSignaturePrefix(_env_file: Optional[Union[pathlib.Path, str]] = '<object object>', _env_file_encoding: Optional[str] = None, _secrets_dir: Optional[Union[pathlib.Path, str]] = None)[source]

SettingsSignaturePrefix.

Show Schema JSON

Show the schema json representation of pydantic settings within in the class doc string as a collapsable code block.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_settings_show_json

directive

settings-show-json

Available values with rendered examples

class SettingsShowJson(_env_file: Optional[Union[pathlib.Path, str]] = '<object object>', _env_file_encoding: Optional[str] = None, _secrets_dir: Optional[Union[pathlib.Path, str]] = None)[source]

SettingsShowJson.

Show JSON schema
{
   "title": "SettingsShowJson",
   "description": "SettingsShowJson.",
   "type": "object",
   "properties": {},
   "additionalProperties": false
}

Warning

Fields containing custom objects may not be JSON serializable. This will break the schema generation by default. However, it can be handled via Show Schema JSON Error Strategy.

Show Schema JSON Error Strategy

Define error handling in case a pydantic field breaks pydantic settings schema generation. This occurs if a pydantic field is not JSON serializable.

Configuration (added in version 1.4.0)

conf.py

autodoc_pydantic_settings_show_json_error_strategy

directive_option

settings-show-json-error-strategy

Available values:

  • coerce: Keep violating fields in resulting schema but only show the title. Do not provide a warning during doc building process.

  • warn (default): Keep violating fields in resulting schema but only show the title. Provide a warning during the doc building process.

  • raise: Raises an sphinx.errors.ExtensionError during building process.

Fields

List Validators

List all linked validators within doc string that process the current field. Hyperlinks to corresponding validators are automatically provided.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_field_list_validators

directive

field-list-validators

Available values with rendered examples

class FieldListValidators(*, field: int = 1)[source]

FieldListValidators.

classmethod check(v) str[source]

Check.

attribute field: int

Field.

Validated by
  • check

Docstring Policy

Define what content is displayed in the main field docstring. The following values are possible:

  • docstring shows the exact docstring of the python attribute.

  • description displays the information provided via the pydantic field’s description.

  • both will output the attribute’s docstring together with the pydantic field’s description.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_field_doc_policy

directive

field-doc-policy

Available values with rendered examples

class FieldDocPolicy(*, field: int = 1)[source]

FieldDocPolicy.

attribute field: int

Field.

Show Constraints

Displays all constraints that are associated with the given pydantic field.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_field_show_constraints

directive

field-show-constraints

Available values with rendered examples

class FieldShowConstraints(*, field: target.configuration.ConstrainedIntValue = 1)[source]

FieldShowConstraints.

attribute field: int

Field.

Constraints
  • minimum = 0

  • maximum = 100

Show Alias

Provides the pydantic field’s alias in the signature.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_field_show_alias

directive

field-show-alias

Available values with rendered examples

class FieldShowAlias(*, field2: int = 1)[source]

FieldShowConstraints.

attribute field: int (alias 'field2')

Field.

Show Default Value

Provides the pydantic field’s default value in the signature. Unfortunately this is not provided by standard sphinx autodoc (as of version 4.1.2).

Configuration (added in version 1.4.0)

conf.py

autodoc_pydantic_field_show_default

directive

field-show-default

Available values with rendered examples

class FieldShowDefault(*, field: int = 1)[source]

FieldShowDefault.

attribute field: int = 1

Field.

Show Required

Add [Required] marker for all pydantic fields that do not have a default value. Otherwise, misleading default values like PydanticUndefined or Ellipsis are displayed when field-show-default is enabled.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_field_show_required

directive

field-show-required

Available values with rendered examples

class FieldShowRequired(*, field1: int, field2: int, field3: int)[source]

FieldShowRequired.

attribute field1: int [Required]

field1

attribute field2: int [Required]

field2

attribute field3: int [Required]

field3

Signature Prefix

Define the signature prefix for pydantic field.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_field_signature_prefix

directive

field-signature-prefix

Available values with rendered examples

class FieldSignaturePrefix(*, field: int = 1)[source]

FieldSignaturePrefix.

field field: int

Field.

Validators

Replace Signature

Replaces the validator signature with custom links to corresponding fields. Pydantic validator signatures usually do not carry important information and hence may be replaced. However, you may want to keep the signature patterns constant across methods. In this scenario, you may list the associated fields within the doc string via validator-list-fields.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_validator_replace_signature

directive

validator-replace-signature

Available values with rendered examples

class ValidatorReplaceSignature(*, field: int = 1)[source]

ValidatorReplaceSignature.

classmethod check  »  field[source]

Check.

attribute field: int

List Fields

List all fields that are processed by current validator. This provides the same information as validator-replace-signature, however it does not change the signature but adds the links in the doc string.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_validator_list_fields

directive

validator-list-fields

Available values with rendered examples

class ValidatorListFields(*, field: int = 1)[source]

ValidatorListFields.

classmethod check(v) str[source]

Check.

Validates
  • field

attribute field: int

Signature Prefix

Define the signature prefix for pydantic validator.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_validator_signature_prefix

directive

validator-signature-prefix

Available values with rendered examples

class ValidatorSignaturePrefix(*, field: int = 1)[source]

ValidatorSignaturePrefix.

validator check(v) str[source]

Check.

attribute field: int

Config Class

Show Members

Show members. By default, members are hidden for standard auto directives. For pydantic class config, this is overwritten if enabled.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_config_members

directive

members

Available values with rendered examples

class ConfigMembers[source]

ConfigUndocMembers.

class Config[source]
allow_mutation = True

Allow Mutation.

title = 'foobar'

Note

By default, all undocumented members are shown for the Config class. The directive option :undoc-members: is added automatically.

Signature Prefix

Define the signature prefix for config class.

Configuration (added in version 0.1.0)

conf.py

autodoc_pydantic_config_signature_prefix

directive

config-signature-prefix

Available values with rendered examples

model Config

Config.