Erdantic
Entity relationship diagrams for Python data model classes like Pydantic
Install / Use
/learn @drivendataorg/ErdanticREADME
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 Graphviz library. Supported data modeling frameworks are:
- Pydantic V2
- Pydantic V1 legacy
- attrs
- msgspec
- dataclasses from the Python standard library
We also support D2 as an alternative output format.
You can use erdantic either as a convenient CLI or as a Python library. Great for adding a simple and clean data model reference to your documentation.
<object type="image/svg+xml" data="https://raw.githubusercontent.com/drivendataorg/erdantic/refs/heads/main/docs/docs/assets/example_diagram.svg" width="100%" typemustmatch><img alt="Example diagram created by erdantic" src="https://raw.githubusercontent.com/drivendataorg/erdantic/refs/heads/main/docs/docs/assets/example_diagram.svg"></object>
Type annotations are formatted using the typenames library.
Installation
erdantic's graph modeling depends on pygraphviz and Graphviz, an open-source C library. If you are on Linux or macOS, the easiest way to install everything together is to use conda and conda-forge:
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
Development version
You can get the development version from GitHub with:
pip install "erdantic @ git+https://github.com/drivendataorg/erdantic.git"
See pip's documentation for more on how to specify VCS dependencies.
Quick usage
First, make sure that the data model classes that you want to include in your diagram are importable. This means the code with your models should either be available on your sys.path or installed into the same virtual environment as erdantic.
The fastest way to produce a diagram like the above example is to use the erdantic CLI. Simply specify the full dotted import path to your model and an output file 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. This lets you inspect the diagram data and potentially modify it. You will have greater ability to customize the diagram in Python.
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)
list(diagram.models.keys())
#> [ 'erdantic.examples.pydantic.Adventurer',
#> 'erdantic.examples.pydantic.Party',
#> 'erdantic.examples.pydantic.Quest',
#> 'erdantic.examples.pydantic.QuestGiver']
diagram.draw("diagram.png")
Check out the "Usage Examples" section of our docs to see more.
Related Skills
node-connect
339.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
claude-opus-4-5-migration
83.9kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
model-usage
339.3kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
