ERAlchemy is a Python library for generating Entity-Relation (ER) diagrams from SQLAlchemy models, declarative database metadata, or a simple text file format. It leverages the external Graphviz engine to visualize the relationships and can output diagrams in various formats such as PNG, SVG, and PDF. The current stable version is 1.6.0, with development activity having slowed in recent years, but it remains a functional tool for its primary purpose.
pip install eralchemyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to generate an ER diagram from SQLAlchemy models using `eralchemy`. It creates a simple SQLite database with two related tables (`User` and `Email`) and then uses `render_er` to generate a PNG file. Crucially, the external Graphviz program must be installed on your system for rendering to succeed.
Install Graphviz on your system and ensure its executables are available in your system's PATH. Refer to the official Graphviz documentation for detailed installation instructions.
Ensure Graphviz and its development headers (e.g., `graphviz-dev` on Debian/Ubuntu, or Xcode Command Line Tools on macOS) are installed *before* attempting to install `pygraphviz` or `eralchemy[all]`. If issues persist, consider using the default rendering backend without `pygraphviz`.
Be mindful of this if working with very new SQLAlchemy versions or complex model structures that push the boundaries of common ER diagram representations. Test thoroughly if encountering unexpected rendering issues.
Verify the generated diagram against your actual model to ensure correctness. For highly complex cases, manual adjustments to the diagram or using an `eralchemy` 'meta' file for declarative definitions might be necessary to achieve the desired representation.
Install Graphviz on your system. For Debian/Ubuntu: `sudo apt install graphviz libgraphviz-dev`. For macOS: `brew install graphviz`. For Windows, download and install Graphviz from their official website and ensure its `bin` directory is added to your system's PATH environment variable.
Install the 'Build Tools for Visual Studio' from Microsoft's website and ensure that the C++ build tools are selected during installation. Alternatively, install `eralchemy` using Anaconda/Conda via `conda install -c conda-forge eralchemy` which often handles these dependencies better on Windows.
Ensure Graphviz is properly installed and its `bin` directory is in the system PATH. For specific database drivers (e.g., Oracle, MySQL), ensure they are also correctly installed (e.g., `pip install cx_Oracle` or `pip install mysqlclient`). If issues persist on Windows, consider using Windows Subsystem for Linux (WSL) or a Docker environment.
Downgrade your SQLAlchemy installation to a version prior to 1.4 by running `pip install 'sqlalchemy<1.4'`.