dpdpguard-python-sdk
DPDP Guard Server SDK (Python) — typed API client, consent gate, token broker
helper, audit-hash verifier, and webhook signature verifier over DPDP Guard's
public /api/v1 (spec §4.2).
PyPI distribution: dpdpguard-sdk · Import as: dpdpguard
Part of the DPDP Guard SDK family. See the design spec: https://github.com/chintans/dpdpbot/blob/main/docs/specs/mobile-server-sdk.md
This SDK mirrors @dpdpguard/server
(the Node/TypeScript reference implementation) method for method, so behavior —
auth modes, idempotency headers, error codes, audit-hash canonicalization — stays
identical across ecosystems (ADR-001's audit-uniformity goal).
Install
pip install dpdpguard-sdk
Usage
import os
from dpdpguard import DpdpGuardClient, has_consent, verify_webhook_signature
client = DpdpGuardClient(
"https://<your-deployment>.convex.site",
api_key=os.environ["DPDP_SERVICE_API_KEY"], # convex/apiKeys.ts, for broker_token() only
)
# Mint a brokered principal access token (ADR-004 D1/D2) for a known user.
client.broker_token(external_id)
# Now authenticated calls use that token automatically.
result = client.list_dsr_requests()
client.create_dsr_request(organization_id=org_id, type="erasure")
# Public reads need no auth at all.
org = client.get_organization("acme")
notices = client.get_notices(org["orgId"])
# Verify an inbound webhook (convex/webhooks.ts's X-DPDP-Signature header).
ok = verify_webhook_signature(webhook_secret, raw_body, request.headers.get("x-dpdp-signature"))
Use it as a context manager to close the underlying httpx.Client automatically:
with DpdpGuardClient(base_url) as client:
org = client.get_organization("acme")
Every non-2xx response raises a DpdpGuardApiError with a code from the
ADR-002 error catalog (err.code, e.g. "NOT_FOUND") and the HTTP status.
Consent gate
from dpdpguard import has_consent
if not has_consent(consents, "Marketing"):
return # don't send the campaign
Audit-hash verification
A holder of the platform's DPDP_AUDIT_HASH_HMAC_SECRET can independently
verify a consentAuditTrail row's auditHash:
from dpdpguard import AuditHashInput, compute_audit_hash
input = AuditHashInput(
organization_id="org_abc123",
notice_id="notice_v1",
notice_version=1,
purpose="Newsletter",
data_types=["email"],
given_at=1700000000000,
source="direct",
)
assert compute_audit_hash(input, secret) == stored_audit_hash
Contract
This package vendors its wire contract from dpdpbot's single source of
truth (ADR-001/002) rather than depending on a published @dpdpguard/contract
Python package (none exists yet):
src/dpdpguard/models.pyis hand-kept in sync withopenapi/v1.yaml'scomponents.schemas.src/dpdpguard/errors.pyloads_data/error-catalog.json, vendored verbatim from@dpdpguard/contract/conformance/error-catalog.json(ADR-002 D2).tests/test_audit_hash.pyruns_data/audit-hash-vectors.json(vendored from@dpdpguard/contract/conformance/audit-hash-vectors.json) as a required CI gate (ADR-002 D5) — a failure means this SDK'saudit_hash.pyhas drifted fromconvex/lib/auditHash.ts.
Development
pip install -e ".[dev]"
ruff check .
mypy src
pytest --cov=src --cov-report=term-missing
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dpdpguard_sdk-1.0.0.tar.gz.
File metadata
- Download URL: dpdpguard_sdk-1.0.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbd77d404358c68308d33069cc5c7e7109b04b82bbc34a854f3eec755259371f
|
|
| MD5 |
2b195a68dcdc3838ef115f77533fd6ff
|
|
| BLAKE2b-256 |
3d691e9dc89b5e944563facff2d9eace8f73c1680501bf40d2ebd4057caba01f
|
Provenance
The following attestation bundles were made for dpdpguard_sdk-1.0.0.tar.gz:
Publisher:
publish.yml on dpdp-guard-ai/dpdpguard-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dpdpguard_sdk-1.0.0.tar.gz -
Subject digest:
fbd77d404358c68308d33069cc5c7e7109b04b82bbc34a854f3eec755259371f - Sigstore transparency entry: 2289558813
- Sigstore integration time:
-
Permalink:
dpdp-guard-ai/dpdpguard-python-sdk@05c1b96e343ec3a50c06fffbaa5f68a0a9c6cb04 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/dpdp-guard-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@05c1b96e343ec3a50c06fffbaa5f68a0a9c6cb04 -
Trigger Event:
release
-
Statement type:
File details
Details for the file dpdpguard_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: dpdpguard_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b456a1a60ba596e066a1060d5847dd2f8af012feabc64ecd454780e6965ab13
|
|
| MD5 |
3cf05ebe710fe6e4056ebd3e0cc134d9
|
|
| BLAKE2b-256 |
cfe7084ad654f1dccc8476744da090f63620e96f2e58a626e62ca1ec3bb8253e
|
Provenance
The following attestation bundles were made for dpdpguard_sdk-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on dpdp-guard-ai/dpdpguard-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dpdpguard_sdk-1.0.0-py3-none-any.whl -
Subject digest:
8b456a1a60ba596e066a1060d5847dd2f8af012feabc64ecd454780e6965ab13 - Sigstore transparency entry: 2289558866
- Sigstore integration time:
-
Permalink:
dpdp-guard-ai/dpdpguard-python-sdk@05c1b96e343ec3a50c06fffbaa5f68a0a9c6cb04 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/dpdp-guard-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@05c1b96e343ec3a50c06fffbaa5f68a0a9c6cb04 -
Trigger Event:
release
-
Statement type: