Skip to main content

ddigraph

CI codecov PyPI Downloads Docs License Python Neo4j DDI Code style Type checking pre-commit Buy Me a Coffee

A modern Python toolkit that transforms DDI (Data Documentation Initiative) XML metadata into knowledge graphs. Supports DDI Codebook and DDI-L FragmentInstance formats with streaming parsing, batched writes, and full async I/O across multiple graph backends.

Documentation | Getting Started | PyPI | Source Code


Features

  • Neo4j and RDF -- load into Neo4j, or read and write RDF with a documented, versioned vocabulary aligned to DISCO, SKOS and XKOS
  • File export -- ddigraph export writes Turtle, JSON-LD, N-Triples, RDF/XML, JSON or CSV with no database involved
  • SHACL shapes -- generated from the same schema that builds the Neo4j constraints, so they cannot drift
  • Preview before you load -- ddigraph preview summarises a file as text, Mermaid, or one self-contained HTML page
  • Streaming XML processing -- Memory-bounded iterparse for files of any size
  • Batched writes -- UNWIND-based Cypher for 10-100x fewer database round trips
  • Async I/O -- Concurrent parsing and writing with back-pressure control
  • Format auto-detection -- identifies DDI Codebook, DDI-L and DDI-CDI input
  • Unified schema -- Single source of truth for all node and relationship definitions
  • Adapter pattern -- Plug in custom graph backends via GraphWriteAdapter protocol
  • Production-ready -- Retry logic, observability hooks, pydantic-based configuration

Quick Start

Install

pip install ddigraph

Load DDI metadata (CLI)

# Set Neo4j connection
export DDIGRAPH_NEO4J_URI=bolt://localhost:7687
export DDIGRAPH_NEO4J_USER=neo4j
export DDIGRAPH_NEO4J_PASSWORD=secret

# Bootstrap schema and load data (format is auto-detected)
ddigraph bootstrap
ddigraph load survey.xml --dataset-id my-survey

Load DDI metadata (Python)

import ddigraph

ddigraph.bootstrap(target="bolt://localhost:7687")
result = ddigraph.load("survey.xml", target="bolt://localhost:7687")
print(result.nodes_written, "nodes,", result.relationships_written, "relationships")

Export without a database

import ddigraph

result = ddigraph.export("survey.xml", "survey.ttl", format="turtle")
print(result.triples, "triples")

Supported Formats

Format Description Use Case
DDI Codebook Traditional flat format with central Dataset node Survey archives, data catalogs
DDI-L FragmentInstance Lifecycle 3.x format with reusable fragments Questionnaire design, CAPI/CAWI instruments
DDI-CDI 1.0 Cross-Domain Integration metadata Data integration, statistical production

XSD Coverage

ddigraph ships with 100 % coverage of every concrete identifiable element declared in the bundled XSD schemas (schemas/). Coverage is enforced by the audit script and a pytest guardrail so new schema releases surface any gaps:

Flavor Scope Target Covered
DDI-L 3.x Concrete Maintainable + Versionable + Identifiable elements 189 100 %
DDI-C 2.x Codebook elements with the GLOBALS attribute group (no layout tags) 73 100 %
DDI-CDI 1.0 Concrete top-level entity elements (associations excluded) 210 100 %

Run python scripts/xsd_coverage.py to regenerate the audit or python scripts/xsd_coverage.py --json for machine-readable output.

Supported Backends

Backend Status Install
Neo4j Shipped. Read and write, all three DDI flavors base install
RDF/SPARQL Shipped. Read and write, SHACL shapes ddigraph[rdf]
JSON / CSV Shipped. Export only base install
Gremlin Shipped. Write, idempotent upserts ddigraph[gremlin]
NetworkX Shipped. In-memory graph ddigraph[networkx]
pandas Shipped. Node and relationship DataFrames ddigraph[pandas]

Every backend reads DDI XML of all three flavors, or an RDF export:

from ddigraph.backends.networkx import to_networkx
from ddigraph.backends.pandas import to_dataframes

G = to_networkx("survey.xml")
frames = to_dataframes("survey.ttl")

To feed a store ddigraph does not cover, use ddigraph.iter_graph(), which yields backend-neutral nodes and relationships for any DDI flavor.

Docker Quick Start

docker run --rm --name neo4j-demo \
  -p 7474:7474 -p 7687:7687 \
  -e NEO4J_AUTH=neo4j/password \
  neo4j:5

export DDIGRAPH_NEO4J_URI=bolt://localhost:7687
export DDIGRAPH_NEO4J_USER=neo4j
export DDIGRAPH_NEO4J_PASSWORD=password

ddigraph bootstrap
ddigraph load your-file.xml --dataset-id demo

Documentation

Full documentation is available at pbisson44.github.io/ddigraph in English and French.

Development

git clone https://github.com/pbisson44/ddigraph.git
cd ddigraph
pip install -e ".[dev,docs]"

ruff check . && ruff format .
mypy .
pytest
mkdocs serve

License

MIT -- see LICENSE for details.

Metadata

Release files for ddigraph 0.5.1

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

Source distribution (sdist)

Source distribution for ddigraph 0.5.1
File Size Uploaded Provenance Actions
ddigraph-0.5.1.tar.gz 1.2 MB With provenance Details for ddigraph-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ddigraph 0.5.1
File Interpreter ABI Platform Actions
ddigraph-0.5.1-py3-none-any.whl Python 3 none any Details for ddigraph-0.5.1-py3-none-any.whl

Total release size: 2.5 MB

Release files / ddigraph-0.5.1.tar.gz

Download URL ddigraph-0.5.1.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
23fc2bea41743f548dafafe4fddd9d061a74885dabbe510adf755078dc5bcda4
BLAKE2b-256 checksum
How to use checksums
d1f3accec94a8670b5ebc751c68deed61b1fbd6338bcb27cc76b76a6157197bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 4, 2026.

Transparency log

Release files / ddigraph-0.5.1-py3-none-any.whl

Download URL ddigraph-0.5.1-py3-none-any.whl
Size 1.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
763b06ad42df5378b6e0678045b3e821d6002858b8a3e270942e60a70091f83e
BLAKE2b-256 checksum
How to use checksums
f2ed6f9af6496af0913cb3419311991d9f74b3661552b384d33b17e3fc51dffb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 4, 2026.

Transparency log

Security for ddigraph 0.5.1

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ddigraph-0.5.1.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 Oct 4, 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