Skip to main content

Generate ERD diagrams from SQLite databases

Project description

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

Requires Python 3.12+ and uv.

# Clone the repository
git clone https://github.com/yourusername/sqlite-to-erd.git
cd sqlite-to-erd

# Install dependencies
uv sync

# Install GraphViz (for image generation)
# macOS: brew install graphviz
# Ubuntu: sudo apt-get install graphviz
# Windows: https://graphviz.org/download/

Usage

Basic Usage

# Generate DOT format output
uv run sqlite_to_erd.py database.db

# Generate PNG directly (new!)
uv run sqlite_to_erd.py database.db --png schema.png

# Pipe to GraphViz for other formats
uv run sqlite_to_erd.py database.db | dot -Tsvg -o schema.svg

# Use simple box format instead of HTML tables
uv run sqlite_to_erd.py database.db --simple

# Combine options
uv run sqlite_to_erd.py database.db --simple --png simple_schema.png

Quick Examples

# Test with included examples
just fk-png      # Creates test_fk.png
just complex-png # Creates complex_test.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

uv run sqlite_to_erd.py blog.db --png blog.png

Development

# Run tests
just fk        # Test foreign key visualization
just complex   # Test complex schema

# Generate test images
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.

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

sqlite_to_erd-0.3.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlite_to_erd-0.3.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file sqlite_to_erd-0.3.0.tar.gz.

File metadata

  • Download URL: sqlite_to_erd-0.3.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.14

File hashes

Hashes for sqlite_to_erd-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6f85eddac41a8968ebecac10ffe68b7ef45df76010edc1b5f1dffe1248128b96
MD5 d27e17e790f591c292ee6e8510b7829b
BLAKE2b-256 ca1abf5105bdfb826d330fa0dcdea7ea63a82724ed3934efc057628d020166a8

See more details on using hashes here.

File details

Details for the file sqlite_to_erd-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlite_to_erd-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9ac481c6d5299ba4fe6a4a39a01b0f0b0fe4c537885349158046a725e8c3f96
MD5 e3973e4aab675dc8ae790b33cba325e7
BLAKE2b-256 8189e027074936cefe9bdb30b07b60f765f910c0c640cf7cfb51ba3980e34c52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page