Code Generator
Code generator transforming CDIF profile schemas and vocabularies into dartfx-rdf models.
- class dartfx.cdif.codegen.LoadedArtifacts(cdif_root, context, schemas=<factory>, composite_schemas=<factory>, provenance_activities=<factory>)[source]
Bases:
objectContainer holding all parsed upstream CDIF artifacts.
- Parameters:
cdif_root (Path)
context (dict[str, Any])
schemas (dict[str, dict[str, Any]])
composite_schemas (dict[str, dict[str, Any]])
provenance_activities (list[ActivityConcept])
- cdif_root: Path
- context: dict[str, Any]
- schemas: dict[str, dict[str, Any]]
- composite_schemas: dict[str, dict[str, Any]]
- provenance_activities: list[ActivityConcept]
- class dartfx.cdif.codegen.ProfileSpec(key, module_name, root_class_name, mixin_class_name, profile_uris, schema_path, frame_path, shacl_path, base_classes=('CdifBaseModel',), description='')[source]
Bases:
objectMetadata describing a CDIF profile and its upstream artifact paths.
- Parameters:
key (str)
module_name (str)
root_class_name (str | None)
mixin_class_name (str | None)
profile_uris (tuple[str, ...])
schema_path (str)
frame_path (str)
shacl_path (str)
base_classes (tuple[str, ...])
description (str)
- key: str
- module_name: str
- root_class_name: str | None
- mixin_class_name: str | None
- profile_uris: tuple[str, ...]
- schema_path: str
- frame_path: str
- shacl_path: str
- base_classes: tuple[str, ...] = ('CdifBaseModel',)
- description: str = ''
- dartfx.cdif.codegen.default_models_output_dir()[source]
Return the default
src/dartfx/cdif/modelsoutput directory.- Return type:
Path
- dartfx.cdif.codegen.emit_modules(modules, output_dir)[source]
Write all resolved
ModuleIRfiles and package__init__.pyfiles.- Parameters:
modules (list[ModuleIR])
output_dir (Path)
- Return type:
list[Path]
- dartfx.cdif.codegen.generate_all(cdif_root=None, output_dir=None)[source]
Load upstream CDIF profile definitions and generate Python model modules.
- Parameters:
cdif_root (Path | str | None) – Path to the local
git-cdifdirectory. Defaults toresolve_cdif_root().output_dir (Path | str | None) – Destination directory for generated modules. Defaults to
src/dartfx/cdif/models.
- Returns:
Paths of all generated Python files.
- Return type:
list[Path]
- dartfx.cdif.codegen.load_artifacts(cdif_root, specs=(ProfileSpec(key='core', module_name='core', root_class_name='CdifCoreDataset', mixin_class_name=None, profile_uris=('https://w3id.org/cdif/core/2.0', 'https://w3id.org/cdif/core/1.1', 'https://w3id.org/cdif/core/1.0'), schema_path='profile-core/cdifCoreStructuredSchema.json', frame_path='profile-core/cdifCore-frame.jsonld', shacl_path='validation/ShaclValidation/CDIF-Discovery-Shapes.ttl', base_classes=('CdifBaseModel',), description='CDIF Core metadata profile (schema:Dataset).'), ProfileSpec(key='discovery', module_name='discovery', root_class_name='CdifDiscoveryDataset', mixin_class_name='CdifDiscoveryMixin', profile_uris=('https://w3id.org/cdif/discovery/2.0', 'https://w3id.org/cdif/discovery/1.1', 'https://w3id.org/cdif/discovery/1.0'), schema_path='profile-discovery/cdifDiscoveryStructuredSchema.json', frame_path='profile-discovery/cdifDiscovery-frame.jsonld', shacl_path='validation/ShaclValidation/CDIF-Discovery-Shapes.ttl', base_classes=('CdifCoreDataset', 'CdifDiscoveryMixin'), description='CDIF Discovery profile extending Core with measurement, variable, spatial, temporal, and quality.'), ProfileSpec(key='data_description', module_name='datadescription', root_class_name='CdifDataDescriptionDataset', mixin_class_name='CdifDataDescriptionMixin', profile_uris=('https://w3id.org/cdif/data_description/2.0', 'https://w3id.org/cdif/data_description/1.1', 'https://w3id.org/cdif/data_description/1.0'), schema_path='profile-datadescription/cdifDataDescriptionStructuredSchema.json', frame_path='profile-datadescription/cdifDataDescription-frame.jsonld', shacl_path='validation/ShaclValidation/CDIF-DataDescription-Shapes.ttl', base_classes=('CdifDiscoveryDataset', 'CdifDataDescriptionMixin'), description='CDIF Data Description profile extending Discovery with variableMeasured, physical mapping, and stats.'), ProfileSpec(key='data_structure', module_name='datastructure', root_class_name=None, mixin_class_name=None, profile_uris=('https://w3id.org/cdif/data_structure/2.0', 'https://w3id.org/cdif/data_structure/1.1', 'https://w3id.org/cdif/data_structure/1.0'), schema_path='profile-datastructure/cdifDataStructureStructuredSchema.json', frame_path='profile-datastructure/CDIFDataStructure-frame.jsonld', shacl_path='validation/ShaclValidation/CDIF-DataStructure-Shapes.ttl', base_classes=(), description='CDIF Data Structure profile (DDI-CDI structural components, keys, and represented variables).'), ProfileSpec(key='provenance', module_name='provenance', root_class_name='CdifProvenanceDataset', mixin_class_name='CdifProvenanceMixin', profile_uris=('https://w3id.org/cdif/provenance/2.0', 'https://w3id.org/cdif/provenance/1.1', 'https://w3id.org/cdif/provenance/1.0'), schema_path='profile-provenance/cdifProvenanceStructuredSchema.json', frame_path='profile-provenance/cdifProvenance-frame.jsonld', shacl_path='validation/ShaclValidation/CDIF-Provenance-Shapes.ttl', base_classes=('CdifCoreDataset', 'CdifProvenanceMixin'), description='CDIF Provenance profile extending Core with prov:wasGeneratedBy activities, instruments, and HowTo plans.'), ProfileSpec(key='manifest', module_name='manifest', root_class_name='CdifManifestDataset', mixin_class_name='CdifManifestMixin', profile_uris=('https://w3id.org/cdif/manifest/2.0', 'https://w3id.org/cdif/manifest/1.1', 'https://w3id.org/cdif/manifest/1.0'), schema_path='profile-manifest/cdifManifestStructuredSchema.json', frame_path='profile-manifest/cdifManifest-frame.jsonld', shacl_path='validation/ShaclValidation/CDIF-Manifest-Shapes.ttl', base_classes=('CdifCoreDataset', 'CdifManifestMixin'), description='CDIF Manifest profile extending Core with package schema:hasPart resources and archive parts.'), ProfileSpec(key='codelist', module_name='codelist', root_class_name='CdifCodelist', mixin_class_name=None, profile_uris=('https://w3id.org/cdif/codelist/2.0', 'https://w3id.org/cdif/codelist/1.1', 'https://w3id.org/cdif/codelist/1.0'), schema_path='profile-codelist/CDIFCodelistProfileStructuredSchema.json', frame_path='profile-codelist/CDIFCodelist-frame.jsonld', shacl_path='profile-codelist/rules.shacl', base_classes=('CdifBaseModel',), description='CDIF Codelist profile (skos:ConceptScheme / schema:DefinedTermSet).'), ProfileSpec(key='complete', module_name='complete', root_class_name='CdifCompleteDataset', mixin_class_name=None, profile_uris=('https://w3id.org/cdif/complete/2.0', 'https://w3id.org/cdif/complete/1.1', 'https://w3id.org/cdif/complete/1.0', 'https://w3id.org/cdif/bbr/metadata/profiles/cdifCompositeProfile/cdifComplete'), schema_path='validation/CDIFCompleteSchema.json', frame_path='validation/CDIF-frame-2026.jsonld', shacl_path='validation/ShaclValidation/CDIF-Complete-Shapes.ttl', base_classes=('CdifDataDescriptionDataset', 'CdifProvenanceMixin', 'CdifManifestMixin'), description='CDIF Complete composite profile combining Core, Discovery, Data Description, Provenance, and Manifest.')))[source]
Load all CDIF schemas, context, and vocabularies from
cdif_root.- Parameters:
cdif_root (Path)
specs (tuple[ProfileSpec, ...])
- Return type:
- dartfx.cdif.codegen.render_module(mod)[source]
Render a
ModuleIRinto formatted Python source code.- Parameters:
mod (ModuleIR)
- Return type:
str
- dartfx.cdif.codegen.resolve_cdif_root(cdif_root=None)[source]
Resolve the local
git-cdifdirectory path.Resolution order: 1. Explicit
cdif_rootargument. 2.CDIF_ROOTenvironment variable. 3. Siblinggit-cdifdirectory next togit-dartfx(monorepo layout).- Parameters:
cdif_root (Path | str | None)
- Return type:
Path
- dartfx.cdif.codegen.resolve_modules(artifacts)[source]
Resolve loaded CDIF schemas and vocabularies into
ModuleIRobjects.- Parameters:
artifacts (LoadedArtifacts)
- Return type:
list[ModuleIR]
Configuration
Configuration and profile specifications for the CDIF code generator.
- class dartfx.cdif.codegen.config.ProfileSpec(key, module_name, root_class_name, mixin_class_name, profile_uris, schema_path, frame_path, shacl_path, base_classes=('CdifBaseModel',), description='')[source]
Bases:
objectMetadata describing a CDIF profile and its upstream artifact paths.
- Parameters:
key (str)
module_name (str)
root_class_name (str | None)
mixin_class_name (str | None)
profile_uris (tuple[str, ...])
schema_path (str)
frame_path (str)
shacl_path (str)
base_classes (tuple[str, ...])
description (str)
- key: str
- module_name: str
- root_class_name: str | None
- mixin_class_name: str | None
- profile_uris: tuple[str, ...]
- schema_path: str
- frame_path: str
- shacl_path: str
- base_classes: tuple[str, ...] = ('CdifBaseModel',)
- description: str = ''
- dartfx.cdif.codegen.config.default_models_output_dir()[source]
Return the default
src/dartfx/cdif/modelsoutput directory.- Return type:
Path
- dartfx.cdif.codegen.config.resolve_cdif_root(cdif_root=None)[source]
Resolve the local
git-cdifdirectory path.Resolution order: 1. Explicit
cdif_rootargument. 2.CDIF_ROOTenvironment variable. 3. Siblinggit-cdifdirectory next togit-dartfx(monorepo layout).- Parameters:
cdif_root (Path | str | None)
- Return type:
Path
Artifact Loader
Loaders for upstream CDIF JSON Schemas, JSON-LD contexts, and RDF vocabularies.
- class dartfx.cdif.codegen.loader.ActivityConcept(uri, notation, pref_label)[source]
Bases:
objectA provenance activity concept extracted from
CDIF_Activities.ttl.- Parameters:
uri (str)
notation (str)
pref_label (str)
- uri: str
- notation: str
- pref_label: str
- class dartfx.cdif.codegen.loader.LoadedArtifacts(cdif_root, context, schemas=<factory>, composite_schemas=<factory>, provenance_activities=<factory>)[source]
Bases:
objectContainer holding all parsed upstream CDIF artifacts.
- Parameters:
cdif_root (Path)
context (dict[str, Any])
schemas (dict[str, dict[str, Any]])
composite_schemas (dict[str, dict[str, Any]])
provenance_activities (list[ActivityConcept])
- cdif_root: Path
- context: dict[str, Any]
- schemas: dict[str, dict[str, Any]]
- composite_schemas: dict[str, dict[str, Any]]
- provenance_activities: list[ActivityConcept]
- dartfx.cdif.codegen.loader.load_artifacts(cdif_root, specs=(ProfileSpec(key='core', module_name='core', root_class_name='CdifCoreDataset', mixin_class_name=None, profile_uris=('https://w3id.org/cdif/core/2.0', 'https://w3id.org/cdif/core/1.1', 'https://w3id.org/cdif/core/1.0'), schema_path='profile-core/cdifCoreStructuredSchema.json', frame_path='profile-core/cdifCore-frame.jsonld', shacl_path='validation/ShaclValidation/CDIF-Discovery-Shapes.ttl', base_classes=('CdifBaseModel',), description='CDIF Core metadata profile (schema:Dataset).'), ProfileSpec(key='discovery', module_name='discovery', root_class_name='CdifDiscoveryDataset', mixin_class_name='CdifDiscoveryMixin', profile_uris=('https://w3id.org/cdif/discovery/2.0', 'https://w3id.org/cdif/discovery/1.1', 'https://w3id.org/cdif/discovery/1.0'), schema_path='profile-discovery/cdifDiscoveryStructuredSchema.json', frame_path='profile-discovery/cdifDiscovery-frame.jsonld', shacl_path='validation/ShaclValidation/CDIF-Discovery-Shapes.ttl', base_classes=('CdifCoreDataset', 'CdifDiscoveryMixin'), description='CDIF Discovery profile extending Core with measurement, variable, spatial, temporal, and quality.'), ProfileSpec(key='data_description', module_name='datadescription', root_class_name='CdifDataDescriptionDataset', mixin_class_name='CdifDataDescriptionMixin', profile_uris=('https://w3id.org/cdif/data_description/2.0', 'https://w3id.org/cdif/data_description/1.1', 'https://w3id.org/cdif/data_description/1.0'), schema_path='profile-datadescription/cdifDataDescriptionStructuredSchema.json', frame_path='profile-datadescription/cdifDataDescription-frame.jsonld', shacl_path='validation/ShaclValidation/CDIF-DataDescription-Shapes.ttl', base_classes=('CdifDiscoveryDataset', 'CdifDataDescriptionMixin'), description='CDIF Data Description profile extending Discovery with variableMeasured, physical mapping, and stats.'), ProfileSpec(key='data_structure', module_name='datastructure', root_class_name=None, mixin_class_name=None, profile_uris=('https://w3id.org/cdif/data_structure/2.0', 'https://w3id.org/cdif/data_structure/1.1', 'https://w3id.org/cdif/data_structure/1.0'), schema_path='profile-datastructure/cdifDataStructureStructuredSchema.json', frame_path='profile-datastructure/CDIFDataStructure-frame.jsonld', shacl_path='validation/ShaclValidation/CDIF-DataStructure-Shapes.ttl', base_classes=(), description='CDIF Data Structure profile (DDI-CDI structural components, keys, and represented variables).'), ProfileSpec(key='provenance', module_name='provenance', root_class_name='CdifProvenanceDataset', mixin_class_name='CdifProvenanceMixin', profile_uris=('https://w3id.org/cdif/provenance/2.0', 'https://w3id.org/cdif/provenance/1.1', 'https://w3id.org/cdif/provenance/1.0'), schema_path='profile-provenance/cdifProvenanceStructuredSchema.json', frame_path='profile-provenance/cdifProvenance-frame.jsonld', shacl_path='validation/ShaclValidation/CDIF-Provenance-Shapes.ttl', base_classes=('CdifCoreDataset', 'CdifProvenanceMixin'), description='CDIF Provenance profile extending Core with prov:wasGeneratedBy activities, instruments, and HowTo plans.'), ProfileSpec(key='manifest', module_name='manifest', root_class_name='CdifManifestDataset', mixin_class_name='CdifManifestMixin', profile_uris=('https://w3id.org/cdif/manifest/2.0', 'https://w3id.org/cdif/manifest/1.1', 'https://w3id.org/cdif/manifest/1.0'), schema_path='profile-manifest/cdifManifestStructuredSchema.json', frame_path='profile-manifest/cdifManifest-frame.jsonld', shacl_path='validation/ShaclValidation/CDIF-Manifest-Shapes.ttl', base_classes=('CdifCoreDataset', 'CdifManifestMixin'), description='CDIF Manifest profile extending Core with package schema:hasPart resources and archive parts.'), ProfileSpec(key='codelist', module_name='codelist', root_class_name='CdifCodelist', mixin_class_name=None, profile_uris=('https://w3id.org/cdif/codelist/2.0', 'https://w3id.org/cdif/codelist/1.1', 'https://w3id.org/cdif/codelist/1.0'), schema_path='profile-codelist/CDIFCodelistProfileStructuredSchema.json', frame_path='profile-codelist/CDIFCodelist-frame.jsonld', shacl_path='profile-codelist/rules.shacl', base_classes=('CdifBaseModel',), description='CDIF Codelist profile (skos:ConceptScheme / schema:DefinedTermSet).'), ProfileSpec(key='complete', module_name='complete', root_class_name='CdifCompleteDataset', mixin_class_name=None, profile_uris=('https://w3id.org/cdif/complete/2.0', 'https://w3id.org/cdif/complete/1.1', 'https://w3id.org/cdif/complete/1.0', 'https://w3id.org/cdif/bbr/metadata/profiles/cdifCompositeProfile/cdifComplete'), schema_path='validation/CDIFCompleteSchema.json', frame_path='validation/CDIF-frame-2026.jsonld', shacl_path='validation/ShaclValidation/CDIF-Complete-Shapes.ttl', base_classes=('CdifDataDescriptionDataset', 'CdifProvenanceMixin', 'CdifManifestMixin'), description='CDIF Complete composite profile combining Core, Discovery, Data Description, Provenance, and Manifest.')))[source]
Load all CDIF schemas, context, and vocabularies from
cdif_root.- Parameters:
cdif_root (Path)
specs (tuple[ProfileSpec, ...])
- Return type:
- dartfx.cdif.codegen.loader.load_provenance_activities(ttl_path)[source]
Parse
CDIF_Activities.ttlinto sortedActivityConceptentries.- Parameters:
ttl_path (Path)
- Return type:
list[ActivityConcept]
Schema Resolver
Resolve CDIF JSON Schemas, JSON-LD contexts, and RDF vocabularies into IR modules.
- dartfx.cdif.codegen.resolver.resolve_modules(artifacts)[source]
Resolve loaded CDIF schemas and vocabularies into
ModuleIRobjects.- Parameters:
artifacts (LoadedArtifacts)
- Return type:
list[ModuleIR]
Intermediate Representation
Intermediate Representation (IR) data structures for the CDIF code generator.
- class dartfx.cdif.codegen.ir.EnumIR(name, docstring='', values=<factory>)[source]
Bases:
objectRepresents a generated
StrEnumcontrolled vocabulary.- Parameters:
name (str)
docstring (str)
values (list[tuple[str, str]])
- name: str
- docstring: str = ''
- values: list[tuple[str, str]]
- class dartfx.cdif.codegen.ir.TypeAliasIR(name, target_expr, docstring='')[source]
Bases:
objectRepresents a module-level Python type alias.
- Parameters:
name (str)
target_expr (str)
docstring (str)
- name: str
- target_expr: str
- docstring: str = ''
- class dartfx.cdif.codegen.ir.FieldIR(python_name, alias, predicate_expr, type_annotation, description='', is_required=False, datatype_expr=None)[source]
Bases:
objectRepresents a Pydantic +
RdfPropertymodel field.- Parameters:
python_name (str)
alias (str)
predicate_expr (str | None)
type_annotation (str)
description (str)
is_required (bool)
datatype_expr (str | None)
- python_name: str
- alias: str
- predicate_expr: str | None
- type_annotation: str
- description: str = ''
- is_required: bool = False
- datatype_expr: str | None = None
- class dartfx.cdif.codegen.ir.ClassIR(name, docstring='', base_classes=<factory>, rdf_types=<factory>, fields=<factory>, profile_uri=None, required_fields=<factory>, any_of_required=<factory>, is_mixin=False, forbid_extra=False)[source]
Bases:
objectRepresents a generated
CdifBaseModelclass or profile mixin.- Parameters:
name (str)
docstring (str)
base_classes (list[str])
rdf_types (list[str])
fields (list[FieldIR])
profile_uri (str | None)
required_fields (list[str])
any_of_required (list[list[str]])
is_mixin (bool)
forbid_extra (bool)
- name: str
- docstring: str = ''
- base_classes: list[str]
- rdf_types: list[str]
- profile_uri: str | None = None
- required_fields: list[str]
- any_of_required: list[list[str]]
- is_mixin: bool = False
- forbid_extra: bool = False
- class dartfx.cdif.codegen.ir.ModuleIR(name, rel_path, docstring='', prefix_vars=<factory>, extra_imports=<factory>, enums=<factory>, type_aliases=<factory>, classes=<factory>, exports=<factory>)[source]
Bases:
objectRepresents a Python module to emit under
src/dartfx/cdif/models/.- Parameters:
name (str)
rel_path (str)
docstring (str)
prefix_vars (set[str])
extra_imports (list[str])
enums (list[EnumIR])
type_aliases (list[TypeAliasIR])
classes (list[ClassIR])
exports (list[str])
- name: str
- rel_path: str
- docstring: str = ''
- prefix_vars: set[str]
- extra_imports: list[str]
- type_aliases: list[TypeAliasIR]
- exports: list[str]
Code Emitter
Code emitter converting resolved ModuleIR objects into Python modules.