Skip to main content

Interactive ERD visualization for SQLAlchemy 2.0 models

Project description

erdalchemy

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
  • Multi-schema support with visual grouping and cross-schema FKs
  • Zero dependencies beyond SQLAlchemy

preview

Installation

pip install erdalchemy

PNG and PDF export require an optional dependency:

pip install "erdalchemy[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

# Only include specific database schemas
sqlalchemy-erd myapp.models:Base --schemas public,billing,audit

# Tune layout parameters
sqlalchemy-erd myapp.models:Base --k-repulse 50000 --k-attract 0.05 --ideal-len 350

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

# Only include specific database schemas
generate_erd(Base, output="erd.html", schemas=["public", "billing", "audit"])

# Tune layout parameters
generate_erd(Base, output="erd.html", k_repulse=50000, k_attract=0.05, ideal_len=350)

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",
    },
)

Layout tuning

The force-directed layout can be customized via four parameters:

Parameter Default Description
k_repulse 35000 Repulsion strength between all nodes. Increase to spread tables further apart.
k_attract 0.1 Attraction strength between connected nodes. Higher values pull FK-related tables closer.
k_align 0.02 Horizontal-alignment force. Pushes connected tables to the same Y, favoring side-by-side placement.
ideal_len 280 Target edge length (px) between connected tables.

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
Cross-schema FK Dashed with longer gaps

Examples

See the examples/ directory:

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

erdalchemy-0.2.0.tar.gz (863.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

erdalchemy-0.2.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file erdalchemy-0.2.0.tar.gz.

File metadata

  • Download URL: erdalchemy-0.2.0.tar.gz
  • Upload date:
  • Size: 863.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for erdalchemy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8b72e85db28cb6e6a1663cd828a80cb398a7246805f94bee75b936972642c815
MD5 d50297dab9ef1fb8b986c69b58a56125
BLAKE2b-256 7268fff5ff3735fbb6df1b3f52eb4bb692fe8312b19b25ecc8daa77206269964

See more details on using hashes here.

File details

Details for the file erdalchemy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: erdalchemy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for erdalchemy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5a39181e61657562f6cdba61fdaab57c3265708422e3ca39862a6cb7f8b50ce
MD5 fef97cf218a547626989c56f6c9f5a25
BLAKE2b-256 86d81e0e0506ee021ef01e429c5199813cc6abbcae6d3389f9d8afbecfe2e4e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page