Skip to main content

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

Project description

Sqlalchemy DB graphing tool

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

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 basic arguments:

  • pk_color: color of primary keys.
  • fk_color: color of foreign keys.
  • pk_and_fk_color: color of columns that are both a primary and a foreign key.
  • display_legend: whether the legend is displayed or not.

Finally, it supports all graphviz arguments, see https://graphviz.org/docs/graph/ for a comprehensive list.

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

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+asyncpg://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.1.0.tar.gz (11.5 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.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlalchemy_db_graphing-0.1.0.tar.gz
  • Upload date:
  • Size: 11.5 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.1.0.tar.gz
Algorithm Hash digest
SHA256 cedf25eb9b1b3db3661f3d3e74f89417314b55aa72747edfea0b57a2bc9343dd
MD5 09516de42f508d1e6817edc5f9f659d2
BLAKE2b-256 9a1ef1f8e19739873481d36a56da0e68d3aded342ce47d0fdf01439ad1ea8fad

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_db_graphing-0.1.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.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_db_graphing-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07eef4819fac5e82cd3b214aeba67717cd5bf386765ec96d02e539a036bc84ab
MD5 f8b33e6fef74f8f1c892a5fc9ed79d40
BLAKE2b-256 3c1e70c70abfd6ba58e88e8912c95b8b830f9e1a308a855040291b6c7f50bcb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_db_graphing-0.1.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