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" ||--|{ "departments" : "about_dept -> department_id"
"complaints" ||--|{ "user" : "by_user -> user_id"
"employees" ||--|{ "departments" : "employee_dept -> department_id"
Installation
pip install sqlmermaid
or
uv tool install sqlmermaid
Usage
Command line
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
sqlmermaid sqlite:///mydb.db
# Write Markdown
sqlmermaid sqlite:///mydb.db -o schema.md
# Open in browser
sqlmermaid postgresql://user:pass@localhost/mydb --browser
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))
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 |
Metadata
Release files for sqlmermaid 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqlmermaid-1.0.1.tar.gz | 17.6 kB | Without provenance | Details for sqlmermaid-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqlmermaid-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for sqlmermaid-1.0.1-py3-none-any.whl |
Total release size: 24.1 kB
Release files / sqlmermaid-1.0.1.tar.gz
| Download URL | sqlmermaid-1.0.1.tar.gz |
|---|---|
| Size | 17.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bfa89a21f1e355ed8d09256722b5144af7d2520ec4a025dd2559c071a30810a4
|
|
BLAKE2b-256 checksum How to use checksums |
8153edceaa5a1ce3d005ac00f6efa60511282b59300f4c8dabfb7993921c96fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.3 {"installer":{"name":"uv","version":"0.13.3","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.1-py3-none-any.whl
| Download URL | sqlmermaid-1.0.1-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3bc4b1bfeed97d66d73d68d37bd70ed53cd498eff36b46a7b6ef8f2ad8a53afd
|
|
BLAKE2b-256 checksum How to use checksums |
4d2c4027ce6bcbbf1948d5a0b6b067dfac4b90276b60d71fe2d99c87f7cbf89d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.3 {"installer":{"name":"uv","version":"0.13.3","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}
|
Security for sqlmermaid 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.