A python edsl for specifying and generating ER diagrams, SQLite DBs and markdown/PDF reports
Find a file
2025-09-22 10:20:22 +02:00
.idea initial commit 2025-09-16 23:14:54 +02:00
docs make notation not a string but an enum 2025-09-22 09:44:24 +02:00
erdig remove unnecessarily restrictive checks 2025-09-22 10:20:22 +02:00
examples make notation not a string but an enum 2025-09-22 09:44:24 +02:00
.gitignore update gitignore 2025-09-17 01:27:15 +02:00
LICENSE update README.md and add license 2025-09-17 00:28:28 +02:00
pyproject.toml add pyproject.toml for building/installing 2025-09-17 01:27:41 +02:00
README.md add markdown/pdf generation utility 2025-09-17 00:35:31 +02:00

ERDIG — Declarative ER Schemas & Diagrams (Python)

ERDIG is a tiny, dependency-free Python library for declaring EntityRelationship (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 dot if 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 dot command to your PATH.
  • Optional: install pandoc to enable Markdown-to-PDF export (erdig.markdown.MarkdownAssembler.save_pdf).
  • Without Graphviz, you can still save .dot/.gv files 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 implementation
  • examples/ ... 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

License

MIT License