erdalchemy is an interactive ERD visualizer for SQLAlchemy 2.0 models. Point it at your DeclarativeBase and get a diagram, no manual configuration.
- Drag-and-drop interactive HTML, with hover highlighting
- Three layouts: hierarchical layered (default), force-directed, and star
- Orthogonal edge routing that follows foreign keys without cutting across cards
- Regex filtering to focus large schemas (include/exclude tables and columns)
- Export to HTML, SVG, PNG, and PDF
- Built-in themes and per-table color overrides
- Multi-schema support with cross-schema FKs
- Zero dependencies beyond SQLAlchemy
pip install erdalchemyPNG and PDF export need an optional dependency:
pip install "erdalchemy[all]"from sqlalchemy_erd import generate_erd
from myapp.models import Base
generate_erd(Base, output="erd.html")Or from the command line:
sqlalchemy-erd myapp.models:Base --format svg --output erd.svg| Layout | When to use |
|---|---|
layered (default) |
General purpose. Ranks tables into columns by FK direction; cards never overlap. Best for large or wide schemas. |
force |
Small, highly-connected graphs where an organic shape reads better. |
star |
Star/snowflake and ETL schemas, or many disconnected tables. |
generate_erd(Base, output="erd.html", layout="layered")Full reference (every CLI flag, the Python API, themes, layout tuning, card sizing, and supported column types) lives in docs/reference.md.
See examples/ for ready-to-run schemas:
showcase/- 12 tables across four FK levels (the preview above)blog/- blog schema (User, Post, Comment)ecommerce/- 1:N chainsuniversity/- N:N via association tableshr/- 1:1 and 1:Nmulti_schema/- cross-schema FKs
Inspired by eralchemy2 (originally eralchemy), which pioneered generating ER diagrams from SQLAlchemy models. erdalchemy reimagines the idea with a self-contained, interactive, dependency-free renderer.
MIT
