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 Example script in demo/, not part of the package ddigraph[gremlin]
NetworkX Example script in demo/, not part of the package ddigraph[networkx]
pandas Example script in demo/, not part of the package ddigraph[pandas]

demo/ scripts ship in neither the wheel nor the source distribution. They are worked examples of driving another store from the parser tier, not supported backends. To build your own, 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.

Download files

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

Source Distribution

ddigraph-0.5.0.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

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

ddigraph-0.5.0-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file ddigraph-0.5.0.tar.gz.

File metadata

  • Download URL: ddigraph-0.5.0.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ddigraph-0.5.0.tar.gz
Algorithm Hash digest
SHA256 cbb93c7b8a679becbdde41a9ec648df28c7e80787f9be73ca6a5cd684893f1c1
MD5 d8a44bec84301feb2634dd9923d4a62f
BLAKE2b-256 041ebd06de5ad1cfb86f5935831c1d8b623194327493150f7e7f554cf9fb5e33

See more details on using hashes here.

Provenance

The following attestation bundles were made for ddigraph-0.5.0.tar.gz:

Publisher: publish.yml on pbisson44/ddigraph

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

File details

Details for the file ddigraph-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: ddigraph-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ddigraph-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 283940ba7f3c76c05b25b318a45631f72cfd3cb69fad516f36b18faad3557185
MD5 d0c2ba33f890d47094ce5104e9559fe5
BLAKE2b-256 9e5b608607c0cd1bf565fe0e4f1e87a5dfefbb20a3752363c008c9052e920a01

See more details on using hashes here.

Provenance

The following attestation bundles were made for ddigraph-0.5.0-py3-none-any.whl:

Publisher: publish.yml on pbisson44/ddigraph

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

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

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