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

# Python: インド DPDP

> Python SDK のインド DPDP スイート: client.dpdp.scan / evaluate / emit / require / evidence / sessions / timers、システム監査付き。

<Info>
  **概念:** [インド DPDP ガイド](/concepts/india-dpdp) | **API:** [インド DPDP 概要](/api-reference/dpdp-overview)
</Info>

すべての DPDP エンドポイントは `client.dpdp` 上の型付きメソッドとして利用可能です。サブクライアントは自動的に付着します — `RailScoreClient` を構築して `client.dpdp.*` に到達します。非同期クライアント (`AsyncRAILClient`) は `await client.dpdp.*` で同じメソッドを公開します。

```python theme={null}
from rail_score_sdk import RailScoreClient

client = RailScoreClient(api_key="YOUR_RAIL_API_KEY")
scan = client.dpdp.scan("Applicant PAN ABCDE1234F", pii_action="mask")
```

```mermaid theme={null}
flowchart TD
    S["client.dpdp.create_session(purpose=...)"] --> E["client.dpdp.emit([...])"]
    E --> SC["client.dpdp.scan(content, pii_action=...)"]
    SC --> EV{"client.dpdp.evaluate(action, context)"}
    EV -- "require_action" --> RQ["client.dpdp.require(session_id, workflow_step)"]
    EV -- "allow" --> OK["進行"]
    E --> T["client.dpdp.list_timers(status='active')"]
    T --> EVD["client.dpdp.evidence(type, params)"]
```

## インド個人識別情報のコンテンツをスキャン

Aadhaar (Verhoeff 検証済み)、PAN、UPI、モバイル、その他を検出し、児童シグナル (S.9) と目的のずれ (S.4) を検出します。`detect`、`mask`、または `block` を選択します。

<CodeGroup>
  ```python 検出 theme={null}
  result = client.dpdp.scan(
      "Applicant PAN is ABCDE1234F and mobile 9876543210.",
      pii_action="detect",
      purpose="loan_advisory",
  )
  print(result.compliant, [p.type for p in result.pii_found])
  ```

  ```python マスク theme={null}
  result = client.dpdp.scan(
      "Aadhaar 2341 5678 9012 on file.",
      pii_action="mask",
  )
  print(result.content_masked)
  ```
</CodeGroup>

## 意思決定をゲート

`evaluate` は決定的な判定を返します — `allow`、`block`、または `require_action` — あなたが行おうとしているアクション向け。

```python theme={null}
decision = client.dpdp.evaluate(
    action="make_decision",
    context={"user_id": "u_42", "purpose": "loan_advisory"},
    session_id="sess_1a2b3c",  # オプション、決定をセッションに関連付ける
)

if decision.verdict == "require_action":
    print("未処理の義務:", decision.required_actions)
```

## イベントを記録

`emit` は 1–50 のコンプライアンスイベントを記録し、それらがトリガーする法定タイマーを自動開始します (例えば、`dsr.received` はレスポンスクロックを開始します)。

```python theme={null}
client.dpdp.emit(
    [
        {"type": "notice.shown", "data": {"user_id": "u_42"}},
        {"type": "consent.granted", "data": {"user_id": "u_42", "purpose": "loan_advisory"}},
    ],
    session_id="sess_1a2b3c",
)
```

## ワークフローステップの必要なアクション

```python theme={null}
required = client.dpdp.require(
    session_id="sess_1a2b3c",
    workflow_step="data_processing",
)
for action in required.required_actions:
    print(action)
```

## セッション

セッションは 1 つのデータ主体のジャーニーをまとめるスレッドです。`create_session` は `purpose` を必須とします — SDK は空の場合、ラウンドトリップを無駄にすることはなく、すぐに `ValueError` を発生させます。

```python theme={null}
session = client.dpdp.create_session(
    purpose="loan_advisory",
    entity_type="data_fiduciary",
)
fetched = client.dpdp.get_session(session.session_id)
print(fetched.state.consent_status)
```

## タイマー

ステータス、タイプ、または期限までの日数でフィルタリングされた規制期限タイマーをリストします。

```python theme={null}
timers = client.dpdp.list_timers(status="active", approaching_days=30)
print(timers.summary.total_active)
for t in timers.timers:
    print(t.type, t.days_remaining)
```

## 証拠 (Pro+)

セッションの記録された証跡から監査級パケットをアセンブルします。

```python theme={null}
packet = client.dpdp.evidence(
    evidence_type="dsr_response",
    params={"session_id": "sess_1a2b3c", "request_id": "r_9"},
)
```

## システム監査

`dpdp_audit` はシステム説明の段階的なコンプライアンス評価を実行し、エンティティ固有のコンテキストと罰則露出スコアリング付き。ホストされたコンプライアンスチェックをラップするため、**ホスト型のみ**。

```python theme={null}
from rail_score_sdk import DPDPHostedOnlyError

try:
    audit = client.dpdp.dpdp_audit(
        content="Our fintech processes Aadhaar for KYC; consent via checkbox.",
        entity_type="data_fiduciary",
        sector="finance",
    )
    print(audit.overall_label, audit.total_penalty_exposure_crore)
except DPDPHostedOnlyError:
    # ホストされていない監査を提供しない自社ホストエージェントを指していると発生します。
    print("dpdp_audit はホスト型 API に対してのみ実行されます。")
```

<Warning>
  `dpdp_audit` と基礎となるコンプライアンスチェックは**ホスト型** API 上でのみ利用可能です。自社ホスト RAIL エージェントに対しては、SDK は生の 404/501 の代わりに `DPDPHostedOnlyError` を発生させます。
</Warning>

## エラーハンドリング

DPDP メソッドは標準 SDK エラー (`AuthenticationError`、`RateLimitError`、Pro 以下の `evidence` 向け `InsufficientTierError`) と DPDP 固有のエラーを発生させます。

```python theme={null}
from rail_score_sdk import DPDPHostedOnlyError
from rail_score_sdk import AuthenticationError, RateLimitError

try:
    client.dpdp.scan("...", pii_action="block")
except AuthenticationError:
    print("API キーを確認してください")
except RateLimitError:
    print("リクエストを減速してください")
```

## 関連

<CardGroup cols={2}>
  <Card title="DPDP API リファレンス" icon="shield-halved" href="/api-reference/dpdp-overview">
    すべてのエンドポイント、クレジットコスト、レスポンスエンベロープ。
  </Card>

  <Card title="構成" icon="gear" href="/sdk/python/configuration">
    アプリケーションのポリシー、プラン機能、次元を検査します。
  </Card>
</CardGroup>
