drivendataorg/erdantic
소개
Entity relationship diagrams for Python data model classes like Pydantic
디자인 및 미디어측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalerdantic: Entity Relationship Diagrams
erdantic is a simple tool for drawing entity relationship diagrams (ERDs) for Python data model classes. Supported data modeling frameworks are:
- Pydantic V2
- Pydantic V1 legacy
- attrs
- msgspec
- dataclasses from the Python standard library
Diagrams are rendered using the Graphviz 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.
Type annotations are formatted using the typenames library.
How to read the diagram
Each node in the diagram is a data model class: a class whose primary purpose is to hold data in a declared set of typed fields. Each edge is a compositional relationship, meaning a field on one class has a type annotation referencing another class, so that the first class "contains" the second. Edges use crow's foot notation to represent the cardinality and modality of each relationship.
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.
관련 프로젝트 살펴보기
불러오는 중…