erdantic: Entity Relationship Diagrams
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:
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.
conda install erdantic -c conda-forge
If not using conda, Graphviz must be installed first (before you can install pygraphviz). For recommended options and installation troubleshooting, see the pygraphviz docs. Then to install erdantic and its Python dependencies from PyPI:
pip install erdantic
You can get the development version from GitHub with:
pip install https://github.com/drivendataorg/erdantic.git#egg=erdantic
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), PydanticModel(QuestGiver)] diagram.draw("diagram.png")
Check out the "Usage Examples" section of our docs to see more.