Skip to main content

Python SDK for interacting with Digital Product Passport (DPP) System Infrastructure

Project description

dpp-sdk (Python)

Python SDK for Digital Product Passports (DPP), built on Pydantic v2.

It provides typed models, validation, and JSON transport for digital product passports, plus HTTP clients for the two DPP backend APIs:

  • the DPP registry — hosted by the European Commission, and
  • the DPP repository — hosted by economic operators or service providers.

Both APIs conform to the draft standardisation documents published by CEN/CENELEC.

Install

pip install dpp-sdk

Requires Python 3.11+.

Quickstart

Parse, validate, serialize

from dpp_sdk import from_json, to_json, validate_dpp4fun

# Parse an incoming passport (accepts both flat and nested JSON shapes)
dpp = from_json(raw_json)

# Validate against the DPP rule set (raises on violations)
validate_dpp4fun(dpp)

# Serialize back to the flattened wire JSON
payload = to_json(dpp)

Full lifecycle

This builds a passport from typed models, validates it, stores it in the repository, registers it with the registry, then reads, updates, and deletes it. It runs as-is against the local mock services — see Testing against the mock services to start them first.

from datetime import date
from uuid import uuid4

from dpp_sdk import (
    Address, BillOfMaterials, Characteristics, Contact, Dimensions,
    Documentation, Dpp4Fun, Dpp4FunJsonCodec, DppCore, DppValidationError,
    Email, Material, Nameplate, Organization, OrganizationRole,
    PassportMetadata, ProductClassification, validate_dpp4fun,
)
from dpp_sdk.clients import (
    DppRegistryClient, DppRepoClient, RegisterDppRequest, local_repo_base_url,
)

# 1. Build a passport from typed, validated models.
manufacturer = Organization(
    name="ACME Furniture GmbH",
    gln="4012345000009",
    role=OrganizationRole.MANUFACTURER,
    contact=Contact(
        organization="ACME HQ",
        address=Address(country="DE", town="Berlin", street="Hauptstr. 1", zipCode="10115"),
        email=Email(emailAddress="info@acme.example", typeOfEmail="business"),
    ),
)

dpp = Dpp4Fun(
    coreDpp=DppCore(
        passportMetadata=PassportMetadata(
            uniqueProductIdentifier=uuid4(),            # drives dpp.dpp_id
            passportUpdateDates=[date.today()],
            qrCodeOrDigitalTag="QR-001",
        ),
        nameplate=Nameplate(
            gtinCode="GTIN-0001",                       # drives dpp.product_id
            internalArticleNumber="ART-1",
            manufacturer=manufacturer,
        ),
        documentation=Documentation(
            digitalInstructionsLink="https://acme.example/docs",
            downloadable=True,
            availableForYears=10,
        ),
    ),
    classification=ProductClassification(
        sector="Furniture", category="Office Chair", group="Seating",
        tags=["ergonomic", "adjustable"],
    ),
    characteristics=Characteristics(
        productName="ErgoChair Pro", productType="Office Chair", brand="ACME",
        dimensions=Dimensions(width=60.0, height=120.0, depth=60.0, unit="cm"),
        weight=14.5, features=["lumbar-support"],
    ),
    billOfMaterials=BillOfMaterials(
        materials=[
            Material(name="steel", mandatory=True, portion=0.6, reference="MAT-STEEL"),
            Material(name="foam", portion=0.4),
        ],
    ),
)

# 2. Validate against the full DPP rule set (collects all violations, then raises).
try:
    validate_dpp4fun(dpp)
except DppValidationError as exc:
    raise SystemExit(f"passport is invalid: {exc}")

# 3. Connect the clients. (Swap for_local_mock() for the explicit-URL constructors in prod.)
repo = DppRepoClient.for_local_mock(Dpp4FunJsonCodec(), validate_dpp4fun)
registry = DppRegistryClient.for_local_mock()
assert repo.health_check() and registry.health_check(), "start the mock services first"

# 4. Store the passport in the repository (POST /dpps -> dppId).
created = repo.create_dpp(dpp)
print("stored:", created.dppId)

