Skip to main content

sqlmermaid

pypi

Generate Mermaid ER diagrams from any SQLAlchemy-supported database — just pass a connection string.

erDiagram
  "complaints" {
     INTEGER about_dept FK
     INTEGER by_user FK
     DATETIME at_time
     VARCHAR-500 text "in index: comp_ind"
  }
  "departments" {
     INTEGER department_id PK
     VARCHAR-60 department_name
  }
  "user" {
     INTEGER user_id PK
     VARCHAR-16 user_name
     VARCHAR-60 email_address
     VARCHAR-50 nickname
  }
  "employees" {
     INTEGER employee_id PK
     VARCHAR-60 employee_name
     INTEGER employee_dept FK
  }
  "complaints" ||--|{ "user" : "by_user -> user_id"
  "complaints" ||--|{ "departments" : "about_dept -> department_id"
  "employees" ||--|{ "departments" : "employee_dept -> department_id"

Installation

pip install sqlmermaid

Usage

Python API

from sqlmermaid import get_mermaid, to_file, open_in_browser

# Mermaid diagram as a string
print(get_mermaid("sqlite:///mydb.db"))

# Write to a file
to_file("postgresql://user:pass@host/db", "schema.md")   # fenced Mermaid block
to_file("postgresql://user:pass@host/db", "schema.html") # standalone HTML page

# Open in browser
open_in_browser("sqlite:///mydb.db")

You can also pass a pre-populated sqlalchemy.MetaData object:

import sqlalchemy as sa
from sqlmermaid import get_mermaid

meta = sa.MetaData()
meta.reflect(bind=engine)
print(get_mermaid(meta))

Command line

python -m sqlmermaid <connection_string> [options]
Option Description
(none) Print Mermaid diagram to stdout
-o FILE / --output FILE Write diagram to .md or .html
--browser Open diagram in the default browser
# Print to stdout
python -m sqlmermaid sqlite:///mydb.db

# Write Markdown
python -m sqlmermaid sqlite:///mydb.db -o schema.md

# Open in browser
python -m sqlmermaid postgresql://user:pass@localhost/mydb --browser

Diagram features

  • Columns annotated with PK and FK
  • Index membership noted in column comments
  • Foreign key relationships rendered as labelled edges
  • Column size specifiers rewritten for Mermaid compatibility (VARCHAR(255)VARCHAR-255, NUMERIC(10, 2)NUMERIC-10-2)
  • Views included when reflecting from a connection string

Output formats

Extension Description
.md Fenced Mermaid code block
.html Standalone page rendered via the Mermaid CDN

Release files for sqlmermaid 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlmermaid 1.0.0
File Size Uploaded
sqlmermaid-1.0.0.tar.gz 17.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlmermaid 1.0.0
File Interpreter ABI Platform
sqlmermaid-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.8 kB

Release files / sqlmermaid-1.0.0.tar.gz

Download URL sqlmermaid-1.0.0.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9bf0a75b6f0d0b5b029a7fcb9b36b92e8c8e02b64e2470bbed1af47c6033c240
BLAKE2b-256 checksum
How to use checksums
f011ef6d4980a2c53d2bd698f71276b5e59912d1f24b5221fea787eb70c7b9c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sqlmermaid-1.0.0-py3-none-any.whl

Download URL sqlmermaid-1.0.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd114dd6b514875afe49cda4ffdd4635c4a50649bb018f91846f18d1757b9610
BLAKE2b-256 checksum
How to use checksums
4e995acf1d57e020ace02f385a0cf6435911d9d6b6d2f5ab482ec298bdf761eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page