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:
- Pydantic
- 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.
Installation
erdantic's graph modeling depends on pygraphviz and Graphviz, an open-source C library. Graphviz must be installed first, and the simplest way is with conda. For other options and installation troubleshooting, see the pygraphviz docs.
To install erdantic from PyPI:
pip install erdantic
Development version
You can get the development version from GitHub with:
pip install https://github.com/drivendataorg/erdantic.git#egg=erdantic
Quick Usage
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.