erdantic is a simple tool for drawing entity relationship diagrams (ERDs) for Python data model classes. Diagrams are rendered using the venerable Graphviz library. Supported data modeling frameworks are:
- Pydantic V1
- dataclasses from the Python standard library
Features include a convenient CLI, automatic native rendering in Jupyter notebooks, and easy extensibility to other data modeling frameworks. Docstrings are even accessible as tooltips for SVG outputs. Great for adding a simple and clean data model reference to your documentation.
erdantic's graph modeling depends on pygraphviz and Graphviz, an open-source C library.
PyGraphviz can tend to be difficult to install due to the dependence on Graphviz, so please consult the installation instructions for help.
If Graphviz
is installed on MacOS via Homebrew, install PyGraphviz
via:
brew install graphviz
pip install --use-pep517 \
--config-setting="--global-option=build_ext" \
--config-setting="--build-option=-I$(brew --prefix graphviz)/include/" \
--config-setting="--build-option=-L$(brew --prefix graphviz)/lib/" \
pygraphviz
When installing via pip, just call:
pip install git+https://github.com/christophertubbs/erdantic.git
The fastest way to produce a diagram like the above example is to use the erdantic CLI. Simply specify the full dotted path to your data model class and an output path. The rendered format is interpreted from the filename extension.
erdantic erdantic.examples.pydantic.Party -o diagram.png
You can also import the erdantic Python library and use its functions.
import erdantic as erd
from erdantic.examples.pydantic import Party
# Easy one-liner
erd.draw(Party, out="diagram.png")
# Or create a diagram object that you can inspect and do stuff with
diagram = erd.create(Party)
diagram.models
#> [PydanticModel(Adventurer), PydanticModel(Party), PydanticModel(Quest)]
diagram.draw("diagram.png")
You can also limit or expand the number of models shown:
erdantic erdantic.examples.pydantic.Party -o Party.png -d 0
erdantic erdantic.examples.pydantic.Party -o All.png -d 999