Skip to main content

Azure Data Explorer (Kusto) dialect for SQLAlchemy

Project description

Azure Data Explorer (Kusto) dialect for SQLAlchemy

pypi

sqlalchemy-kusto implements a DBAPI (PEP-249) and SQLAlchemy dialect that enables SQL query execution via SQLAlchemy.

Current project includes support for two dialects: SQL dialect and KQL dialect.

SQL dialect

Current implementation has full support for SQL queries. But pay your attention that Kusto implementation of T-SQL has not full coverage; check the list of known issues.

KQL dialect

KQL dialect still in progress. Please, use it on your own risk for now.

Notice that implemented Kusto dialects don't support DDL statements and inserts, deletes, updates.

Installation

pip install sqlalchemy-kusto

Library usage

Using DBAPI

from sqlalchemy_kusto import connect

connection = connect(
        cluster=kusto_url,
        database=database_name,
        msi=False,
        user_msi=None,
        azure_ad_client_id=kusto_client_id,
        azure_ad_client_secret=kusto_client_secret,
        azure_ad_tenant_id=kusto_tenant_id,
)

result = connection.execute(f"select 1").fetchall()

Using SQLAlchemy raw sql

from sqlalchemy.engine import create_engine

engine = create_engine(
    f"kustosql+{kusto_url}/{database_name}?"
    f"msi=False&azure_ad_client_id={kusto_client_id}&"
    f"azure_ad_client_secret={kusto_client_secret}&"
    f"azure_ad_tenant_id={kusto_tenant_id}"
)
engine.connect()
cursor = engine.execute(f"select top 1")
data_rows = cursor.fetchall()

Using SQLAlchemy

from sqlalchemy import create_engine, MetaData, Table, Column, String, Integer

engine = create_engine(
    f"kustosql+{kusto_url}/{database_name}?"
    f"msi=False&azure_ad_client_id={kusto_client_id}&"
    f"azure_ad_client_secret={kusto_client_secret}&"
    f"azure_ad_tenant_id={kusto_tenant_id}"
)

my_table = Table(
        "MyTable",
        MetaData(),
        Column("Id", Integer),
        Column("Text", String),
)

query = my_table.select().limit(5)

engine.connect()
cursor = engine.execute(query)
print([row for row in cursor])

Contributing

Please see the CONTRIBUTING.md for development setup and contributing process guidelines.


Issue in Apache Superset repository that inspired current solution.

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-kusto-1.1.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

sqlalchemy_kusto-1.1.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy-kusto-1.1.0.tar.gz.

File metadata

  • Download URL: sqlalchemy-kusto-1.1.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.11

File hashes

Hashes for sqlalchemy-kusto-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e75724dac5d953093cf8851a2cf9ac3030ee1e268f7a5e145332a749ba073c7b
MD5 077b8e17fd4906d02d4f163402e1eaef
BLAKE2b-256 a26c8fcc4e176ec512777e99fcd337354f59995b0e590a8a733582b33c15114f

See more details on using hashes here.

File details

Details for the file sqlalchemy_kusto-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: sqlalchemy_kusto-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.11

File hashes

Hashes for sqlalchemy_kusto-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1be6b3d0881b76bb17f1792f3e7eefe3f574537065bab22c775b9c3b6cf0372
MD5 2ed8e91ef692ef7f3db7182f78bc1888
BLAKE2b-256 23310086b98016d374d761fcd2386ddb5ebed124e884821c491fdf08b26b3994

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page