Azure Data Explorer (Kusto) dialect for SQLAlchemy
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,
dev_mode=False
)
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}&"
f"dev_mode=False"
)
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])
Using with Apache Superset
Apache Superset starting from version 1.5 also supports Kusto database engine spec.
When connecting to a new data source you may choose a data source type either KustoSQL or KustoKQL depending on the dialect you want to use.
There are following connection string formats:
# KustoSQL
kustosql+https://<CLUSTER_URL>/<DATABASE>?azure_ad_client_id=<CLIENT_ID>&azure_ad_client_secret=<CLIENT_SECRET>&azure_ad_tenant_id=<TENANT_ID>&msi=False
# KustoKQL
kustokql+https://<CLUSTER_URL>/<DATABASE>?azure_ad_client_id=<CLIENT_ID>&azure_ad_client_secret=<CLIENT_SECRET>&azure_ad_tenant_id=<TENANT_ID>&msi=False
Important notice on package version compatibility.
Apache Superset stable releases 1.5 and 2.0 dependent onsqlalchemy==1.3.24. If you want to usesqlalchemy-kustowith these versions you need to install version1.*of the package.Current
masterbranch of theapache/supersetdependent onsqlalchemy==1.4.36. If you want to usesqlalchemy-kustowith the latest unstable version ofapache/superset, you need to install version2.*of the package.
Contributing
Please see the CONTRIBUTING.md for development setup and contributing process guidelines.
Issue in Apache Superset repository that inspired current solution.
Metadata
Release files for sqlalchemy-kusto 3.1.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 |
|---|---|---|---|---|
| sqlalchemy_kusto-3.1.2.tar.gz | 22.0 kB | Without provenance | Details for sqlalchemy_kusto-3.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqlalchemy_kusto-3.1.2-py3-none-any.whl | Python 3 | none | any | Details for sqlalchemy_kusto-3.1.2-py3-none-any.whl |
Total release size: 42.6 kB
Release files / sqlalchemy_kusto-3.1.2.tar.gz
| Download URL | sqlalchemy_kusto-3.1.2.tar.gz |
|---|---|
| Size | 22.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9faf05f49cec720acfd601f23623c93309d667571974e22bc22a9397d0bcbbe
|
|
BLAKE2b-256 checksum How to use checksums |
7b885005ffbd6863fb5f457107f5d2d5225dd3d13a0fdd2bdbdcfcbd0c0f13a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.16
|
Release files / sqlalchemy_kusto-3.1.2-py3-none-any.whl
| Download URL | sqlalchemy_kusto-3.1.2-py3-none-any.whl |
|---|---|
| Size | 20.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8503befabc3138f4da47d87ec95cf44c821e8b55ec2449402dda1932d2d6e560
|
|
BLAKE2b-256 checksum How to use checksums |
fb9ee015a7646d4d96c336dbdae73af5385c90d354f50a424f709f3c47ed513f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.16
|
Security for sqlalchemy-kusto 3.1.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.