> ## 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: Indien DPDP

> Die Indien DPDP Suite im Python SDK: client.dpdp.scan / evaluate / emit / require / evidence / sessions / timers, plus das System-Audit.

<Info>
  **Konzept:** [Indien DPDP Leitfaden](/concepts/india-dpdp) | **API:** [Indien DPDP Übersicht](/api-reference/dpdp-overview)
</Info>

Jeder DPDP Endpoint ist als typisierte Methode auf `client.dpdp` verfügbar. Der Sub-Client wird automatisch angehängt — konstruieren Sie einen `RailScoreClient` und greifen Sie auf `client.dpdp.*`. Der Async-Client (`AsyncRAILClient`) zeigt die gleichen Methoden auf `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["proceed"]
    E --> T["client.dpdp.list_timers(status='active')"]
    T --> EVD["client.dpdp.evidence(type, params)"]
```

## Scannen Sie Inhalte auf indische PII

Erkennen Sie Aadhaar (Verhoeff-validiert), PAN, UPI, Mobilfunk und mehr, plus Kindersignale (S.9) und Zweckabweichung (S.4). Wählen Sie `detect`, `mask` oder `block`.

<CodeGroup>
  ```python Detect 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 Mask theme={null}
  result = client.dpdp.scan(
      "Aadhaar 2341 5678 9012 on file.",
      pii_action="mask",
  )
  print(result.content_masked)
  ```
</CodeGroup>

## Gate eine Entscheidung

`evaluate` gibt ein deterministisches Urteil zurück — `allow`, `block` oder `require_action` — für die Aktion, die Sie durchführen werden.

```python theme={null}
decision = client.dpdp.evaluate(
    action="make_decision",
    context={"user_id": "u_42", "purpose": "loan_advisory"},
    session_id="sess_1a2b3c",  # optional, ties the decision to a session
)

if decision.verdict == "require_action":
    print("Outstanding obligations:", decision.required_actions)
```

## Ereignisse aufzeichnen

`emit` schreibt 1–50 Compliance-Ereignisse und startet automatisch alle gesetzlichen Timer, die sie auslösen (beispielsweise startet `dsr.received` die Antwortuhr).

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

## Erforderliche Aktionen für einen Workflow-Schritt

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

## Sitzungen

Eine Sitzung verbindet die Reise eines Datenhauptlings. `create_session` erfordert einen `purpose` — das SDK wirft sofort `ValueError`, wenn es leer ist (es wird die Reise nicht verschwenden).

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

## Timer

Listen Sie regulatorische Fristen-Timer auf, gefiltert nach Status, Typ oder wie bald sie fällig sind.

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

## Nachweise (Pro+)

Stellen Sie ein Audit-taugliches Paket aus der erfassten Spur der Sitzung zusammen.

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

## System-Audit

`dpdp_audit` führt eine abgestuften Compliance-Bewertung einer Systembeschreibung mit entitätsspezifischem Kontext und Strafen-Exponierung-Scoring durch. Es umhüllt die gehostete Compliance-Prüfung, daher ist es **gehostet-nur**.

```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:
    # Raised when pointed at a self-hosted agent that does not serve the audit.
    print("dpdp_audit runs against the hosted API only.")
```

<Warning>
  `dpdp_audit` und die zugrunde liegende Compliance-Prüfung sind nur auf der **gehosteten** API verfügbar. Gegen einen selbstgehosteten RAIL Agent wirft das SDK stattdessen `DPDPHostedOnlyError`.
</Warning>

## Fehlerbehandlung

Die DPDP Methoden werfen die Standard-SDK-Fehler (`AuthenticationError`, `RateLimitError`, `InsufficientTierError` für `evidence` unter Pro) plus DPDP-spezifische.

```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("Check your API key")
except RateLimitError:
    print("Slow down requests")
```

## Verwandt

<CardGroup cols={2}>
  <Card title="DPDP API Referenz" icon="shield-halved" href="/api-reference/dpdp-overview">
    Jeder Endpoint, Kreditkosten und die Response Envelope.
  </Card>

  <Card title="Konfiguration" icon="gear" href="/sdk/python/configuration">
    Überprüfen Sie die Richtlinie, Plan-Fähigkeiten und Dimensionen Ihrer Anwendung.
  </Card>
</CardGroup>
