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 bundle (placeholder page until v0.4)

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.0a2

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.0a2
File Size Uploaded Provenance Actions
dpdpkit_fastapi-0.1.0a2.tar.gz 45.3 kB With provenance Details for dpdpkit_fastapi-0.1.0a2.tar.gz

Built distribution (wheel)

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

Total release size: 85.8 kB

Release files / dpdpkit_fastapi-0.1.0a2.tar.gz

Download URL dpdpkit_fastapi-0.1.0a2.tar.gz
Size 45.3 kB
Tags Source
SHA-256 checksum
How to use checksums
56a4aefe440e17190c8421b1e2b2b2da05175fbb04c146436a763d7676794eb6
BLAKE2b-256 checksum
How to use checksums
ffb5f25ad44e530998dd0c2ce4840568dbfead5b3a4ec90d8f4f7bf29b868064
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 2, 2026.

Transparency log

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

Download URL dpdpkit_fastapi-0.1.0a2-py3-none-any.whl
Size 40.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4254390595463e1a6269465ae4bae42e9f138f95df1c2b7956bcbf2ca8d9f59
BLAKE2b-256 checksum
How to use checksums
bdb1d02201fbe5a108c68ffd843034a713b217c5973502837aeab1f1885aaff2
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 2, 2026.

Transparency log

Security for dpdpkit-fastapi 0.1.0a2

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.0a2.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 2, 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