SQLAlchemy SchemaDisplay is a Python library (version 2.0) for generating visual diagrams from SQLAlchemy ORM models or directly from a database schema. It leverages the Graphviz engine to produce high-quality visualizations of database structures, showing tables, columns, relationships, and data types. Releases are primarily driven by feature additions and compatibility updates with SQLAlchemy.
pip install sqlalchemy-schemadisplay graphvizVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define simple SQLAlchemy models using `declarative_base` and then use `create_schema_graph` to generate a PNG diagram representing their structure. It outputs a file named `schema.png` in the current directory. Remember that the Graphviz executable must be installed on your system for this to work.
Install Graphviz on your operating system (e.g., `sudo apt-get install graphviz` on Debian/Ubuntu, `brew install graphviz` on macOS, or from graphviz.org for Windows).
Ensure both `sqlalchemy-schemadisplay` and `graphviz` are installed: `pip install sqlalchemy-schemadisplay graphviz`.
Always use `metadata=Base.metadata` for declarative models or `metadata=db_engine.metadata` for reflected schemas.
Call a `write_` method on the returned graph object with a valid file path, e.g., `graph.write_png('my_schema.png')`.