sphinxcontrib-pydantic
A Sphinx extension for documenting Pydantic models in your documentation.
This project was inspired by autodoc_pydantic,
which I have been using for years but has gone unmaintained and is now incompatible
with Sphinx 9.0+. Unlike its predecessor, sphinxcontrib-pydantic focuses
exclusively on modern versions: Pydantic v2+ and Sphinx 9.0+ (Python 3.11+).
This project was vibe-coded using Claude Code (Opus 4.5); using autodoc_pydantic as
inspiration as well as the source code of sphinx and pydantic as documentation.
Installation
pip install sphinxcontrib-pydantic
Configuration
Enable the extension in your conf.py:
extensions = [
"sphinx.ext.autodoc",
"sphinxcontrib.pydantic",
]
Usage
With autodoc
The extension integrates with sphinx.ext.autodoc. Simply use automodule or
autoclass:
.. automodule:: mypackage.models
:members:
Pydantic models are automatically detected and documented with field summaries and validators.
With autosummary
For larger projects, use autosummary with a custom template:
.. currentmodule:: mypackage.models
.. autosummary::
:toctree: generated/api
:template: autosummary/models.rst
UserConfig
DatabaseConfig
Create _templates/autosummary/models.rst:
{{ fullname | escape | underline }}
.. currentmodule:: {{ module }}
.. pydantic-model:: {{ fullname }}
:inherited-members: BaseModel
Standalone directives
Document models directly with the pydantic-model directive:
.. pydantic-model:: mypackage.models.UserConfig
:show-field-summary:
:show-validator-summary:
For Pydantic settings:
.. pydantic-settings:: mypackage.settings.AppSettings
:show-field-summary:
Configuration Options
All options use the sphinxcontrib_pydantic_ prefix in conf.py, e.g.
sphinxcontrib_pydantic_model_show_json.
Model Options
| Option | Default | Description |
|---|---|---|
model_show_json |
False |
Show JSON schema for the model |
model_show_field_summary |
True |
Show summary table of fields |
model_show_validator_summary |
True |
Show summary table of validators |
model_show_members |
True |
Show individual field/validator documentation (directives only) |
model_signature_prefix |
"model" |
Prefix shown before model name (directives only) |
model_hide_paramlist |
True |
Hide __init__ parameter list |
Note: The
signature_prefixandshow_membersoptions only affect directive-based documentation (pydantic-model,pydantic-settings). When using autodoc (autoclass,automodule), the standard "class" prefix is used and members are documented via autodoc's member processing.
Field Options
| Option | Default | Description |
|---|---|---|
field_show_alias |
True |
Show field aliases |
field_show_default |
True |
Show default values |
field_show_required |
True |
Show required status |
field_show_constraints |
True |
Show field constraints (e.g., min_length) |
Validator Options
| Option | Default | Description |
|---|---|---|
validator_list_fields |
True |
List fields affected by each validator |
Settings Options
Settings options mirror model options with settings_ prefix (e.g.,
sphinxcontrib_pydantic_settings_show_json). They default to the same values as their
model counterparts.
| Option | Default | Description |
|---|---|---|
settings_show_json |
False |
Show JSON schema for the setting |
settings_show_field_summary |
True |
Show summary table of fields |
settings_show_validator_summary |
True |
Show summary table of validators |
settings_show_members |
True |
Show individual field/validator documentation (directives only) |
settings_signature_prefix |
"settings" |
Prefix shown before setting name (directives only) |
settings_hide_paramlist |
True |
Hide __init__ parameter list |
Interoperability Options
| Option | Default | Description |
|---|---|---|
resolve_legacy_inventories |
False |
Resolve cross-references into objects.inv files produced by the legacy autodoc_pydantic extension |
autodoc_pydantic documents Pydantic objects under custom Python-domain object
types (py:pydantic_model, py:pydantic_field, ...) rather than the stock
py:class. A project built with this extension does not know those object types,
so a cross-reference (e.g. via intersphinx) into a project still documented with
autodoc_pydantic cannot resolve and a nitpicky build fails. Enable this option
to register those object types (object types only, no directives) so such
references resolve:
# conf.py
extensions = ["sphinx.ext.intersphinx", "sphinxcontrib.pydantic"]
intersphinx_mapping = {"legacy": ("https://legacy.example/docs/", None)}
sphinxcontrib_pydantic_resolve_legacy_inventories = True
Example Configuration
# conf.py
sphinxcontrib_pydantic_model_show_json = True
sphinxcontrib_pydantic_model_show_field_summary = True
sphinxcontrib_pydantic_field_show_constraints = True
sphinxcontrib_pydantic_settings_signature_prefix = "config"
Metadata
Release files for sphinxcontrib-pydantic 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sphinxcontrib_pydantic-0.4.0.tar.gz | 204.0 kB | Without provenance | Details for sphinxcontrib_pydantic-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sphinxcontrib_pydantic-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for sphinxcontrib_pydantic-0.4.0-py3-none-any.whl |
Total release size: 238.5 kB
Release files / sphinxcontrib_pydantic-0.4.0.tar.gz
| Download URL | sphinxcontrib_pydantic-0.4.0.tar.gz |
|---|---|
| Size | 204.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4d717b6327dd030e9803efeb348cbc084ac4b2c54d007bd2cb4936b21180db34
|
|
BLAKE2b-256 checksum How to use checksums |
031b2b610e271a0a32a6cfb07b395220038d771871d1f98cd292d2a4ce1e2112
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / sphinxcontrib_pydantic-0.4.0-py3-none-any.whl
| Download URL | sphinxcontrib_pydantic-0.4.0-py3-none-any.whl |
|---|---|
| Size | 34.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
557d4b44f5df4b0d99c3ea47c826e6da3d519f57115405b51a9921c4d4ccbda2
|
|
BLAKE2b-256 checksum How to use checksums |
df45fdee30bf797ac39143f15f86d677601d5897a4b1f63d8ebd0af6bc1f86ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for sphinxcontrib-pydantic 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.