Django integration

The Django adapter (pip install "dpdpstack-python-sdk[django]") runs the engine against your own models, with a database-backed audit store - still zero-egress, since the mutation happens on your instance in your database.

Setup

Add the app and migrate so the audit log has a table:

# settings.py
INSTALLED_APPS += ["dpdpstack.contrib.django"]
python manage.py migrate

Declare PII once with @pii

The @pii(...) decorator records each model's PII fields and how to anonymize them, so you don't pass pii_fields= on every call.

from django.db import models
from dpdpstack import null, redact
from dpdpstack.contrib.django.service import pii

@pii(name=null, email=null, phone=redact(keep_last=4))
class User(models.Model):
    name = models.CharField(max_length=120)
    email = models.EmailField()
    phone = models.CharField(max_length=20)
    external_ref = models.CharField(max_length=64)  # your opaque subject id

Erase an instance

erase_instance(instance, policy=..., subject=...) resolves the policy, performs the mutation on that instance, and appends to the audit log.

from dpdpstack import RetentionPolicy, Action, rbi_kyc
from dpdpstack.contrib.django.service import erase_instance

# Hard delete + audit
erase_instance(user, policy=RetentionPolicy(purpose="marketing", action=Action.DELETE),
               subject=user.external_ref)

# Anonymize PII, keep the (regulated) row - uses the @pii declaration above
erase_instance(user, policy=RetentionPolicy(purpose="profile", action=Action.ANONYMIZE),
               subject=user.external_ref)

# KYC withdrawal → deferred under the RBI hold; nothing deleted, basis recorded
erase_instance(user, policy=rbi_kyc("kyc"), subject=user.external_ref)

You can still override the fields for a single call with pii_fields={...} if a model needs something different from its @pii declaration.

Subjects stay opaque

Always pass an opaque subject (an external ref, a hashed id) - never the user's email or name. The audit log and certificates reference subjects by this id, which keeps PII out of your evidence trail.

Next