Griffe Pydantic

raw JSON →
1.3.1 verified Mon Apr 27 auth: no python

Griffe extension that extracts Pydantic models, fields, validators, and configurations from Python source code for documentation generation. Current version: 1.3.1. Released under MIT license with regular updates.

pip install griffe-pydantic
error ModuleNotFoundError: No module named 'griffe'
cause griffe-pydantic 1.3.0+ requires griffelib, not griffe.
fix
pip install griffelib
error AttributeError: module 'griffe_pydantic' has no attribute 'GriffePydanticExtension'
cause Importing incorrectly, e.g., from griffe_pydantic import griffe_pydantic.
fix
from griffe_pydantic import GriffePydanticExtension
breaking As of griffe-pydantic 1.3.0, the dependency changed from 'griffe' to 'griffelib' (griffe 1.x). Existing installations must be updated to use griffelib.
fix pip install griffelib; ensure griffe-pydantic>=1.3.0 and griffelib (not griffe) are installed.
deprecated The logger name was changed to 'griffe_pydantic' in 1.1.5; the old logger name may still work but is deprecated.
fix Use the logger named 'griffe_pydantic' instead.
gotcha Properties in Pydantic models are not processed as fields (since 1.1.4). If you rely on properties being documented as fields, update your model design or use @property explicitly for other behavior.
fix Use Field() or class attributes for fields; do not expect @property to be treated as a model field.

Load a package and extract Pydantic models with the extension.

import griffe
from griffe_pydantic import GriffePydanticExtension

ext = GriffePydanticExtension()
loader = griffe.load('my_package', extensions=[ext])
for model in loader.modules['my_package'].classes:
    print(model.name, model.lines)