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

# Python SDK

> Profound API 向けの公式 Python SDK をインストールして使用します

Python SDK は PyPI で [profound](https://pypi.org/project/profound/) として公開されています。

## インストール

```bash Install the package wrap theme={null}
pip install profound
```

## クイックスタート

```python Create a client and run a report expandable wrap theme={null}
from profound import Profound

client = Profound(
    api_key="your-api-key-here"  # or set PROFOUND_API_KEY env var
)

# Get organization categories
categories = client.organizations.categories.list()
print(categories)

# Generate a report
report = client.reports.visibility(
    category_id=categories[0]['id'],
    start_date="2024-01-01",
    end_date="2024-01-31",
    dimensions=["asset_name"],
    metrics=["visibility_score"]
)
print(report)
```

## 認証

SDK は、次のいずれかから API キーを読み込みます：

1. **環境変数**（推奨）：環境に `PROFOUND_API_KEY` を設定します。
2. **コンストラクターのパラメーター**：クライアントの初期化時に `api_key` を渡します。

```bash Set the environment variable wrap theme={null}
export PROFOUND_API_KEY="your-api-key-here"
```

API キーの取得方法について詳しくは、[認証](/ja-jp/rest-api/authentication) を参照してください。

## エラー処理

```python Catch API errors expandable wrap theme={null}
from profound import Profound, APIError

client = Profound()

try:
    report = client.reports.visibility(
        category_id="invalid-id",
        start_date="2024-01-01",
        end_date="2024-01-31",
        dimensions=["asset_name"],
        metrics=["visibility_score"]
    )
except APIError as e:
    print(f"API Error: {e.status_code} - {e.message}")
```

## レート制限

API のデフォルトの制限は、API キーごとに 1 時間あたり 600 リクエストです。この制限を超えると、`429 Too Many Requests` エラーが返されます。SDK はエラーを送出するので、それをキャッチして処理できます。

```python Handle rate limits wrap theme={null}
from profound import RateLimitError

try:
    report = client.reports.visibility(...)
except RateLimitError as e:
    print("Rate limit exceeded. Please wait before retrying.")
```

## 非同期サポート

SDK は同期・非同期の両方の使い方に対応しています：

```python Synchronous and asynchronous clients expandable wrap theme={null}
# Synchronous
from profound import Profound
client = Profound()
categories = client.organizations.categories.list()

# Asynchronous
from profound import AsyncProfound
import asyncio

async def main():
    client = AsyncProfound()
    categories = await client.organizations.categories.list()

asyncio.run(main())
```

## コード例

API ドキュメントのすべてのエンドポイントには、動作する Python のサンプルが含まれています。REST API & SDKs タブの **Endpoints** セクションで、次の内容を扱う例を参照できます：

* 組織の管理
* カテゴリーの検出
* レポートの生成
* 生データへのアクセス

<Tip>
  API の改善に伴い、SDK のインターフェースが変更される場合があります。本番環境では特定のバージョンに固定してください。
</Tip>
