from eralchemy import render_er
## Draw from SQLAlchemy base
render_er(Base, 'erd_from_sqlalchemy.png')
## Draw from database
render_er("sqlite:///relative/path/to/db.db", 'erd_from_sqlite.png')
Adjustments to the rendering config
When rendering dot files, it can be needed to adjust how some parts are visualized.
This can be used to get crowfoot relations, stars instead of underlines for primary keys or a top-bottom rendering instead the default left-right rendering.
It can be adjusted by manipulating the global from eralchemy.cst import config dictionary.
Some helper functions exist like dot_star_primary, dot_top_down, dot_digraph and dot_crowfoot.
The config can be reset using reset_config.
This can be used like
from eralchemy import render_er
from eralchemy.cst import dot_crowfoot, dot_digraph
dot_crowfoot()
dot_digraph()
render_er(Base, "forum.svg")
Architecture
graph LR
subgraph Inputs
A[Markdown representation]
B[SQLAlchemy Schema]
C[Existing database]
D[Other ORM ?]
end
E[Intermediary representation]
subgraph Outputs
F[Markdown representation]
G[Graphviz code]
H[Drawing]
end
A --> E
B --> E
C --> E
D --> E
E --> F
E --> G
E --> H
Thanks to it's modular architecture, it can be connected to other ORMs/ODMs/OGMs/O*Ms.
This project uses the pytest test suite.
To run the tests, use : $ pytest or $ nox.
Some tests require having a local PostgreSQL database with a schema named test in a database
named test all owned by a user named eralchemy with a password of eralchemy.
If docker compose is available, one can use docker compose up -d for this purpose.
You can deselect the tests which require a PostgreSQL database using: