Quickstart
This guide walks you through installing dartfx-cdif, loading CDIF documents, inspecting metadata fields, converting between JSON-LD and RDF graphs, and validating profile conformance.
Installation
dartfx-cdif requires Python 3.12+.
Using uv (Recommended)
uv add dartfx-cdif
Using pip
pip install dartfx-cdif
Loading a CDIF Document
CDIF metadata is commonly distributed as JSON-LD documents. The load_cdif() function automatically detects which CDIF profile the document matches and instantiates the corresponding typed model:
from dartfx.cdif import load_cdif
# Load directly from a file path or URL
dataset = load_cdif("examples/kaggle-iris.jsonld")
print(type(dataset).__name__)
# Output: CdifCoreDataset
print(f"Title: {dataset.name}")
print(f"Identifier: {dataset.identifier}")
print(f"License: {dataset.license}")
You can also pass raw JSON strings, Python dictionaries, or an existing rdflib.Graph:
import json
from dartfx.cdif import load_cdif
with open("my_dataset.jsonld", "r", encoding="utf-8") as f:
doc = json.load(f)
# Transparently parsed and matched
dataset = load_cdif(doc)
Accessing Typed Properties
Generated models provide clean, Pythonic attribute access with static type hints:
from dartfx.cdif import CdifCoreDataset
# If you know the profile in advance, load directly:
dataset = CdifCoreDataset.from_jsonld("examples/kaggle-iris.jsonld")
# Access core fields
print(dataset.id) # "@id" URI
print(dataset.name) # "schema:name"
print(dataset.description) # "schema:description"
print(dataset.date_modified)# "schema:dateModified"
# Complex nested structures are typed Pydantic models
if dataset.creator:
for creator in dataset.creator:
print(f"Creator: {creator.name} ({creator.id})")
Exporting Metadata
1. Framed JSON-LD
Export your model as a JSON-LD compliant dictionary or formatted JSON string:
# Export as Python dictionary with standard CDIF JSON-LD aliases
jsonld_dict = dataset.to_jsonld()
# Export as JSON string
json_str = dataset.model_dump_json(by_alias=True, indent=2)
The resulting JSON-LD document contains canonical CDIF aliases (schema:name, schema:description, schema:identifier) and default @context headers.
2. RDF Graph Round-Tripping
Convert any CDIF model directly into an rdflib.Graph:
# Convert to an rdflib.Graph
graph = dataset.to_rdf()
# Serialize to Turtle format
turtle_data = graph.serialize(format="turtle")
print(turtle_data[:500])
# Reconstitute the model from an RDF Graph
reloaded = CdifCoreDataset.from_rdf(graph, subject=dataset.id)
assert reloaded.name == dataset.name
Conformance Validation
CDIF profiles define mandatory fields and structural rules (e.g., core datasets must provide at least one persistent identifier, creator, description, and either a license or access conditions).
You can validate conformance at any time:
# Run CDIF normative profile conformance check
report = dataset.validate_conformance()
if report.is_valid:
print("Dataset complies fully with CDIF profile rules!")
else:
print("Conformance issues detected:")
for err in report.errors:
print(f" - [{err.rule_type}] {err.field_name}: {err.message}")
You can also validate unparsed JSON-LD dictionaries before instantiating models:
from dartfx.cdif import CdifCoreDataset
report = CdifCoreDataset.validate_conformance(jsonld_dict)
print(f"Valid: {report.is_valid}")
Creating a CDIF Dataset Programmatically
You can construct valid CDIF metadata programmatically using Python objects:
from dartfx.cdif import CdifCoreDataset
from dartfx.cdif.models.common import (
CatalogRecord,
Identifier,
ObjectReference,
Person,
)
# Instantiate a new CDIF Core Dataset
my_dataset = CdifCoreDataset(
id="https://doi.org/10.5061/dryad.example",
name="Marine Microplastic Abundance Surveys 2024",
description="Microplastic concentration measurements collected across Atlantic transects.",
identifier=Identifier(
property_id="https://registry.identifiers.org/registry/doi",
value="10.5061/dryad.example",
),
date_modified="2026-05-12",
license=["https://creativecommons.org/licenses/by/4.0/"],
url="https://example.org/datasets/marine-microplastics-2024",
creator=[
Person(
name="Dr. Jane Doe",
id="https://orcid.org/0000-0002-1825-0097",
)
],
subject_of=CatalogRecord(
id="https://example.org/records/dryad-example",
additional_type=[ObjectReference(id="dcat:CatalogRecord")],
conforms_to=[ObjectReference(id="https://w3id.org/cdif/core/1.1")],
),
jsonld_context=CdifCoreDataset.default_jsonld_context(),
)
# Verify conformance
assert my_dataset.validate_conformance().is_valid
# Save to disk as JSON-LD
with open("marine_dataset.jsonld", "w", encoding="utf-8") as f:
f.write(my_dataset.model_dump_json(by_alias=True, indent=2))
Using the CLI
dartfx-cdif includes a command-line tool cdif:
# List all registered CDIF profiles and models
cdif profiles
# Validate a JSON-LD or Turtle metadata file
cdif validate path/to/dataset.jsonld
# Validate against a specific profile
cdif validate path/to/dataset.jsonld --profile discovery
# Regenerate models from schema sources
cdif codegen --output-dir src/dartfx/cdif/models