Interactive ERD visualization for SQLAlchemy 2.0 models
Project description
sqlalchemy-erd
Interactive ERD visualizer for SQLAlchemy 2.0 models. Introspects your DeclarativeBase metadata and generates diagram files with no manual configuration required.
- Drag-and-drop interactive HTML output
- Auto-layout via force-directed algorithm
- Hover highlighting for tables and relationships
- Export to HTML, SVG, PNG, and PDF
- Built-in color themes and per-table color overrides
- Zero dependencies beyond SQLAlchemy
Installation
pip install sqlalchemy-erd
PNG and PDF export require an optional dependency:
pip install "sqlalchemy-erd[all]"
Quick start
from sqlalchemy_erd import generate_erd
from myapp.models import Base
generate_erd(Base, output="erd.html")
CLI
# Interactive HTML (default)
sqlalchemy-erd myapp.models:Base
# Specific format and output path
sqlalchemy-erd myapp.models:Base --format svg --output erd.svg
# With theme and custom title
sqlalchemy-erd myapp.models:Base --format png --theme blue --title "My Schema"
# Per-table color overrides as JSON
sqlalchemy-erd myapp.models:Base --colors '{"users": "#1d4ed8", "orders": "#059669"}'
# High-resolution PNG
sqlalchemy-erd myapp.models:Base --format png --scale 3
Python API
from sqlalchemy_erd import generate_erd
from myapp.models import Base
generate_erd(Base, output="erd.html", format="html")
generate_erd(Base, output="erd.svg", format="svg")
generate_erd(Base, output="erd.png", format="png", scale=2) # requires cairosvg
generate_erd(Base, output="erd.pdf", format="pdf") # requires cairosvg
Themes
Five built-in themes: default, blue, green, dark, rose.
Preview images for each theme are available in examples/themes/.
generate_erd(Base, theme="dark")
Per-table color overrides let you assign any hex color to individual tables while keeping the rest of the theme intact:
generate_erd(
Base,
theme="default",
table_colors={
"users": "#1e40af",
"orders": "#065f46",
"products": "#9f1239",
},
)
Supported column types
| SQLAlchemy type | Badge |
|---|---|
| Primary key | PK |
| Foreign key | FK |
String |
string |
Text |
text |
Integer / BigInteger / SmallInteger |
int / bigint / smallint |
Float / Numeric |
float / numeric |
Date |
date |
DateTime |
datetime |
Boolean |
bool |
JSON |
json |
Uuid |
uuid |
Nullable columns display a ? suffix (e.g. text?, date?).
Relationship types
| Cardinality | Line style |
|---|---|
| 1:N | Solid with arrow |
| N:N | Dashed with arrow |
Examples
See the examples/ directory:
examples/blog/- blog schema (User, Post, Comment)examples/ecommerce/- 1:N chains (Category, Product, Order, Customer, OrderItem)examples/university/- N:N via association tables (Student, Course, Professor, Department)examples/hr/- 1:1 and 1:N (Employee, EmployeeProfile, Department, Project)
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file erdalchemy-0.1.0.tar.gz.
File metadata
- Download URL: erdalchemy-0.1.0.tar.gz
- Upload date:
- Size: 886.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a72e29e5ba92c3b6064384e93e9c076eedde876dd0ac6bdcdd4439d1c83286ca
|
|
| MD5 |
2375030914bced0a0e4f7009b09413e2
|
|
| BLAKE2b-256 |
cacb3378a9e68c6121c46e4c3bd3028038e6c35bc3daf5286944648ae2784273
|
File details
Details for the file erdalchemy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: erdalchemy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30af5b79afa5984bacc97fcdd0fb3da92b0c164b1e93297a33a720104548cd31
|
|
| MD5 |
4a832625ac309ba71627a1e361e1e97d
|
|
| BLAKE2b-256 |
068358121a71eeeee8fbdde2686f4861bfa1edeeac6d9a13e0671b5bea28e64c
|