Skip to content
Accessibility palettes

ddi-l

ddi-l is a Python library for creating, reading, updating and validating DDI Lifecycle 3.3 XML documents. You work with studies, questions and variables as Python objects, and ddi-l writes and checks the XML.

Quick start

import ddi_l as ddi

# Create a new study
doc = ddi.new_study(title="Household Survey", agency="example.org")

# Add questions
q = doc.add_question(text="How old are you?")

# Add variables linked to questions
doc.add_variable(name="Age", question=q)

# Save to XML
doc.save("household-survey.xml")
# Open an existing study
doc = ddi.open_ddi("household-survey.xml")

for v in doc.variables:
    print(v.identifier)

Install

Install ddi-l with pip or Poetry. The full extra adds the faster lxml backend (see Installation).

pip install ddi-l
poetry add ddi-l
poetry run ddi --help

Where to go next

The site also has a 16-module training curriculum, an API reference and a models reference. To contribute, see the development guide and the contributor guide.