用于Azure Data Explorer的高级Python SDK
项目描述
简介
pykusto 是 Azure Data Explorer (也称为 Kusto) 的先进 Python SDK。
始于 2019 年的 Microsoft Hackathon 项目。
入门
安装
默认安装
pip install pykusto
包含运行测试所需的依赖项
pip install pykusto[test]
不包含 PySpark 中不需要的依赖项
pip install pykusto --global-option pyspark
基本用法
from datetime import timedelta
from pykusto import PyKustoClient, Query
# Connect to cluster with AAD device authentication
# Databases, tables, and columns are auto-retrieved
client = PyKustoClient('https://help.kusto.windows.net')
# Show databases
print(tuple(client.get_databases_names()))
# Show tables in 'Samples' database
print(tuple(client.Samples.get_table_names()))
# Connect to 'StormEvents' table
t = client.Samples.StormEvents
# Build query
(
Query(t)
# Access columns using table variable
.project(t.StartTime, t.EndTime, t.EventType, t.Source)
# Specify new column name using Python keyword argument
.extend(Duration=t.EndTime - t.StartTime)
# Python types are implicitly converted to Kusto types
.where(t.Duration > timedelta(hours=1))
.take(5)
# Output to pandas dataframe
.to_dataframe()
)
重试失败的查询
# Turn on retrying for all queries
from pykusto import PyKustoClient, RetryConfig, Query
client = PyKustoClient(
"https://help.kusto.windows.net",
retry_config=RetryConfig() # Use default retry config
)
# Override retry config for specific query
Query(client.Samples.StormEvents).take(5).to_dataframe(
retry_config=RetryConfig(attempts=3, sleep_time=1, max_sleep_time=600, sleep_scale=2, jitter=1)
)
贡献
本项目欢迎贡献和建议。大多数贡献都需要您同意贡献者许可协议 (CLA),声明您有权利,并且实际上确实授予我们使用您的贡献的权利。有关详细信息,请访问 https://cla.opensource.microsoft.com。
当您提交拉取请求时,CLA 机器人将自动确定您是否需要提供 CLA,并相应地装饰 PR(例如,状态检查,注释)。只需遵循机器人提供的说明即可。您只需在整个使用我们 CLA 的所有存储库中这样做一次。
本项目采用了 Microsoft 开源行为准则。有关更多信息,请参阅 行为准则常见问题解答 或联系 opencode@microsoft.com 了解任何额外的问题或评论。
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源代码发行版
pykusto-0.2.0.tar.gz (56.7 kB 查看哈希值)
构建发行版
pykusto-0.2.0-py3-none-any.whl (40.2 kB 查看哈希值)
关闭
pykusto-0.2.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e2035b1dc72829d696b2e9acdc85dc7ffe76f8e8d9326b9811f27246b0f6baaa |
|
MD5 | 532adc659ea6f476cad2b7ea13811629 |
|
BLAKE2b-256 | 8904bbed59d5e6983563707fafe81f889769bd4344d7e4a1af40debdfacd980a |