In your preferred IDE or text editor, create a project or file named hello kusto using the convention appropriate for your preferred language. Then add the following code:
from azure.kusto.data import KustoClient, KustoConnectionStringBuilder
import { Client as KustoClient, KustoConnectionStringBuilder } from "azure-kusto-data";
import { InteractiveBrowserCredentialInBrowserOptions } from "@azure/identity";
Note
For Node.js apps, use InteractiveBrowserCredentialNodeOptions instead of InteractiveBrowserCredentialInBrowserOptions.
public class HelloKusto
{
public static void main(String[] args) throws Exception {
try {
}
}
}
Create a connection string builder object that defines the cluster URI and sets the authentication mode to interactive. For more information about the cluster URI, see Kusto connection strings.
var clusterUri = "https://help.chinaeast2.kusto.chinacloudapi.cn/";
var kcsb = new KustoConnectionStringBuilder(clusterUri).WithAadUserPromptAuthentication();
The clientId and redirectUri are from the Microsoft Entra app registration you created in the Prerequisites section of Set up your development environment.
For interactive authentication, you need a Microsoft account or a Microsoft Entra user identity. An Azure subscription isn't required.
In C#, the interactive authentication process may not prompt the user if:
The user is already authenticated on the device
There is an existing Kusto.Explorer or Azure Date Explorer web UI authentication on the device
Create a client object that uses the connection string builder object to connect to the cluster.
Note
We highly recommended that you cache and reuse the Kusto client instance. Frequently recreating Kusto clients may lead to performance degradation in your application and increased load on your cluster.
The query output is returned in the response as an object that contains one or more tables, comprised of one more more rows and columns.
The format of the object depends on the client library language.
The print kusto query returns a single table with one row and column.
Use the GetString() method to get the value of the first column
The response in the primary results JSON object. The object contains an array of tables, which in turn contains an array of rows. Each row contains data organized into a dictionary of columns. You can reference the result, as follows:
The first array index [0] references the first table
The second array index [0] references the first row
The dictionary key ["Welcome"] references the Welcome column
The response is a KustoOperationResult object. You can reference the result, as follows:
Use the getPrimaryResults() method to get the primary results table