跳转到主要内容

Kusto数据客户端

项目描述

from azure.kusto.data import KustoClient, KustoConnectionStringBuilder

cluster = "<insert here your cluster name>"
client_id = "<insert here your AAD application id>"
client_secret = "<insert here your AAD application key>"
authority_id = "<insert here your AAD tenant id>"

kcsb = KustoConnectionStringBuilder.with_aad_application_key_authentication(cluster, client_id, client_secret, authority_id)
# It is a good practice to re-use the KustoClient instance, as it maintains a pool of connections to the Kusto service.
# This sample shows how to create a client and close it in the same scope, for demonstration purposes.
with KustoClient(kcsb) as client:
    db = "Samples"
    query = "StormEvents | take 10"

    response = client.execute(db, query)
    for row in response.primary_results[0]:
        print(row[0], " ", row["EventType"])

Apache Kusto Python 客户端库 提供了使用 Python 查询 Kusto 集群的功能。它与 Python 3.x 兼容,并通过熟悉的 Python DB API 接口支持所有数据类型。

可以使用此库,例如,从 Jupyter Notebooks,这些笔记本连接到 Spark 集群,包括但不限于 Azure Databricks 实例。

异步客户端

Kusto 现在提供用于查询的异步客户端。

要使用客户端,首先使用带有“aio”扩展的包进行安装

pip install azure-kusto-data[aio]

异步客户端使用与常规客户端相同的接口,但它在 azure.kusto.data.aio 命名空间中,并返回 Futures,您需要等待它的结果

from azure.kusto.data import KustoConnectionStringBuilder
from azure.kusto.data.aio import KustoClient

cluster = "<insert here your cluster name>"
client_id = "<insert here your AAD application id>"
client_secret = "<insert here your AAD application key>"
authority_id = "<insert here your AAD tenant id>"


async def sample():
    kcsb = KustoConnectionStringBuilder.with_aad_application_key_authentication(cluster, client_id, client_secret, authority_id)
    async with KustoClient(kcsb) as client:
        db = "Samples"
        query = "StormEvents | take 10"

        response = await client.execute(db, query)
        for row in response.primary_results[0]:
            print(row[0], " ", row["EventType"])

项目详情


版本历史 发布通知 | RSS 源

下载文件

下载适合您平台的应用程序文件。如果您不确定要选择哪一个,请了解更多关于 安装包 的信息。

源代码分发

azure-kusto-data-4.6.1.tar.gz (41.1 kB 查看哈希值)

上传时间:

构建分发

azure_kusto_data-4.6.1-py2.py3-none-any.whl (51.1 kB 查看哈希值)

上传时间: Python 2 Python 3

支持