Skip to main content

A module to display sqlalchemy database tables and keys as a graph

Project description

Sqlalchemy DB graphing tool version 0.2.0

A module to display sqlalchemy database tables and keys as a graph. Inspired by https://pypi.org/project/sqlalchemy-schemadisplay/.

license: MIT license

Features

Generate graphs from your sqlalchemy declarative database in one simple function call.

How to use:

from sqlalchemy_db_graphing import generate_graph_as_png
from mymodule.database_schema import MySQLAlchemySchema

filename = "path/to/save/file.png"
generate_graph_as_png(metadata=MySQLAlchemySchema.metadata, filename=filename)

Database Graph

generate_graph_as_png also supports arguments:

  • style_options: either a string referring to a style preset, or a dictionary of options defining the style of each graphviz node. Keys are: - table_style: Style of each table (table element). - table_name_style: Style of the table name (font element). - header_style: Style of the table headers (td element). - schema_name_style: Style of the schema name (font element). - pk_style: Style of a column identified as a primary key (td element). - fk_style: Style of a column identified as a foreign key (td element). - pk_fk_style: Style of a column identified as both a primary and foreign key (td element). - column_style: Style of all other columns (td element). - legend_style: Style of the legend (table element).
  • display_legend: whether the legend is displayed or not.

Style options dict example (Default style):

{
    "table_style": "cellborder='1' cellspacing='0' cellpadding='4' border='1' style='rounded'",
    "table_name_style": "color='red'",
    "header_style": "align='center' bgcolor='grey' border='0'",
    "schema_name_style": "color='black'",
    "pk_style": "align='left' bgcolor='#99CCFF' border='0'",
    "fk_style": "align='left' bgcolor='#CCFF99' border='0'",
    "pk_fk_style": "align='left' bgcolor='#99CCFF' border='0'",
    "column_style": "align='left' border='0'",
    "legend_style": "border='0' cellpadding='2' cellspacing='0'"
}

Finally, all graphviz keyword arguments are supported, see https://graphviz.org/docs/graph/ for a comprehensive list.

generate_graph_as_png(
        metadata=MySQLAlchemySchema.metadata,
        filename=filename,
        style_options="blue_rounded",
        display_legend=False,
        rankdir="LR",  # Draw the graph from Left to Right instead of Top Down.
        splines = "ortho",
)

Database Graph

generate_graph_as_png(
        metadata=MySQLAlchemySchema.metadata,
        filename=filename,
        style_options="purple_rounded",
        display_legend=False,
        rankdir="TD",
        splines = "curved",
)

Database Graph

generate_graph_as_png(
        metadata=MySQLAlchemySchema.metadata,
        filename=filename,
        style_options="purple_blue",
        display_legend=False,
        rankdir="TD",
        splines = "curved",
)

Database Graph

The module also includes a few other functions:

  • generate_graph_as_svg for svg pictures generation.
  • generate_graph_as_pydot to get a pydot representation of your declarative base.
  • get_schema_metadata_from_live_database to retrieve the metadata from a live database instead of the declarative database

Example with live database:

from sqlalchemy_db_graphing import get_schema_metadata_from_live_database

database_url = f"postgresql+psycopg2://username:password@host:port/db_name"
metadata = get_schema_metadata_from_live_database(url=database_url, schema="my_app_schema")

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

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

sqlalchemy_db_graphing-0.2.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlalchemy_db_graphing-0.2.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_db_graphing-0.2.0.tar.gz.

File metadata

  • Download URL: sqlalchemy_db_graphing-0.2.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for sqlalchemy_db_graphing-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a6380e10604dea99132f9cf3571baecc94694fe0516d358de9294d07e4865385
MD5 a927fc573237c2365e00342ecce2f2dc
BLAKE2b-256 f04d4d15769403804fd7ae453b33f0f1fccba60f84e8d7b59b4e289d66da05f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_db_graphing-0.2.0.tar.gz:

Publisher: publish.yaml on erwann-met/sqlalchemy-db-graphing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sqlalchemy_db_graphing-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_db_graphing-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d311f60cb51869d332d7bddae7f6bb002561995df67f64fea9562b6b95f788f
MD5 8b2cd4918682ba03cb2d6512c95cba07
BLAKE2b-256 88662732d90eab313af93b84ce85bb9f18a805f57bfa085efba6a4d7e237f3c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_db_graphing-0.2.0-py3-none-any.whl:

Publisher: publish.yaml on erwann-met/sqlalchemy-db-graphing

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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