# 5. Register it with the registry. The registry verifies the repo reference,
#    so the passport must already exist in the repo.
registered = registry.post_new_dpp_to_registry(
    RegisterDppRequest(
        productIdentifier=dpp.product_id,
        dppIdentifier=dpp.dpp_id,
        operatorIdentifier="operator-123",
        repoUrl=local_repo_base_url(),
    )
)
print("registered:", registered.registryIdentifier)

# 6. Read it back — by id and by product id.
fetched = repo.read_dpp_by_id(dpp.dpp_id)
assert repo.read_dpp_by_product_id(dpp.product_id).dpp_id == dpp.dpp_id

# 7. Update a single curated element (PATCH /dpps/{id}/elements/{path}).
repo.update_data_element(dpp.dpp_id, "characteristics.productName", "ErgoChair Pro 2")

# 8. Soft-delete the passport (DELETE /dpps/{id}).
repo.delete_dpp_by_id(dpp.dpp_id)

HTTP clients

The httpx-based clients for the registry and repository APIs live in dpp_sdk.clients.

In production, pass the real endpoint of each service explicitly:

from dpp_sdk.clients import DppRegistryClient, DppRepoClient
from dpp_sdk.dpp4fun import Dpp4FunJsonCodec, validate_dpp4fun

repo = DppRepoClient(
    "https://repo.example.com",
    codec=Dpp4FunJsonCodec(),
    validator=validate_dpp4fun,
)
registry = DppRegistryClient("https://registry.example.com")

Testing against the mock services

The companion CIR4FUN-EU/dpp-sdk project ships runnable mock services (mock-dpp-repo, mock-eu-registry) so you can integration-test your application against real REST endpoints. Start them with the provided docker-compose.yml:

git clone https://github.com/CIR4FUN-EU/dpp-sdk.git
cd dpp-sdk/dpp-sdk-demo
docker compose up --build      # repo on :8080, registry on :8081

Then point the clients at them with the for_local_mock() factories:

repo = DppRepoClient.for_local_mock(Dpp4FunJsonCodec(), validate_dpp4fun)
registry = DppRegistryClient.for_local_mock()

# Verify the services are up before exercising them (GET /health):
assert repo.health_check() and registry.health_check()

for_local_mock() defaults to the mock endpoints http://localhost:8080 (repo) and http://localhost:8081 (registry). Override them without code changes via environment variables — either the port or a full base URL:

Variable Default Overrides
DPP_REPO_PORT / DPP_REGISTRY_PORT 8080 / 8081 the port on localhost
DPP_REPO_BASE_URL / DPP_REGISTRY_BASE_URL the whole base URL (takes precedence)

Or pass an explicit override directly: DppRepoClient.for_local_mock(codec, validator, base_url="http://localhost:9000"). The defaults are also exposed as DEFAULT_REPO_BASE_URL / DEFAULT_REGISTRY_BASE_URL and the helpers local_repo_base_url() / local_registry_base_url() in dpp_sdk.clients.

Packages

Package Purpose
dpp_sdk.core Core DPP model, validation, and JSON transport
dpp_sdk.dpp4fun Furniture-specific DPP aggregate
dpp_sdk.clients HTTP clients for the DPP registry & repository APIs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dpp_sdk-0.2.1.tar.gz (27.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dpp_sdk-0.2.1-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file dpp_sdk-0.2.1.tar.gz.

File metadata

  • Download URL: dpp_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 27.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dpp_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 dc71f30dab55c5184a469ec38913051e14841f215e8dbc212b3495fe370138bc
MD5 14e19dc83124ebee11fffa3c7ba5ae9b
BLAKE2b-256 302c8afe57ca706d3855586991d236d57af57d3460a59529334800f2f0a691c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for dpp_sdk-0.2.1.tar.gz:

Publisher: release.yml on CIR4FUN-EU/dpp-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dpp_sdk-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: dpp_sdk-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 28.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dpp_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f9ef120a1cfc223540c21a27e48629a7db2c5f13486a435dbc26c5678005636
MD5 45afa22a17c7dd95613bb3c689d0fb04
BLAKE2b-256 bfeeb274250ccd1341f6c11330d80f9f2a155a15396f67e8f3c7790870b73c0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for dpp_sdk-0.2.1-py3-none-any.whl:

Publisher: release.yml on CIR4FUN-EU/dpp-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page