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
ER diagram of the SQLAlchemy example schema: users and posts (2 tables, 1 relationship)
The SQLAlchemy example below, drawn by the tool: users and posts (2 tables, 1 relationship).

At a glance

What it is
SQL to ER Diagram is a free, open-source browser tool that turns SQLAlchemy models into an interactive entity-relationship (ER) diagram.
Input
SQLAlchemy declarative model classes (Python source).
Output
An interactive ER diagram you can rearrange, then export as PNG, SVG, Mermaid, DBML or PlantUML, or share as a link.
Cost
Free. MIT-licensed open source. No account or signup.
Privacy
Runs entirely in your browser. The schema is never uploaded, and share links carry the diagram in the URL fragment, which is not sent to a server.
Limits
It never connects to your database itself: you paste schema text, or run one read-only catalog query in your own client and paste the result. There are no accounts, so there is no real-time multi-user editing; diagrams are kept in your browser, as a saved file, or as a share link. Layout stays smooth at around 300 tables.

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_id → users.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