> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connecting Python to Insights

> Query legacy PlayFab Insights from Python and Jupyter Notebooks with the Azure Kusto Python SDK, using Microsoft Entra ID authentication for your game data.

# Tutorial: Connecting Python to Insights

This guide helps you get started using Python with Insights. It uses the Azure Kusto Python SDK. After connecting, you can query your game data with Python and use the library from Jupyter Notebooks. To learn more about other tools you can connect with Insights, see [Connecting external tools to Insights](/services/playfab/data-analytics/legacy/connectivity).

<Note>
  PlayFab Insights Management was retired on 3/31/2026. We recommend using [Azure Data Explorer (ADX) Connections](/services/playfab/data-analytics/export-data/data-connection-adx) to manage your performance and cost going forward. If your title is still using **Insights**, continue to see this article for implementation details. For more information, see [PlayFab Digest: March feature updates](https://developer.microsoft.com/en-us/games/articles/2026/04/playfab-digest-march-feature-updates/).
</Note>

## Prerequisites

### PlayFab account authenticated with Azure AD

You need a PlayFab account or user for which the authentication provider is set to Microsoft. The Microsoft authentication provider uses Azure Active Directory (Azure AD) for authentication which is required to use the Azure services. See [Azure Active Directory Authentication for Game Manager](/services/playfab/identity/dev-identity/authentication/aad-authentication) for instructions on creating an Azure AD-authenticated account or user.

To verify that the account, or user, is set to use the Microsoft authentication provider:

* Visit the PlayFab [log in page](https://developer.playfab.com).
* Select **Sign in with Microsoft** to access your PlayFab account.

If you can sign in, then the account is set to use the Microsoft authentication provider.

### Game Manager permissions for Insights

You need to assign your account a [user role](/services/playfab/identity/dev-identity/permissions/playfab-user-roles) with the following Game Manager permissions enabled:

* Admin status.
* Access to the Explorer tab and associated data.
* Read and write access to Analytics data.

You can either create a new user role or add these permissions to an existing role.

### Other prerequisites

* [Create an Azure Active Directory (AAD) application and connect it to your title database](/services/playfab/data-analytics/legacy/connectivity/creating-AAD-app-for-insights)

## Install Python packages

1. Install the following python packages using [pip](https://pypi.org/project/pip/):
   * azure-kusto-data
   * azure-kusto-ingest
   * adal
2. Below is an example script to get started with.

```python theme={null}
from azure.kusto.data.exceptions import KustoServiceError
from azure.kusto.data.request import KustoClient, KustoConnectionStringBuilder, ClientRequestProperties

from msal import ConfidentialClientApplication

cluster = "https://insights.playfab.com"

# These parameters are taken from your Azure app
client_id = "<Azure app client id>"
client_secret = "<Azure app client secret>" 
tenant = "<Azure app tenant id>"

authority_url = "https://login.microsoftonline.com/" + tenant

client_instance = ConfidentialClientApplication(
  client_id=client_id,
  client_credential=client_secret,
  authority=authority_url,
)

# Acquire a token from AAD to pass to PlayFab
_scopes = ["https://help.kusto.windows.net"]
token_response = client_instance.acquire_token_for_client(scopes=_scopes)

token = None
if token_response:
    if token_response['access_token']:
        token = token_response['access_token']

kcsb = KustoConnectionStringBuilder.with_aad_application_token_authentication(cluster, token)
client = KustoClient(kcsb)

db = "<title id>"
query = "['events.all'] | count"

# Force Kusto to use the v1 query endpoint
client._query_endpoint = cluster + "/v1/rest/query"

crp = ClientRequestProperties()
crp.application = "KustoPythonSDK"
response = client.execute(db, query)

# Response processing
print(response)
```

## Additional resources

* [Azure Kusto Python SDK documentation](https://learn.microsoft.com/en-us/azure/data-explorer/kusto/api/python/kusto-python-client-library)
* To learn about other tools to connect to Insights, see  [Connecting external tools to Insights](/services/playfab/data-analytics/legacy/connectivity)


## Related topics

- [Connecting external tools with Insights](/services/playfab/data-analytics/legacy/connectivity/index.md)
- [Connecting Grafana to Insights](/services/playfab/data-analytics/legacy/connectivity/connecting-grafana-to-insights.md)
- [Connecting Kusto C# SDK to Insights](/services/playfab/data-analytics/legacy/connectivity/connecting-kusto-csharp-to-insights.md)
- [Connecting Kusto Explorer to Insights](/services/playfab/data-analytics/legacy/connectivity/connecting-kusto-explorer-to-insights.md)
- [Connecting Power BI to Insights](/services/playfab/data-analytics/legacy/connectivity/connecting-power-bi-to-insights.md)
