A simple integration between autodoc and Pydantic in your Sphinx documentation.
Project description
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 |
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"
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinxcontrib_pydantic-0.3.0.tar.gz.
File metadata
- Download URL: sphinxcontrib_pydantic-0.3.0.tar.gz
- Upload date:
- Size: 199.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f55d7dfd48b5b58f7a78f22eae5a4ad557f9ee588fa3a2dd0f906f3677f276f
|
|
| MD5 |
3f9b8c0e2616f41492003b02ec4d5904
|
|
| BLAKE2b-256 |
f2b09b82524553b93b22cfcea0fc60fe013a6d4e72fbc8f151149898761fa7f4
|
File details
Details for the file sphinxcontrib_pydantic-0.3.0-py3-none-any.whl.
File metadata
- Download URL: sphinxcontrib_pydantic-0.3.0-py3-none-any.whl
- Upload date:
- Size: 32.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68831ed9f2013a2270a4445b743b5fbcf042abfa1e7b45539d74cd96de4a2ba8
|
|
| MD5 |
e088ca8c60cc47e082b7c34e4ecf779d
|
|
| BLAKE2b-256 |
76852ca2c74b79e72a798ebb3e857ba3bf66f20f0d4e1093df0a8f30f065572f
|