Skip to main content

Python package installation for erlachemy_schemadisplay_anywidget_magicy

Project description

erlachemy_schemadisplay_anywidget_magic

IPython magic to generate a database schema using eralchemy and display it using jupyter_anywidget_graphviz Graphviz WASM anywidget.

Install from PyPi as:

pip install erlachemy_schemadisplay_anywidget_magic

Enable magics: %load_ext eralchemy_schemadisplay_magic

Create magic with "hidden" graphviz anywidget: %schema_magic_init

Alternatively, create an anywidget and pass it it:

from jupyter_anywidget_graphviz import (
    graphviz_headless,
)

g = graphviz_headless()
%schema_magic_init g

Create example database:

import sqlite3


def create_database():
    # Connect to (or create) the SQLite database
    conn = sqlite3.connect("example.db")
    cursor = conn.cursor()

    # Create the parent table
    cursor.execute(
        """
        CREATE TABLE IF NOT EXISTS users (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            name TEXT NOT NULL
        )
    """
    )

    # Create the child table with a foreign key reference to users
    cursor.execute(
        """
        CREATE TABLE IF NOT EXISTS orders (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            user_id INTEGER NOT NULL,
            product TEXT NOT NULL,
            FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
        )
    """
    )

    # Commit and close
    conn.commit()
    conn.close()

create_database()

Generate schema as dot script and render using graphviz widget:

__Note that this requires the -m / --mode to be set to dot, which it is by default, although we can also pass it explicitly.

dot_data = %schema_magic -c "sqlite:///example.db" -m dot

from IPython.display import SVG
SVG( g.render(dot_data)["svg"] )
```

If we pass a widget in to the magic, and we have a "full" `anywidget` running environment (not JupyterLite/marimo/pyodide), we can use the `-e / --embed` switch to return the dot diagram rendered as SVG (this will attempt to create/use an internally created graphviz widget). Alternatively, we can pass a grpahviz widget using the `-w / --widget-name` parameter.

`%schema_magic -c "sqlite:///example.db" -m dot -e`

`%schema_magic -c "sqlite:///example.db" -m dot -w g`

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

Built Distribution

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

File details

Details for the file erlachemy_schemadisplay_anywidget_magic-0.0.1.tar.gz.

File metadata

File hashes

Hashes for erlachemy_schemadisplay_anywidget_magic-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b4430b1dca47f06c0339ed73b55b9b67a43a635e4e64920b1040f1e04e12ebf5
MD5 4db7cd668222dc957fb9670bd16b817d
BLAKE2b-256 bb5db42f1c0697d4a69076ffef46f028837670892dce834ec977ecfb19000131

See more details on using hashes here.

File details

Details for the file erlachemy_schemadisplay_anywidget_magic-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for erlachemy_schemadisplay_anywidget_magic-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 de54ec2d9122b3c4eeacaf9d54b4591f31fa1cd80f7970ab324fcfb98f87f3fb
MD5 a57c0a194436e3667fce19597b568aac
BLAKE2b-256 d7be91b9793e2b594525e74d5df2ec0f9d40676a1418cd315245497b35df5642

See more details on using hashes here.

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