A python edsl for specifying and generating ER diagrams, SQLite DBs and markdown/PDF reports
- Python 100%
| .idea | ||
| docs | ||
| erdig | ||
| examples | ||
| .gitignore | ||
| LICENSE | ||
| pyproject.toml | ||
| README.md | ||
ERDIG — Declarative ER Schemas & Diagrams (Python)
ERDIG is a tiny, dependency-free Python library for declaring Entity–Relationship (ER) models in code and generating ER diagrams. It provides a Pythonic DSL to define entities, attributes, relationships (including n-ary and relationship attributes), cardinalities, domains/enums, and generalization (inheritance). Models validate to a canonical, renderer-agnostic IR which can be rendered to Graphviz DOT/SVG/PNG/PDF. An optional SQLite helper can generate DDL and initialize a database file from your model.
- No non-stdlib dependencies
- Strong validation with helpful error messages
- Stable, deterministic IR via
Schema.to_spec() - Graphviz renderer included (uses your system
dotif present) - Optional SQLite DDL generator + executor (pure stdlib)
Installation
No installation is required if you use this repository directly. The package is pure Python and has no external dependencies.
- Optional: install Graphviz to export SVG/PNG/PDF. On most systems installing Graphviz adds the
dotcommand to your PATH. - Optional: install pandoc to enable Markdown-to-PDF export (
erdig.markdown.MarkdownAssembler.save_pdf). - Without Graphviz, you can still save
.dot/.gvfiles and view them with any DOT viewer.
Quick Example
from erdig import Schema, T, Role, one, zero_or_more
s = Schema("Blog")
User = (
s.entity("User").attr("id", T.UUID, nullable=False).attr("email", T.String(120)).pk("id").unique("email")
)
Post = s.entity("Post").attr("id", T.BigInt, nullable=False).attr("title", T.String(200), nullable=False).pk("id")
s.relationship("Writes", Role(User, one()), Role(Post, zero_or_more()))
s.validate()
diagram = s.diagram()
diagram.save("blog.dot") # always available
# diagram.save("blog.svg") # requires Graphviz
Project Structure
erdig/... library implementationexamples/... runnable examples (small/medium/big)docs/... documentation
Documentation Map
- Quick start:
docs/quickstart.md - Public API:
docs/api.md - SQLite DDL:
docs/sqlite.md - Markdown docs:
docs/markdown.md - Modeling cookbook:
docs/modeling-cookbook.md - IR format:
docs/ir.md - Rendering:
docs/rendering.md - Validation & errors:
docs/validation.md