Skip to main content

An Apache Superset compatible SQLAlchemy dialect for connecting to a [GizmoSQL](https://github.com/gizmodata/gizmosql) server with ADBC

Project description

Superset SQLAlchemy GizmoSQL ADBC Dialect

superset-sqlalchemy-gizmosql-adbc-dialect-ci Supported Python Versions PyPI version PyPI Downloads

Basic Apache Superset compatible SQLAlchemy dialect for GizmoSQL

This package uses a version of SQLAlchemy which is compatible with Apache Superset 5.0.*

Installation

Option 1 - from PyPi

$ pip install superset-sqlalchemy-gizmosql-adbc-dialect

Option 2 - from source - for development

git clone https://github.com/gizmodata/superset-sqlalchemy-gizmosql-adbc-dialect

cd superset-sqlalchemy-gizmosql-adbc-dialect

# Create the virtual environment
python3 -m venv .venv

# Activate the virtual environment
. .venv/bin/activate

# Upgrade pip, setuptools, and wheel
pip install --upgrade pip setuptools wheel

# Install Superset SQLAlchemy GizmoSQL ADBC Dialect - in editable mode with dev dependencies
pip install --editable .[dev]

Note

For the following commands - if you are running from source and using --editable mode (for development purposes) - you will need to set the PYTHONPATH environment variable as follows:

export PYTHONPATH=$(pwd)/src

Usage

Once you've installed this package, you should be able to just use it, as SQLAlchemy does a python path search

Start a GizmoSQL Server - example below - see https://github.com/gizmodata/GizmoSQL for more details

docker run --name gizmosql \
           --detach \
           --rm \
           --tty \
           --init \
           --publish 31337:31337 \
           --env TLS_ENABLED="1" \
           --env GIZMOSQL_PASSWORD="gizmosql_password" \
           --env PRINT_QUERIES="1" \
           --pull missing \
           gizmodata/gizmosql:latest

Connect with the SQLAlchemy GizmoSQL ADBC Dialect

import os
import logging

from sqlalchemy import create_engine, MetaData, Table, select, Column, text, Integer, String, Sequence
from sqlalchemy.orm import Session
from sqlalchemy.orm import declarative_base
from sqlalchemy.engine.url import URL

# Setup logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)


Base = declarative_base()


class FakeModel(Base):  # type: ignore
    __tablename__ = "fake"

    id = Column(Integer, Sequence("fakemodel_id_sequence"), primary_key=True)
    name = Column(String)


def main():
    # Build the URL
    url = URL.create(drivername="gizmosql",
                     host="localhost",
                     port=31337,
                     username=os.getenv("GIZMOSQL_USERNAME", "gizmosql_username"),
                     password=os.getenv("GIZMOSQL_PASSWORD", "gizmosql_password"),
                     query={"disableCertificateVerification": "True",
                            "useEncryption": "True"
                            }
                     )

    print(f"Database URL: {url}")

    engine = create_engine(url=url)
    Base.metadata.create_all(bind=engine)

    metadata = MetaData()
    metadata.reflect(bind=engine)

    for table_name in metadata.tables:
        print(f"Table name: {table_name}")

    with Session(bind=engine) as session:

        # Try ORM
        session.add(FakeModel(id=1, name="Joe"))
        session.commit()

        joe = session.query(FakeModel).filter(FakeModel.name == "Joe").first()

        assert joe.name == "Joe"

        # Execute some raw SQL
        results = session.execute(statement=text("SELECT * FROM fake")).fetchall()
        print(results)

        # Try a SQLAlchemy table select
        fake: Table = metadata.tables["fake"]
        stmt = select(fake.c.name)

        results = session.execute(statement=stmt).fetchall()
        print(results)


if __name__ == "__main__":
    main()

Superset - connection URL example

Here is a example connection URL (for use with Apache Superset):

gizmosql://gizmosql_username:gizmosql_password@localhost:31337?disableCertificateVerification=True&useEncryption=True

To specify a catalog other than the default - you can specify the catalog argument - example:

gizmosql://gizmosql_username:gizmosql_password@localhost:31337?disableCertificateVerification=True&useEncryption=True&catalog=test

Credits

Much code and inspiration was taken from repo: https://github.com/Mause/duckdb_engine

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 superset_sqlalchemy_gizmosql_adbc_dialect-0.0.7.tar.gz.

File metadata

File hashes

Hashes for superset_sqlalchemy_gizmosql_adbc_dialect-0.0.7.tar.gz
Algorithm Hash digest
SHA256 c123a9bf9554ea87f783231b861540e09989acfd8388e0f0d36c490b1ab9c412
MD5 42273d4ea1d298f018ed6e0d5604db53
BLAKE2b-256 da0a044c5f66d19cc19372c9a6d8aac2e1fb2c04a31049a1a60a50b1162277cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for superset_sqlalchemy_gizmosql_adbc_dialect-0.0.7.tar.gz:

Publisher: ci.yml on gizmodata/superset-sqlalchemy-gizmosql-adbc-dialect

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

File details

Details for the file superset_sqlalchemy_gizmosql_adbc_dialect-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for superset_sqlalchemy_gizmosql_adbc_dialect-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 5f03fd2e76ac58ce7142981d63b2ea99f5d89bbc7167ffdb105d91d731f8f5bb
MD5 94bb4041e534afaa537fb318eff82761
BLAKE2b-256 4d3dc6a81749b61737fad60e26b344d9aa7f212fee120f3ea372c5354b3da203

See more details on using hashes here.

Provenance

The following attestation bundles were made for superset_sqlalchemy_gizmosql_adbc_dialect-0.0.7-py3-none-any.whl:

Publisher: ci.yml on gizmodata/superset-sqlalchemy-gizmosql-adbc-dialect

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