Visualizing SQL databases
Project description
sqlmermaid
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
PKandFK - 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 |
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
sqlmermaid-1.0.0.tar.gz
(17.4 kB
view details)
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 sqlmermaid-1.0.0.tar.gz.
File metadata
- Download URL: sqlmermaid-1.0.0.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bf0a75b6f0d0b5b029a7fcb9b36b92e8c8e02b64e2470bbed1af47c6033c240
|
|
| MD5 |
e2797d3a9a84bdc2ea73492b51246486
|
|
| BLAKE2b-256 |
f011ef6d4980a2c53d2bd698f71276b5e59912d1f24b5221fea787eb70c7b9c8
|
File details
Details for the file sqlmermaid-1.0.0-py3-none-any.whl.
File metadata
- Download URL: sqlmermaid-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd114dd6b514875afe49cda4ffdd4635c4a50649bb018f91846f18d1757b9610
|
|
| MD5 |
7cbedcca85ea401f87057c9a00e9e3ae
|
|
| BLAKE2b-256 |
4e995acf1d57e020ace02f385a0cf6435911d9d6b6d2f5ab482ec298bdf761eb
|