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/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
TO DO - fix things so it works in Marimo:
- remove IPython refs
- move function to create and render dot file out of magic and into a cleaner py api
Metadata
Release files for erlachemy-schemadisplay-anywidget-magic 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| erlachemy_schemadisplay_anywidget_magic-0.0.2.tar.gz | 6.1 kB | Without provenance | Details for erlachemy_schemadisplay_anywidget_magic-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| erlachemy_schemadisplay_anywidget_magic-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for erlachemy_schemadisplay_anywidget_magic-0.0.2-py3-none-any.whl |
Total release size: 13.1 kB
Release files / erlachemy_schemadisplay_anywidget_magic-0.0.2.tar.gz
| Download URL | erlachemy_schemadisplay_anywidget_magic-0.0.2.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
592b6e3ee66ba05f532654ccaa29556ff8e4895166200716da85cc605e55deb4
|
|
BLAKE2b-256 checksum How to use checksums |
c6610f1b6578411ec63be28678c1e0e48b88cce0916742468bcc882b8f2af884
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.0
|
Release files / erlachemy_schemadisplay_anywidget_magic-0.0.2-py3-none-any.whl
| Download URL | erlachemy_schemadisplay_anywidget_magic-0.0.2-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b69ba7f3ef8c0273e2a71801a18ec617c1bb371200cc2ee9775f4196ab791482
|
|
BLAKE2b-256 checksum How to use checksums |
73ad3a803eed4a15c96447613075d03850c2f93ed9ce3ce9a9c3c5f62c79922b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.0
|
Security for erlachemy-schemadisplay-anywidget-magic 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.