autodoc_pydantic
You love pydantic ❤️ and you want to document your models and configuration settings with sphinx?
Perfect, let's go. But wait, sphinx' autodoc does not integrate too well with pydantic models 😕.
Don't worry - just pip install autodoc_pydantic ☺️.
Features
- 💬 provides default values, alias and constraints for model fields
- 🔗 adds references between validators and corresponding fields
- 📃 includes collapsable model json schema
- 🏄 natively integrates with autodoc extension
- 📎 defines explicit pydantic prefixes for models, settings, fields, validators and model config
- 📋 shows summary section for model configuration and validators
- 👀 hides overloaded and redundant model class signature
- 📚 sorts fields, validators and model config within models by type
- 🍀 Supports
pydantic >= 1.0.0andsphinx >= 3.4.0
All of these addons are completely configurable.
Installation
-
Install via
pip install autodoc_pydantic -
Add
'sphinxcontrib.autodoc_pydantic'to theextensionslist inconf.py:extensions = ['sphinxcontrib.autodoc_pydantic']
-
Configure
autodoc_pydanticinconf.py:autodoc_pydantic_field_show_constraints = True autodoc_pydantic_model_show_schema = True
Usage
The standard automodule directive already understands pydantic models that it encounters by default. No more tweaks are required.
.. automodule:: package.module
:members:
Additionally, autodoc_pydantic provides specific directives for models, settings, fields, validators and class config:
.. autopydantic_model:: package.module.MyModel
:members:
.. autopydantic_settings:: package.module.MySettings
:members:
.. autopydantic_field:: package.module.MyModel.foobar
.. autopydantic_validator:: package.module.MyModel.validator
.. autopydantic_class_config:: package.module.MyModel.Config
:members:
Configuration
General
autodoc_pydantic_show_config= True: By default documentConfigclass as class members. If False, hides it completely.autodoc_pydantic_show_validators= True: By default document pydantic validators as class members. If False, hides it completely.
Models / Settings
autodoc_pydantic_model_show_schema= True: By default, adds collapsable section including formatted model json schema.autodoc_pydantic_model_show_config= True: By default, adds model configuration settings to model doc string.autodoc_pydantic_model_show_validators= True: By default, adds validator -> field mappings to model doc string.autodoc_pydantic_model_show_paramlist= False: By default, hides overloaded and redundant parameter list from model signature.autodoc_pydantic_model_member_order= 'groupwise': By default, sorts model members by type to group fields, validators and class config members.
Fields
autodoc_pydantic_field_list_validators= True: By default, lists all validators processing corresponding field.autodoc_pydantic_field_doc_policy= 'both': By default, show doc string and and field description. If 'description', show field description only. If 'docstring', show doc string only.autodoc_pydantic_field_show_constraints= True: By default, show field constraints (e.g. minimum, maximum etc.).autodoc_pydantic_field_show_alias= True: By default, show field alias in signature.
Validators
autodoc_pydantic_validator_show_paramlist= False: By default, hides meaningless parameter list from validators.autodoc_pydantic_validator_replace_retann= True: By default, replaces validators' return annotation with references to processed fields.autodoc_pydantic_validator_list_fields= True: By default, adds list of references to validators' doc string.
Metadata
Release files for autodoc_pydantic 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| autodoc_pydantic-0.1.1.tar.gz | 9.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autodoc_pydantic-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.3 kB
Release files / autodoc_pydantic-0.1.1.tar.gz
| Download URL | autodoc_pydantic-0.1.1.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01088ac1a97d95d5e5306ae147bb76288b1235dccb27fe22d74910a331cc64fe
|
|
BLAKE2b-256 checksum How to use checksums |
995e7118632f20bc9501404100c0ff1ab8297d825631edc53aaebbd518bc62b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.0 CPython/3.9.2 Linux/5.4.0-1043-azure
|
Release files / autodoc_pydantic-0.1.1-py3-none-any.whl
| Download URL | autodoc_pydantic-0.1.1-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d4daf9d2adfef2c3dd8735503ad4bafe15ea8b21c60e12401db274411cf9e8cb
|
|
BLAKE2b-256 checksum How to use checksums |
d9b8d51c33e7486fe5ae86d57bc230947ac5035802c75da6402e051d40a67afe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.0 CPython/3.9.2 Linux/5.4.0-1043-azure
|