> ## 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.

# Python を Insights に接続する

> Microsoft Entra ID 認証を使用して、Azure Kusto Python SDK で Python および Jupyter Notebooks からレガシー PlayFab Insights のゲーム データをクエリします。

# チュートリアル: Python を Insights に接続する

このガイドは、Python を Insights とともに使い始めるのに役立ちます。Azure Kusto Python SDK を使用します。接続後、Python でゲーム データをクエリし、Jupyter Notebooks からライブラリを使用できます。Insights に接続できる他のツールについては、[外部ツールを Insights に接続する](/services/playfab/data-analytics/legacy/connectivity) を参照してください。

<Note>
  PlayFab Insights Management は 2026/3/31 に廃止されました。今後のパフォーマンスとコストを管理するには、[Azure Data Explorer (ADX) Connections](/services/playfab/data-analytics/export-data/data-connection-adx) の使用をお勧めします。タイトルがまだ **Insights** を使用している場合は、実装の詳細についてこの記事を参照し続けてください。詳細については、[PlayFab Digest: 3 月の機能更新](https://developer.microsoft.com/en-us/games/articles/2026/04/playfab-digest-march-feature-updates/) を参照してください。
</Note>

## 前提条件

### Azure AD で認証された PlayFab アカウント

認証プロバイダーが Microsoft に設定されている PlayFab アカウントまたはユーザーが必要です。Microsoft 認証プロバイダーは、Azure サービスの使用に必要な認証に Azure Active Directory (Azure AD) を使用します。Azure AD で認証されたアカウントまたはユーザーの作成手順については、[Game Manager 用の Azure Active Directory 認証](/services/playfab/identity/dev-identity/authentication/aad-authentication) を参照してください。

アカウントまたはユーザーが Microsoft 認証プロバイダーを使用するように設定されていることを確認するには:

* PlayFab の [ログイン ページ](https://developer.playfab.com) にアクセスします。
* **\[Sign in with Microsoft]** を選択して PlayFab アカウントにアクセスします。

サインインできれば、そのアカウントは Microsoft 認証プロバイダーを使用するように設定されています。

### Insights の Game Manager 権限

アカウントに、次の Game Manager 権限が有効になっている [ユーザー ロール](/services/playfab/identity/dev-identity/permissions/playfab-user-roles) を割り当てる必要があります:

* 管理者ステータス。
* Explorer タブおよび関連データへのアクセス。
* Analytics データへの読み取りおよび書き込みアクセス。

新しいユーザー ロールを作成するか、既存のロールにこれらの権限を追加することができます。

### その他の前提条件

* [Azure Active Directory (AAD) アプリケーションを作成し、タイトル データベースに接続する](/services/playfab/data-analytics/legacy/connectivity/creating-AAD-app-for-insights)

## Python パッケージのインストール

1. [pip](https://pypi.org/project/pip/) を使用して、次の Python パッケージをインストールします:
   * azure-kusto-data
   * azure-kusto-ingest
   * adal
2. 以下は、開始するためのサンプル スクリプトです。

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

## 関連リソース

* [Azure Kusto Python SDK ドキュメント](https://learn.microsoft.com/en-us/azure/data-explorer/kusto/api/python/kusto-python-client-library)
* Insights に接続する他のツールについては、[外部ツールを Insights に接続する](/services/playfab/data-analytics/legacy/connectivity) を参照してください。


## Related topics

- [外部ツールと Insights の接続](/ja-jp/services/playfab/data-analytics/legacy/connectivity/index.md)
- [Grafana を Insights に接続する](/ja-jp/services/playfab/data-analytics/legacy/connectivity/connecting-grafana-to-insights.md)
- [Kusto C# SDK を Insights に接続する](/ja-jp/services/playfab/data-analytics/legacy/connectivity/connecting-kusto-csharp-to-insights.md)
- [Kusto Explorer を Insights に接続する](/ja-jp/services/playfab/data-analytics/legacy/connectivity/connecting-kusto-explorer-to-insights.md)
- [Power BI を Insights に接続する](/ja-jp/services/playfab/data-analytics/legacy/connectivity/connecting-power-bi-to-insights.md)
