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

# Python XDK

> X API v2 向け公式 Python XDK クライアントライブラリのインストールと使用方法。認証設定、ページネーション付きリクエスト、ストリーミングの例を含みます。

[Python XDK](https://github.com/xdevplatform/xdk-py) は X API v2 向けの公式クライアントライブラリです。認証、ページネーション、ストリーミングを処理してくれるため、構築に集中できます。

<Card title="GitHub リポジトリ" icon="github" href="https://github.com/xdevplatform/xdk-py">
  ソースコード、Issue、リリース。
</Card>

***

## インストール

```bash theme={null}
pip install xdk
```

Python 3.8 以上が必要です。

***

## クイックスタート

```python theme={null}
from xdk import Client

client = Client(bearer_token="YOUR_BEARER_TOKEN")

# Search for posts
for page in client.posts.search_recent(query="X API", max_results=10):
    if page.data and len(page.data) > 0:
        print(page.data[0].text)
        break
```

***

## 主な機能

| 機能                | 説明                                                          |
| :---------------- | :---------------------------------------------------------- |
| **OAuth サポート**    | Bearer Token、PKCE 付き OAuth 2.0、および OAuth 1.0a               |
| **自動ページネーション**    | 手動で `next_token` を扱わずに結果を反復処理                               |
| **ストリーミング**       | 永続接続によるリアルタイムデータ (filtered stream など)                       |
| **完全な API カバレッジ** | X API v2 のすべてのエンドポイント — search、timelines、filtered stream ほか |

***

## 認証

<Tabs>
  <Tab title="Bearer Token">
    ```python theme={null}
    from xdk import Client

    client = Client(bearer_token="YOUR_BEARER_TOKEN")
    ```
  </Tab>

  <Tab title="OAuth 2.0">
    ```python theme={null}
    from xdk import Client
    from xdk.oauth2_auth import OAuth2PKCEAuth

    auth = OAuth2PKCEAuth(
        client_id="YOUR_CLIENT_ID",
        redirect_uri="YOUR_CALLBACK_URL",
        scope="tweet.read users.read offline.access"
    )

    auth_url = auth.get_authorization_url()
    tokens = auth.fetch_token(authorization_response=callback_url)
    client = Client(bearer_token=tokens["access_token"])
    ```
  </Tab>

  <Tab title="OAuth 1.0a">
    ```python theme={null}
    from xdk import Client
    from xdk.oauth1_auth import OAuth1

    oauth1 = OAuth1(
        api_key="YOUR_API_KEY",
        api_secret="YOUR_API_SECRET",
        access_token="YOUR_ACCESS_TOKEN",
        access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
    )

    client = Client(auth=oauth1)
    ```
  </Tab>
</Tabs>

***

## よく使うメソッド

| カテゴリ       | メソッド                           |
| :--------- | :----------------------------- |
| **Posts**  | `client.posts.search_recent()` |
| **Users**  | `client.users.get_me()`        |
| **Spaces** | `client.spaces.get()`          |
| **Lists**  | `client.lists.get()`           |
| **DMs**    | `client.direct_messages.get()` |

***

## さらに詳しく

<CardGroup cols={2}>
  <Card title="インストール" icon="download" href="/xdks/python/install">
    開発用インストール、前提条件、動作確認。
  </Card>

  <Card title="クイックスタート" icon="rocket" href="/xdks/python/quickstart">
    ステップバイステップの初回リクエストのウォークスルー。
  </Card>

  <Card title="認証" icon="key" href="/xdks/python/authentication">
    すべての認証方法の詳細ガイド。
  </Card>

  <Card title="ページネーション" icon="arrows-left-right" href="/xdks/python/pagination">
    自動ページネーションとイテレーター。
  </Card>

  <Card title="ストリーミング" icon="satellite-dish" href="/xdks/python/streaming">
    filtered stream によるリアルタイムデータ。
  </Card>

  <Card title="API リファレンス" icon="book" href="/xdks/python/reference/modules">
    クライアントとモデルの完全リファレンス。
  </Card>
</CardGroup>

コード例については [samples リポジトリ](https://github.com/xdevplatform/samples/tree/main/python) を参照してください。
