Generate SVG Entity Relationship Diagrams from PostgreSQL database dump files
Project description
pypgsvg - Lightweight PostgreSQL ERD Generator
pypgsvg is a lightweight Python tool that generates a JS/CSS/SVG interactive Entity Relationship Diagrams (ERDs) from PostgreSQL schema dump files. With only Graphviz as a dependency, manually run or place in CI/CD pipelines, fast rapid deployment verification scenarios.
๏ฟฝ๏ธ Screenshots & Examples
๐ Complete ERD Example
Example of a complex database schema with multiple relationships and interactive features
๐ฌ Interactive Features Demo
Live demonstration of drag, resize, and navigation features
๐บ๏ธ Miniature Overview Navigation
Interactive minimap for navigating large schemas with viewport indicator
๐ Metadata Information Panel
Comprehensive schema statistics and generation parameters
๐ฏ Selection & Details Panel
View detailed SQL for selected tables, foreign keys, and triggers
๐ Basic Schema Example
Simple schema showing core functionality and clean output
Features
- Zero-dependency Python tool (except Graphviz)
- Interactive SVG output with navigation and selection tools
- Scriptable and automatable for enterprise workflows
- Quick deployment - install and run in seconds
- Self-contained - no database connections required
- Cross-platform support (Windows, macOS, Linux)
โจ Interactive Features
๐ฏ Selection & Navigation Tools
- Smart table/edge selection - Click any element to view detailed SQL
- Miniature overview with viewport indicator for large schemas
- Drag & drop containers - Reposition windows anywhere
- Resizable panels - Customize your workspace layout
๐ Copy & Export Tools
- One-click copy - Copy table definitions, foreign keys, or trigger SQL
- Download selection details - Export selected elements as formatted text
- Emoji-free output - Enterprise-friendly plain text exports
๐ฑ๏ธ Interactive Controls
- Minimize/maximize any panel to focus on your work
- Close buttons for distraction-free viewing
- Pan and zoom with mouse or miniature navigator
- Keyboard shortcuts (ESC/R to reset view)
๐จ Visual Enhancements
- Color-coded tables with accessible contrast
- Hover effects for better element identification
- Professional styling suitable for documentation and presentations
๐ฆ Installation
Lightweight setup - only 2 steps:
-
Install
pypgsvg:pip install pypgsvg
-
Install Graphviz (external dependency):
- macOS:
brew install graphviz - Ubuntu/Debian:
sudo apt-get install graphviz - CentOS/RHEL:
sudo yum install graphviz - Windows: Download from Graphviz.org
- macOS:
That's it! Ready for enterprise deployment.
๐ ๏ธ Enterprise Usage
Quick Start - Schema Analysis
# Generate interactive ERD from schema dump
pypgsvg schema.dump --output database_erd --view
# Enterprise automation (CI/CD ready)
pypgsvg Samples/complex_schema.dump --output Samples/complex_schema --rankdir LR --node-sep 4
Advanced Enterprise Options
# Large schema optimization
pypgsvg Samples/complex_schema.dump --output Samples/complex_schema --rankdir LR --node-sep 4
source venv/bin/activate && python -m src.pypgsvg Samples/complex_schema.dump --node-shape=ellipse --show-standalone=false --output=./Samples/complex_schema --rankdir LR --node-sep 2 --packmode
# Custom layout for documentation
pypgsvg schema.dump --rankdir LR --fontsize 20 --node-fontsize 16 --output presentation_erd
Usage
Get Your PostgreSQL Schema
If you don't have a schema dump, generate one with pg_dump:
# Standard schema export (most common)
pg_dump -h your-host -d database -U username -s --no-owner --no-privileges > schema.dump
# Comprehensive export with triggers and functions
pg_dump -h your-host -d database -U username -s -O -F plain --disable-triggers --encoding=UTF8 > schema.dump
Or use our sample schema for testing.
Interactive ERD Generation
Basic usage:
pypgsvg schema.dump --output my_database_erd --view
Usage:
pypgsvg schema.dump \
--output docs/database_architecture \
--rankdir TB \
--node-sep 4 \
--packmode graph \
--rank-sep 3 \
--hide-standalone
The generated SVG includes:
- ๐ฑ๏ธ Interactive selection - Click tables/edges to view SQL details
- ๐ฑ Miniature navigator - Overview panel for large schemas
- ๐ Copy/download tools - Export selected elements
- ๐จ Resizable panels - Customize your workspace
- โจ๏ธ Keyboard shortcuts - ESC/R to reset view
Note: For full interactivity, open the SVG file locally in your browser. GitHub restricts JavaScript for security.
๐ฌ Quick Demo
[๐ฏ View Interactive Example]
[ REFERENCES public.franchises(id)
ON DELETE CASCADE;
For detailed testing instructions, see the Testing Guide.
Quality metrics:
- โ 95%+ code coverage
- โ 70+ comprehensive tests
- โ Cross-platform compatibility
๐๏ธ Architecture & Performance
Lightweight Design
๐ฆ pypgsvg/
โโโ ๐ Pure Python core (~450 lines)
โโโ ๐จ CSS styling (~200 lines)
โโโ โก JavaScript interactivity (~2000 lines)
โโโ ๐งช Comprehensive tests (~1000+ lines)
โโโ ๐ Zero runtime dependencies (except Graphviz)
Performance characteristics:
- Fast parsing - Processes large schemas in seconds
- Memory efficient - Minimal footprint for enterprise deployment
- Scalable output - Handles schemas with hundreds of tables
- Quick startup - No database connections or heavy frameworks
Enterprise-Ready Features
- ๐ Security-focused - No network requirements, processes local files only
- ๐ Audit-friendly - Deterministic output for version control
- ๐ Container-ready - Minimal Docker image size
- โ๏ธ Configurable - Extensive customization options
- ๐ Monitoring - Built-in error reporting and validation
โ๏ธ Configuration & Customization
Advanced Layout Options
# Horizontal layout for wide displays
pypgsvg schema.dump --rankdir LR --node-sep 3 --rank-sep 2
# Compact layout for presentations
pypgsvg schema.dump --packmode graph --fontsize 16 --node-fontsize 14
# Large schema optimization
pypgsvg schema.dump --hide-standalone --esep 8 --rank-sep 4
Table Filtering (Automatic)
Enterprise-focused exclusions for cleaner diagrams:
- Views (
vw_*) - Database views - Backup tables (
*_bk,*_backup) - Temporary backup data - Utility tables (
*_temp,*_tmp) - Temporary processing tables - Log tables (
*_log,*_audit) - Audit and logging tables - Duplicate tables (
*_dups,*_duplicates) - Data cleanup tables - Version tables (
*_old,*_archive) - Historical data tables
Color & Accessibility
- WCAG-compliant color palette with proper contrast ratios
- Automatic text color calculation for readability
- Color-blind friendly palette selection
- High-contrast mode for professional presentations
๐จ Error Handling & Reliability
Error management:
- Graceful degradation - Continues processing despite individual parsing errors
- Detailed error reporting - Specific line numbers and context
- Encoding resilience - Handles various character encodings
- Malformed SQL recovery - Attempts to extract partial information
- Validation checks - Ensures output integrity
Logging:
# Built-in error collection for monitoring
tables, foreign_keys, triggers, errors = parse_sql_dump(sql_content)
if errors:
for error in errors:
log.warning(f"Schema parsing issue: {error}")
# Continue with partial results
๐ค Contributing
Welcome users and contributors:
- Code quality - Follow PEP 8 and maintain >95% test coverage
- Enterprise focus - Consider automation and deployment scenarios
- Performance - Optimize for large schemas and CI/CD usage
- Documentation - Update examples for enterprise use cases
- Testing - Add tests for new SQL patterns and edge cases
Required
- Python 3.8+ (standard in most enterprise environments)
- Graphviz (system package, widely available)
Development/Testing Only
pytest>=7.0.0- Testing frameworkpytest-cov>=4.0.0- Coverage reporting
Testing
The project includes both unit tests (Python) and functional tests (browser-based).
Quick Start
Use the provided test runner script which handles environment setup:
# Run unit tests
./run-tests.sh
# Run browser tests
./run-tests.sh --browser
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pypgsvg-1.1.3.tar.gz.
File metadata
- Download URL: pypgsvg-1.1.3.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
127757b91c76a7d9e78b6f0471013940f84daee3821049511b2e024618babc34
|
|
| MD5 |
5b25bc8a5d3bcd0c0fc2ab9925381cdf
|
|
| BLAKE2b-256 |
58588a9247c0e13328d2c9d8c1a590cffc3bfbdc87af3de141e39d23e265a35a
|
File details
Details for the file pypgsvg-1.1.3-py3-none-any.whl.
File metadata
- Download URL: pypgsvg-1.1.3-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aed637aab6bc685227e1f4758b6ff58fee48b80054abc63b6b379fbe929dcf29
|
|
| MD5 |
9c808435c4a731a5d211e40ee7e508e6
|
|
| BLAKE2b-256 |
c3d75edda4a5079a3f253a65a3452c2fb1bca97cff37a37411c7e14f8ed9156d
|