Microsoft Azure Kusto Management Client Library for Python

3.4.0 · active · verified Tue Apr 14

The `azure-mgmt-kusto` library is the Microsoft Azure Kusto Management Client Library for Python, used to programmatically manage Azure Kusto (Azure Data Explorer) clusters and databases. It enables operations such as creating, updating, and deleting Kusto clusters and their associated databases. The library follows the modern Azure SDK guidelines and requires Python 3.8 or later. The current version is 3.4.0, released on 2024-01-24.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with `DefaultAzureCredential` and instantiate the `KustoManagementClient`. It then shows how to list Kusto clusters within a specified resource group. Ensure that the required environment variables (`AZURE_SUBSCRIPTION_ID`, and optionally `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`, `KUSTO_RESOURCE_GROUP_NAME`) are set for successful execution.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.kusto import KustoManagementClient

# Set environment variables for authentication and subscription ID
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET (for service principal)
# AZURE_SUBSCRIPTION_ID

subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "YOUR_SUBSCRIPTION_ID")
if not subscription_id or subscription_id == "YOUR_SUBSCRIPTION_ID":
    raise ValueError("AZURE_SUBSCRIPTION_ID environment variable not set or is a placeholder.")

# Authenticate using DefaultAzureCredential. This credential will attempt
# to use various authentication methods, such as environment variables,
# managed identity, or Azure CLI, in a prioritized order.
credential = DefaultAzureCredential()

# Create Kusto Management Client
client = KustoManagementClient(credential=credential, subscription_id=subscription_id)

# Example: List Kusto Clusters in a resource group
# Replace 'YOUR_RESOURCE_GROUP' with an actual resource group name where Kusto clusters exist.
resource_group_name = os.environ.get("KUSTO_RESOURCE_GROUP_NAME", "YOUR_RESOURCE_GROUP")

if not resource_group_name or resource_group_name == "YOUR_RESOURCE_GROUP":
    print("Warning: KUSTO_RESOURCE_GROUP_NAME environment variable not set or is a placeholder. Skipping cluster listing example.")
else:
    print(f"Listing Kusto clusters in resource group: {resource_group_name}")
    try:
        for cluster in client.clusters.list_by_resource_group(resource_group_name):
            print(f"- {cluster.name} (Location: {cluster.location}, SKU: {cluster.sku.name})")
    except Exception as e:
        print(f"Error listing clusters: {e}. Ensure the resource group exists and you have permissions.")

view raw JSON →