Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

dpdpkit-fastapi

FastAPI adapter for dpdpkit. It adds consent, versioned notices, rights requests and retention to your FastAPI app, with tables in your own database. This is the reference implementation of the dpdpkit REST contract.

Disclaimer. dpdpkit is software that helps you implement obligations under India's Digital Personal Data Protection Act, 2023 and the DPDP Rules, 2025. It does not provide legal advice and does not guarantee compliance. Decisions about notices, purposes, retention and incident reporting must be made by you or your counsel.

Install

pip install "dpdpkit[fastapi]"                          # or: pip install dpdpkit-fastapi
pip install "dpdpkit-fastapi[scheduler,postgres]"       # APScheduler + psycopg

Quickstart

dpdpkit init            # writes dpdpkit.yaml: purposes, notice text, contact details
from fastapi import Depends, FastAPI
from dpdpkit.fastapi import DPDPKit, require_consent

app = FastAPI()
dpdp = DPDPKit(
    db_url=settings.DATABASE_URL,
    config="dpdpkit.yaml",  # policy pack, purposes, notice
    principal_resolver=lambda request: request.state.user.id,  # stable id, no personal data
    admin_guard=lambda request: "admin" if request.state.user.is_staff else None,
    signing_key=settings.DPDPKIT_SIGNING_KEY,  # signs consent receipts
    contact_resolver=lookup_contact,  # principal -> Contact(email=..., phone=...)
    notifier=SmtpNotifier("smtp.example.in", sender="privacy@example.in"),
)
dpdp.install(app, prefix="/dpdp")  # router + error handlers + activity middleware + admin


@dpdp.kit.retention.register_handler
def erase(principal: str, purposes: list[str]) -> None: ...  # delete or anonymise your own rows


@app.post("/offers/send", dependencies=[Depends(require_consent("marketing"))])
async def send_offer(): ...
dpdpkit migrate --db-url "$DATABASE_URL"        # Alembic migrations shipped in the package

Run the scheduler in one process (or call dpdpkit retention run from cron):

dpdp.start_scheduler(retention_minutes=15)  # retention run + daily ledger verification and root-hash export

In an async app, pass your AsyncEngine (or an async db_url). Call kit methods with await dpdp.run(...), or inside your own AsyncSession so consent changes commit or roll back with your writes:

dpdp = DPDPKit(engine=async_engine, principal_resolver=current_user, config="dpdpkit.yaml")

async with AsyncSession(async_engine) as s, s.begin():
    s.add(Order(user_id=user_id))
    await dpdp.run_in_session(s, dpdp.kit.consent.grant, user_id, "marketing")

Sync apps use with dpdp.bind(session): ... the same way.

The step-by-step guide is the FastAPI quickstart.

What you get

Component Detail
SqlAlchemyRepository SQLAlchemy 2.0; Postgres, MySQL, SQLite; accepts async URLs and AsyncEngine, joins your Session or AsyncSession; microsecond timestamps so ledger hashes survive round trips
Migrations Alembic, forward-only, shipped in the package (dpdpkit migrate)
Router Full REST contract from dpdpkit-spec
require_consent() Dependency returning 403 consent_required with the purpose
Roles admin_guard returns viewer, handler or admin
Scheduler APScheduler ([scheduler] extra); Celery and Arq entry points in v0.5
Webhooks Database outbox: signed, retried with backoff, dead letters with dpdpkit webhooks retry
Activity middleware Records activity, restarting inactivity clocks and cancelling warned erasures
Admin mount Serves the admin dashboard at <prefix>/admin/ui/ (a source checkout has a placeholder page)

Example

examples/fastapi_shop is a small shop with consent, requests and erasure handlers. It passes the conformance suite:

cd examples/fastapi_shop
uvicorn app:app --reload                                  # http://localhost:8000/docs
DPDPKIT_CONFORMANCE=1 DPDPKIT_ASGI_APP=app:app dpdpkit-conformance

Licence

Apache-2.0.

Metadata

Release files for dpdpkit-fastapi 0.1.0a3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dpdpkit-fastapi 0.1.0a3
File Size Uploaded Provenance Actions
dpdpkit_fastapi-0.1.0a3.tar.gz 197.1 kB With provenance Details for dpdpkit_fastapi-0.1.0a3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dpdpkit-fastapi 0.1.0a3
File Interpreter ABI Platform Actions
dpdpkit_fastapi-0.1.0a3-py3-none-any.whl Python 3 none any Details for dpdpkit_fastapi-0.1.0a3-py3-none-any.whl

Total release size: 392.4 kB

Release files / dpdpkit_fastapi-0.1.0a3.tar.gz

Download URL dpdpkit_fastapi-0.1.0a3.tar.gz
Size 197.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dbaee91cb2bfa866049f753e32f1f829df40f640f6ac7843be801e246b507211
BLAKE2b-256 checksum
How to use checksums
ee8b3c5145bc3a0606900c7b8edf0664c6e967e557704e26a8c27fb60c2078b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / dpdpkit_fastapi-0.1.0a3-py3-none-any.whl

Download URL dpdpkit_fastapi-0.1.0a3-py3-none-any.whl
Size 195.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d94c9bfaab56103bec876f3cfdb95031df8e83ca47384db8f7bb6aeef6c59ec
BLAKE2b-256 checksum
How to use checksums
cf487a898a9b5f2979263988e590f643808d6ca768c804fecf74ad1baa3b482f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Security for dpdpkit-fastapi 0.1.0a3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dpdpkit_fastapi-0.1.0a3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page