SQL to ER Diagram
Home › SQLAlchemy

SQLAlchemy to ER Diagram

Paste your SQLAlchemy declarative models and get an interactive ER diagram — tables from __tablename__, columns, and relations from ForeignKey.

Open the diagram tool →
No signup · nothing uploaded · export PNG / SVG / Mermaid / DBML · shareable link

How it works

  1. Copy your SQLAlchemy model classes (declarative Base / db.Model).
  2. Paste them into the editor — SQLAlchemy is auto-detected.
  3. Each model becomes a table; ForeignKey("table.col") becomes a relation.
  4. Arrange, hide tables, then export PNG/SVG or share a link.

Example

SQLAlchemy models like this:

class User(Base):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True)
    email = Column(String, unique=True)

class Post(Base):
    __tablename__ = "posts"
    id = Column(Integer, primary_key=True)
    author_id = Column(Integer, ForeignKey("users.id"))

…renders two tables with a relation from posts.author_idusers.id. Try it with your own →

Guide

SQLAlchemy has two shapes of model code and both paste fine here: the classic Column(Integer, primary_key=True) declarative style, and the 2.0 typed style with Mapped[int] and mapped_column(...). Tables come from __tablename__ (or the class name if you omit it), columns from the Column/mapped_column calls, and every ForeignKey("users.id") — including composite ForeignKey("t.a"), ForeignKey("t.b") pairs — becomes a drawn relation.

What the parser deliberately ignores: relationship() back-references (the FK is what's drawn — relationship is Python-side only), hybrid properties, and methods. Nothing is executed; the models are read as text, so imports, custom base classes and decorators are all fine.

If your project uses Alembic, an even more exact route is alembic upgrade head --sql to print raw DDL and paste that instead — it captures server defaults and indexes the models don't show. But for most apps, pasting models.py directly is the two-second path to a diagram for your README or design doc.

Why use it

SQLAlchemyPrismaSequelizeSQL

FAQ

How do I visualize SQLAlchemy models?

Paste your declarative model classes. Tables come from __tablename__, columns from Column(...), and relations from ForeignKey.

Do I need to run my app?

No — it reads the model source directly in the browser, nothing is imported or executed.

Is my schema uploaded anywhere?

No. Everything runs locally in your browser — your schema is never uploaded to or stored on any server.

Is it free?

Yes. It is completely free and open source, with no account or sign-up required.

Related