Query Kusto like a pro from the comfort of your Jupyter notebook
Перейти к файлу
Ofri Kleinfeld 0afc492248 CR fixes - fixed bug with not raising an exception and adding test coverage for wrong arguments type 2021-07-20 15:00:47 +03:00
.github/workflows Add support for using in PySpark notebook (#162) 2021-07-06 14:30:22 +03:00
.idea CR fixes - change to vargs syntax instead of a list argument, add test for chained on syntax, and fix type hints 2021-07-20 14:32:26 +03:00
pykusto CR fixes - fixed bug with not raising an exception and adding test coverage for wrong arguments type 2021-07-20 15:00:47 +03:00
test CR fixes - fixed bug with not raising an exception and adding test coverage for wrong arguments type 2021-07-20 15:00:47 +03:00
.gitignore Fix race condition when executing a query before fetch is done (#63) 2020-03-29 16:22:42 +03:00
CODE_OF_CONDUCT.md move to github 2019-07-30 14:32:19 +03:00
LICENSE Add license 2019-07-23 08:46:28 +03:00
README.md Retries (#133) 2021-03-16 14:53:04 +02:00
pykusto.iml Lint fixes (#59) 2020-03-11 12:41:41 +02:00
setup.py Add support for Python 3.9 (#146) 2021-06-17 11:26:48 +03:00

README.md

Introduction

pykusto is an advanced Python SDK for Azure Data Explorer (a.k.a. Kusto).
Started as a project in the 2019 Microsoft Hackathon.

PyPI version Downloads

Getting Started

Installation

pip install pykusto

Basic usage

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()
) 

Retrying failed queries

# Turn on retrying for all queries 
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=3)
)

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.