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

# Quickstart

# はじめに

本記事では、OuterportのPython SDKを使用して、OuterportのAPIを呼び出す方法を説明します。

## インストール

OuterportのPython SDKはPyPI（Python Package Index）からインストールできます。

<CodeGroup>
  ```bash pip
  pip install outerport
  ```

  ```bash uv
  uv add outerport
  ```
</CodeGroup>

## クライアントの初期化

OuterportのPython SDKを使用するにaは、まずOuterportのAPIキーを取得する必要があります。

<Warning>
  現時点ではOuterport APIはまだInvite Onlyとなっています。APIキーをリクエストするには[こちら](mailto:support@outerport.com)からお問い合わせください。
</Warning>

APIキーを取得したら、次のようにクライアントを初期化します。

```python
from outerport import OuterportClient

client = OuterportClient(api_key="your_api_key")
```

### 自己環境でOuterport APIを使用する場合

自己環境でホスティングされたOuterport APIを使用する場合は、`base_url`をホスティングされたAPIのURLに設定します。

```python
client = OuterportClient(
    api_key="your_api_key",
    base_url="http://localhost:8080"
)
```

## 基本的な使い方

### ドキュメントのアップロード

OuterportのPython SDKを使用して、ドキュメントをアップロードする方法を説明します。

```python
with open("document.pdf", "rb") as f:
    doc = client.documents.create(file=f)
```

`client.documents.create`メソッドは、`Document`オブジェクトを返します。

<Note>
  Outerport Python SDKは、基本的に「リソース」を作ると、オブジェクトを返します。リターンされるオブジェクトはクライアントと繋がっているので、`reload()`メソッドを呼び出すことで最新のデータを取得したり、`delete()`メソッドを呼び出すことで削除することができます。
</Note>

### ドキュメントに対して質問をする

OuterportのPython SDKを使用して、ドキュメントに対して質問をする方法を説明します。

```python
question = client.questions.create(
    document_ids=[doc.id],
    question="弊社のパスワードポリシーについて教えてください"
)
```

`client.questions.create`メソッドがリターンされると、質問の答えが`question.final_answer`に格納されます。

<CodeGroup>
  ```python Print Final Answer
  print(question.final_answer)
  ```

  ```json Final Answer
  "パスワードポリシーはパスワードの長さが8文字以上であることです。"
  ```
</CodeGroup>

`question.final_answer`の他にも、質問を答える為の「プラニング」と「リサーチ」の過程が`question.plan`と`question.evidences`に格納されます。例えば、`question.evidences`は以下のような結果が得られます。

<CodeGroup>
  ```python Print Evidences
  print(question.evidences)
  ```

  ```json Evidences
  [
      {
          "id": 1,
          "evidence": "パスワードの長さは8文字以上であることが要求されています。",
          "reasoning": "この引用はパスワードポリシーについて説明しています。",
          "document_id": 1,
          "sequence_number": 1
      }
  ]
  ```
</CodeGroup>

### ドキュメントの検索

関連性の高そうなドキュメントをクエリから検索する事も可能です。

```python
documents = client.documents.search(query="Explain the password policy")
```

`client.documents.search`メソッドは、`Document`オブジェクトのリストを返します。

タグやフォルダーを指定して検索する事も可能です。

```python
documents = client.documents.search(
    query="Explain the password policy", 
    tag="security"
)
```
