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/knowsuchagency/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.5.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.5.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlite_to_erd-0.5.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.5.0.tar.gz
Algorithm Hash digest
SHA256 543cdf998294dc98d819b1f3996bf288d8c7c234c5c0a82863a818f75fbc64fd
MD5 7c74a90344072ca3db95bae1b72d6518
BLAKE2b-256 6bbf5afda70433faf6debe58ebe4d5d6fa99e1cd1180328f78a31db42a053ecc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlite_to_erd-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dae3829f73374324def81caf69ad8d3ad86e196ae01c3f71ca1df9a480e9b59b
MD5 edc6da2e2ede4d9636b604fe01658c44
BLAKE2b-256 f3a3602c6b77898f4742a7e25dfbe8bd08094ede7c24a159dcbf05a09a72bca2

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