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

> Python SDK में India DPDP suite: client.dpdp.scan / evaluate / emit / require / evidence / sessions / timers, plus system audit।

<Info>
  **Concept:** [India DPDP guide](/concepts/india-dpdp) | **API:** [India DPDP overview](/api-reference/dpdp-overview)
</Info>

हर DPDP endpoint `client.dpdp` पर एक typed method के रूप में उपलब्ध है। Sub-client automatically attach होता है — एक `RailScoreClient` construct करें और `client.dpdp.*` के लिए reach करें। Async client (`AsyncRAILClient`) `await client.dpdp.*` पर same methods को expose करता है।

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

## Indian PII के लिए content को scan करें

Aadhaar (Verhoeff-validated), PAN, UPI, mobile, और अन्य को detect करें, plus child signals (S.9) और purpose drift (S.4)। `detect`, `mask`, या `block` choose करें।

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

## एक decision को gate करें

`evaluate` एक deterministic verdict return करता है — `allow`, `block`, या `require_action` — action के लिए जो आप लेने वाले हैं।

```python theme={null}
decision = client.dpdp.evaluate(
    action="make_decision",
    context={"user_id": "u_42", "purpose": "loan_advisory"},
    session_id="sess_1a2b3c",  # optional, decision को session से tie करता है
)

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

## Events को record करें

`emit` 1–50 compliance events को write करता है और किसी भी statutory timers को auto-start करता है जो वह trigger करते हैं (उदाहरण के लिए, `dsr.received` response clock को start करता है)।

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

## एक workflow step के लिए required actions

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

## Sessions

एक session एक data principal की journey को thread करता है। `create_session` को एक `purpose` require है — SDK अगर यह empty है तो immediately एक `ValueError` raise करता है (यह एक round trip को waste नहीं करेगा)।

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

## Timers

Regulatory deadline timers को list करें, status, type, या कितने जल्दी वह due हैं के आधार पर filter करें।

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

## Evidence (Pro+)

Session के recorded trail से एक audit-grade packet को assemble करें।

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

## System audit

`dpdp_audit` एक system description की एक tiered compliance assessment को run करता है, entity-specific context और penalty-exposure scoring के साथ। यह hosted compliance check को wrap करता है, तो यह **hosted-only** है।

```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 जब pointed एक self-hosted agent पर जो audit को serve नहीं करता।
    print("dpdp_audit runs against the hosted API only.")
```

<Warning>
  `dpdp_audit` और underlying compliance check **hosted** API पर ही उपलब्ध हैं। एक self-hosted RAIL agent के against SDK एक raw 404/501 की जगह `DPDPHostedOnlyError` raise करता है।
</Warning>

## Error handling

DPDP methods standard SDK errors को raise करते हैं (`AuthenticationError`, `RateLimitError`, `InsufficientTierError` for `evidence` जो Pro से नीचे है) plus DPDP-specific ones।

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

## Related

<CardGroup cols={2}>
  <Card title="DPDP API reference" icon="shield-halved" href="/api-reference/dpdp-overview">
    हर endpoint, credit costs, और response envelope।
  </Card>

  <Card title="Configuration" icon="gear" href="/sdk/python/configuration">
    अपने application के policy, plan capabilities, और dimensions को inspect करें।
  </Card>
</CardGroup>
