sqlite-to-erd
Convert SQLite database schemas into Entity Relationship Diagrams (ERDs) using GraphViz.
Features
- 📊 Visualize SQLite database schemas as ERDs
- 🔗 Automatic foreign key relationship detection
- 📐 Two rendering modes: HTML-like tables or simple boxes
- 🖼️ Direct PNG generation with
--png
flag
- 🔒 Read-only database access for safety
Installation
Option 1: Run directly with uvx (recommended)
Requires Python 3.12+ and uvx.
uvx sqlite-to-erd database.db
Option 2: Local installation
git clone https://github.com/knowsuchagency/sqlite-to-erd.git
cd sqlite-to-erd
uv sync
Usage
Basic Usage
With uvx (run directly from PyPI):
uvx sqlite-to-erd database.db
uvx sqlite-to-erd database.db --png schema.png
uvx sqlite-to-erd database.db --simple
With local installation:
uv run sqlite_to_erd.py database.db
uv run sqlite_to_erd.py database.db --png schema.png
uv run sqlite_to_erd.py database.db | dot -Tsvg -o schema.svg
uv run sqlite_to_erd.py database.db --simple
uv run sqlite_to_erd.py database.db --simple --png simple_schema.png
Quick Examples
just fk-png
just complex-png
Output Format
The tool generates GraphViz DOT format, which can be:
- Piped to
dot
, neato
, fdp
, etc. for different layouts
- Exported to PNG, SVG, PDF, and other formats
- Edited manually for fine-tuning
Examples
Simple Database
echo "
CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE posts (
id INTEGER PRIMARY KEY,
user_id INTEGER,
title TEXT,
FOREIGN KEY (user_id) REFERENCES users(id)
);
" | sqlite3 blog.db
uvx sqlite-to-erd blog.db --png blog.png
uv run sqlite_to_erd.py blog.db --png blog.png
Development
just fk
just complex
just fk-png
just complex-png
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Pull requests welcome! Please test your changes with the included test databases.