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.4.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.4.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlite_to_erd-0.4.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.4.0.tar.gz
Algorithm Hash digest
SHA256 23f1c6f603697b93627cadf2b89e0b65f884a62ef00b059a91bca3e40b464a6d
MD5 c251e4460366cc092dbcd80f88942ddd
BLAKE2b-256 3356078f396e7ad5792dd669568d4dac08c750483572d1e944040d9e2bd4a794

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlite_to_erd-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c12d9fa03b9c2b7f265519d640e1e23501c9d2950ccf09b5afa767315a757753
MD5 066fc0bf7f2bf57ce7540346dabb9e82
BLAKE2b-256 2f055afa02b1291f1ab18abecb3343f3f27c778e3cd3f0ae430dcdd6a2b35021

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