Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
Unreleased
1.2.0 - 2026-10-26
Added
wait_for_ingestionpolls an ingestion execution until it finishes and returns its terminalIngestionExecutionState, including a failed or cancelled one. It raisesTimeoutErroronly when atimeoutis passed and runs out.TERMINAL_EXECUTION_STATESlists the states it stops on.UNAVAILABLEis not one of them: the execution may still be running, so polling continues and logs a warning with the newIngestionExecutionState.state_error.--waitondcp-tools ingestanddcp-tools pipelineblocks until the execution finishes and exits non-zero when it doesn't succeed or--timeoutruns out.--poll-intervalsets the seconds between checks. Both need--wait.
Changed
LOCAL_PATHandGCS_OUTPUT_FOLDER_PATHare optional.upload_to_cloud_storagewithout adirectoryandfull_gcs_output_pathraise aValueErrornaming the setting when it's unset.- Requires
pydantic-settings>=2.14.0. upload_directory_to_gcs, and with itsync_directory_to_gcs,dcp-tools uploadanddcp-tools pipeline, skips a file whose MD5 matches the blob already at its remote path and logs it as unchanged. A blob without an MD5, such as a composite object, is always overwritten.
Fixed
KGSettingsignores variables in its.envfile that it doesn't define, instead of rejecting them as extra inputs. JSON files and constructor calls still reject unknown keys.ColumnMappingsaccepts the spec'svariableMeasuredandobservationDatekeys, so aconfig.jsonwritten to the spec loads. Mappings are still written withdcid:keys.observationPropertiesin an exportedconfig.jsonuses camelCase keys (scalingFactor,measurementMethod,observationPeriod) whenadd_input_fileorObservationPropertiesgets snake_case ones. Passing both spellings of one key raises aValidationError.
1.1.0 - 2026-10-23
Added
add_provenancetakesimported_source_release_date, written to the Provenance node as a quotedimportedSourceReleaseDate.add_provenanceandProvenanceNodetake a list forsource_data_url, written as one quoted value per URL on thesourceDataUrlline. A single string is written as before.check_ingestion_workflow_contractreads the ingestion workflow's definition and raisesWorkflowContractErrorunless the workflow creates its preprocessing job on Cloud Batch, as DCP 1.1.6 does. It also raises when the definition can't be read, which needsroles/workflows.viewer.run_ingestion_workflowruns it before starting the workflow, anddcp-tools pipelinebefore uploading.skip_workflow_contract_check=True, or--skip-workflow-contract-checkondcp-tools ingestanddcp-tools pipeline, skips the check.get_ingestion_execution_statereads an ingestion execution's state, current steps and error from the Workflow Executions API, as anIngestionExecutionState.
Changed
- dcp-tools leaves logging to the importing application: its module loggers sit under
dcp_tools, propagate to the root logger and set no handler or level, so unconfigured applications see only warnings.LOG_LEVELnow applies to thedcp-toolsCLI only, which still prints its messages. run_ingestion_workflow,dcp-tools ingestanddcp-tools pipelinestart ingestion only on a Data Commons Platform 1.1.6 instance. dcp-tools requiresdatacommons-admin>=1.1.6,<1.1.7, whoseIngestionJobClientsends the ingestion workflow only the list of imports. The workflow runs preprocessing as a Cloud Batch job it creates itself, so no preprocessing job name is sent.datacommons-admin1.1.6 depends ondatacommons-db, which adds Spanner and SQLAlchemy to the installed packages and capssetuptoolsat 80.0.0 for every project that installs dcp-tools.run_ingestion_workflowreturns the started execution's resource name, and raisesRuntimeErrorwhen the workflow's response holds none. It used to returnNoneand log a warning. Blank or comma-onlyimportsingest every import.
Deprecated
dcp_tools.loggerand thedcp-toolslogger name, to be removed in 2.0. Until then both resolve to thedcp_toolspackage logger, provideddcp-toolsis configured after dcp-tools is imported.KGSettings.ingestion_prep_job_nameandINGESTION_PREP_JOB_NAME, to be removed in 2.0. The setting is optional and ignored, and setting it emits aFutureWarning.
Fixed
- Uploads under Application Default Credentials failed with "Project was not passed" when the
credentials carried no default project.
upload_to_cloud_storagepassesgcp_project_idto the GCS client, andget_gcs_clienttakes aprojectargument for the same purpose.
1.0.1 - 2026-10-13
Fixed
- A fresh install could not import
dcp_tools.gcp_utilities, so thedcp-toolsCLI andrun_ingestion_workflowfailed.datacommons-admin1.1.3 movedIngestionJobClientto a new module, and 1.1.6 removed thejob_nameargument dcp-tools passes. The dependency is now capped atdatacommons-admin<1.1.3until dcp-tools supports the new client.
1.0.0 - 2026-10-13
First stable release under the name dcp-tools. The API is unchanged since
1.0.0a5, and from this release on, breaking changes wait for a new major version. To upgrade from
bblocks-datacommons-tools 0.1.1, follow the migration notes in the 1.0.0a1 to 1.0.0a5 entries
below, which describe each change in detail.
Changed
- Breaking: renamed the package from
bblocks-datacommons-toolstodcp-tools, the import path todcp_toolsand the CLI todcp-tools. The old distribution installsdcp-toolsand re-exports it with aDeprecationWarning. - Breaking: ingestion runs on the Data Commons Platform.
run_data_loadis nowrun_ingestion_workflow, the ingestion settings are renamed, and the Cloud SQL and redeploy settings and commands are removed. - Breaking: the Python API is snake_case throughout, the node models drop their
MCFprefix, andadd_sourceandadd_provenancetake separatedcidandnameparameters. - Breaking:
export_allwrites the complete bundle and empties the target directory first. - Minimum supported Python is 3.13.
Added
add_nodefor nodes of any type, andadd_mcf_fileto declare MCF files inconfig.json.- Source and Provenance nodes with licence, refresh and coverage metadata.
- Multi-entity observations through
custom:<name>dimensions. constraint_propertieson StatVars, and ingestion of selected imports.
Removed
- Breaking: the variable-per-column (implicit schema) input format, and the
redeploycommand.
1.0.0a5 - 2026-09-10
Added
license_typeandlicense_attributiononadd_source, andsource_data_urlandlicense_attributiononadd_provenance.
Changed
- Breaking:
license_typeandcuratorare now DCID references, written aslicenseType: dcid:<token>instead of a quoted string. Bare tokens passed toadd_source/add_provenanceare minted;SourceNode/ProvenanceNodestill require thedcid:prefix. - Breaking: renamed the ingestion settings to match the DCP Terraform outputs:
LOAD_JOB_NAME->INGESTION_PREP_JOB_NAME,LOAD_JOB_REGION->GCP_REGION, andLOAD_JOB_SERVICE_ACCOUNT->INGESTION_SERVICE_ACCOUNT. The old names are no longer accepted. - Breaking:
run_data_loadis renamedrun_ingestion_workflowand thedataloadCLI command is renamedingest.importsis now keyword-only on the renamed function. - Breaking:
export_allnow empties the target directory before writing, so a renamed or removed input file no longer lingers and gets ingested. A missing directory is created.
Migration:
- Rename the ingestion settings in your
.env/JSON settings file.KGSettingsno longer accepts theLOAD_JOB_*names. - Replace
run_data_load(...)withrun_ingestion_workflow(...), anddcp-tools dataloadwithdcp-tools ingest. Passimportsby keyword:run_data_load(settings, "climateFinance")becomesrun_ingestion_workflow(settings, imports="climateFinance").
1.0.0a4 - 2026-09-07
Changed
add_provenancenow warns instead of raising whensourceisn't registered in the bundle, so aProvenancecan reference aSourcethat already exists in base Data Commons.
1.0.0a3 - 2026-08-19
Added
add_node(dcid=..., name=..., type_of=...)onCustomDataManagerwrites an MCF node with a caller-suppliedtypeOf, for entity instances (e.g. organisations) or constraint-value classes (e.g.Commitment) the typed builders don't cover.
Changed
gcs_input_folder_path(GCS_INPUT_FOLDER_PATH) is now optional and defaults toingestion/input, the DCP Terraform default.
Fixed
KGSettingsaccepts its snake_case field names as well as the uppercase environment aliases, soKGSettings(local_path=...)works alongsideKGSettings(LOCAL_PATH=...).
1.0.0a2 - 2026-08-10
Added
add_mcf_file(file_name, provenance=...)declares an MCF file inconfig.json'sinputFiles, so the importer reads it. The importer skips MCF files that aren't declared.add_mcf_file("*.mcf", provenance=...)covers them all in a single-provenance import; declare each file separately when an import has more than one provenance.constraint_propertiesonStatVarNodeand as a parameter onCustomDataManager.add_variable_to_mcf, listing the DCID(s) of properties that constrain the StatisticalVariable. Bare tokens are minted todcid:<token>.- Breaking: required
ingestion_workflow_name(INGESTION_WORKFLOW_NAME) setting onKGSettings, the name of the Cloud Workflow that runs ingestion. Every existing.env/settings JSON needs this added beforeKGSettingswill construct.
Changed
InputFilerepresents both CSV and MCF entries. An entry targeting an.mcffile carries only aprovenance— nocolumnMappingsand noformat. CSV entries are unchanged.- Breaking: bumped the
datacommons-adminfloor to>=1.1.1.IngestionJobClient.start_jobis gone in that release, replaced bystart_workflow, which needs the newingestion_workflow_namesetting above in addition to the existingload_job_name.
Fixed
ProvenanceNode.source_linkis renamed tosource, so a provenance's parent source now serializes assource: dcid:source/<name>(wassourceLink:), the property name Data Commons ingestion preprocessing expects.run_data_load(and the CLI'sdataload/pipelinecommands) stopped working against a Data Commons Platform instance upgraded to 1.1.1, since the ingestion process moved from a directly invoked Cloud Run job to a Cloud Workflow execution. See the breaking changes above.run_data_load(and the CLI'sdataload/pipelinecommands) now loads every import when none are named.
1.0.0a1 - 2026-07-27
Added
importsarg on therun_data_loadfunction and--importsflag on thedataloadCLI command. This triggers a load of specific imports rather than all imports.- Optional
LOAD_JOB_SERVICE_ACCOUNTsetting that sets which service account the load job impersonates. When unset, the caller's credentials are used. - Support for multi-entity observations using custom dimensions, each declared using
custom:<name>inColumnMappingsand a matchingdcid:<name>in the StatVar'sobservation_properties.
Changed
- Renamed the package from
bblocks-datacommons-toolstodcp-tools. The import path is nowdcp_tools(wasbblocks.datacommons_tools). Installing the oldbblocks-datacommons-toolsdistribution now pulls indcp-toolsand re-exports it with aDeprecationWarning; update imports todcp_toolsat your convenience. - Minimum supported Python is now 3.13 (was 3.11).
- Packaging now follows the
bblocks-projectscopier template (ruff lint preset,tytype checking, pre-commit hooks, PyPI trusted publishing). - Re-pointed the data load flow at the DCP prep job, using the
IngestionJobClient. - Renamed load job settings:
CLOUD_RUN_JOB_NAME->LOAD_JOB_NAMEandCLOUD_JOB_REGION->LOAD_JOB_REGION. Config.input_filesis nowlist[InputFile](was a dict keyed by file name). Only the variable-per-row format is supported: loading a legacy config that contains"format": "variablePerColumn"now raises a clearValueErrorwith a migration message instead of a generic PydanticValidationError.InputFilenow rejects unknown keys (extra="forbid").- Renamed
export_mfc_filetoexport_mcf_fileandcsv_metadata_to_mfc_filetocsv_metadata_to_mcf_file, correcting a transposition in both names (csv_metadata_to_mcf_fileis exported from the package root). The old spellings are gone; update any calls. - Renamed the input-file API now that there is a single import format. The
ExplicitSchemaFilemodel is nowInputFile, andCustomDataManager.add_explicit_schema_fileis nowadd_input_file. The "explicit schema" name only made sense as a contrast with the removed implicit (variablePerColumn) schema. Behaviour and the serializedconfig.jsonare unchanged; the arguments and field names are the same ones, in the snake_case spelling noted below. - Single-entity StatVars don't emit
observationPropertiesby default. - Replaced
build_stat_var_groups_from_stringswithresolve_group_paths. The old function took aNodescontainer and used the StatVar node'smember_ofas a scratch field, holding a raw path such as"Economic/Employment"until it was overwritten with the resolved group dcid. That is whymember_ofcould not be validated.resolve_group_pathsworks on the path strings alone and returns the resolved dcid per path plus theStatVarGroupNodeobjects, so a node is never constructed with an invalidmember_of.csv_metadata_to_nodesgainedparse_groupsandgroup_namespaceand does the resolution between reading the CSV and building the nodes.CustomDataManager.add_variables_to_mcf_from_csvis unchanged. rename_variablenormalizes a bareold_name/new_nametodcid:<token>, the same ruleadd_variable_to_mcfapplies todcid.- Renamed the node model classes to drop the
MCFqualifier, treating MCF as one serialization of a Data Commons graph node rather than the model's identity:MCFNode→Node,MCFNodes→Nodes, and every subclass. - Collapsed a node's duplicate
Node/dcidproperties into a singledcid. A node's identifier is nownode.dcid, which still serializes to the mandatoryNode:line in MCF; the separate optionaldcidproperty is removed. Node.mcfis now theNode.to_mcf()method (andNodes.to_mcf()), matching theto_dict()/to_json()convention and leaving room for a futureto_jsonld().- The Python API is now snake_case throughout. Node and
Configattributes,CustomDataManagerbuilder keyword arguments, and theset_*methods use snake_case (node.type_of,add_variable_to_mcf(measured_property=...),set_import_name(...)). The serializedconfig.jsonand MCF wire format are unchanged: camelCase keys are preserved via pydantic aliases (alias_generator=to_camel). CSV column headers (e.g.memberOf) keep the Data Commons camelCase convention. export_allwrites and overwrites the complete bundle. It no longer takesmcf_file_namesoroverride. It writesconfig.json, the data CSVs,vertical_specs.json(when specs were added), and every MCF file you've added nodes to, overwriting anything already in the directory. Pass nothing for the full bundle; useexport_mcf_fileto write a single file.- Renamed
overridetooverwriteon the export helpers and flipped the default toTrue(overwrite). AffectsCustomDataManager.export_mcf_file,Nodes.export_to_mcf_file, andcsv_metadata_to_mcf_file. - Replaced
csv2mcf's--overrideflag with--append.csv2mcfnow overwrites the output file by default; pass--appendto add to an existing file instead (which can produce duplicateNode:blocks on repeated runs). add_sourceandadd_provenancetake separatedcid,name, anddescriptionparameters.dcidis the identifier (minted with thesource//provenance/slug prefix);nameis an optional human-readable label;descriptionis optional longer text. Previouslynamewas used as the identifier and the node's ownnameproperty was never set.- Renamed
CustomDataManager.remove_indicatortoremove_variable(parameterindicator_id→dcid), matching thevariableterminology used elsewhere (rename_variable,add_variable_to_mcf).
Removed
add_implicit_schema_filemethod onCustomDataManager.add_variable_to_configmethod onCustomDataManager.ImplicitSchemaFileandVariablemodel classes.ObservationPropertiesis retained but repurposed: it is no longer nested under a variable definition, and now carries the file-level constant observation properties onInputFile. It also accepts custom keys (extra="allow", wasextra="forbid"); the four standard fields are unchanged.- The
redeployCLI command and theredeploy_serviceandredeploy_cloud_run_servicefunctions. The service restart is now owned by the ingestion workflow. - Settings which are no longer used:
CLOUD_SQL_DB_NAME,CLOUD_SQL_REGION,CLOUD_SERVICE_REGION,CLOUD_RUN_SERVICE_NAME, andDATACOMMONS_SERVICE_IMAGE. - BREAKING:
entitykey onColumnMappings. UseobservationAboutfor single-entity data orcustom:<name>for multi-entity dimensions. - The
PeerGroupDcidOrListPeerGroupDcidandTopicDcidOrListTopicDcidtype aliases.PeerGroupDcidOrListPeerGroupDcidwas never referenced by any field, which is how the bypass in it went unnoticed.TopicDcidOrListTopicDcidwas the permissive member ofTopicNode.relevant_variable's union, and nothing references it now that the union has collapsed. ThePeerGroupDcidandTopicDcidthey wrapped are still used, as the types ofStatVarPeerGroupNode.dcidandTopicNode.dcid.
Fixed
rename_variableleft theNodeslookup index keyed by the old name, so variable removal raised "not found" for the renamed node and still resolved the old name. The rename now goes through a newNodes.rename, which keeps the index in step.export_data,export_mcf_file, andexport_vertical_specsraisedOSErrorwhen the target file name (anadd_input_filepath, anmcf_file_name, or avertical_specs_file) nested in a subdirectory that did not yet exist. Each now creates the parent directory before writing.add_variable_to_mcfdid not normalize a baredcidtodcid:<token>, unlike the schema-node builders, so a bare token raised aValidationErrorthere while working everywhere else. It now goes through the sameensure_dcidnormalization, as do itspopulation_type,measured_property,measurement_qualifierandmeasurement_denominatorarguments, which had the same gap.DcidOrListDcidused aPlainValidator, which replaces the wrappedDcidschema instead of running before it, so thedcid:prefix check never executed. Any string, including one with nodcid:prefix at all, passed through unvalidated and landed in the MCF verbatim. This affectedtype_ofon every node,relevant_variable,observation_propertiesandmemberon StatVar nodes, andincluded_in,sub_class_of,domain_includes,range_includesandsub_property_ofon the schema-node builders. These fields now normalize a bare token todcid:<token>(the same ruleensure_dcidalready applied at the builder level) and reject anything empty or whitespace-bearing. A non-string value now raisesValidationErrorrather than being accepted silently. This is a behaviour change for anyone passing a bare token to one of these fields today and relying on it staying bare.GroupDcidOrListGroupDcidhad the samePlainValidatorbypass, soStatVarNode.member_ofaccepted any string and wrote it to the MCF verbatim. It now enforces theGroupDcidpattern, which requires ag/segment, somember_of="dcid:myGroup"now raises andmember_of="one/g/economy"is minted todcid:one/g/economy.TopicNode.relevant_variablewas a union of the fixed type with two unfixed ones, so a value the fixed branch rejected still validated through a permissive branch. Its type is now plainDcidOrListDcid, which accepts exactly the same values the union was meant to allow, group and topic dcids included.Nodenow validates on assignment (validate_assignment=True). Restoring the patterns above would otherwise guard construction only, and the value that reaches the MCF file is often written by assignment, sonode.member_of = "garbage"andNodes.renamecould still put an invalid dcid in the output. Both now raise. Assigned values are also cleaned of line breaks and trailing spaces the way constructed ones are, for declared fields and for the extra keys that carry arbitrary MCF properties.csv_metadata_to_nodesreturned aNodeswhose lookup index did not include the StatVarGroup nodes it appended, so a laterremoveorrenameof a group node on the returned container raised "not found".add_variables_to_mcf_from_csv(parse_groups=True)raisedAttributeErrorwhen the CSV had nomemberOfcolumn, or when a row left it blank. The missing column now raises aValueErrornaming it, and a blank value leaves that node'smember_ofunset.- A group path with a whitespace-only segment, such as
"Economic/\t/Health", minted a group whose dcid ended in a bareg/with no slug. Only/and spaces were stripped, so a tab or line break survived the split andto_camelCasereduced it to an empty slug. Such segments are now dropped. - Breaking:
TopicNode.dcidis now typedTopicDcidrather than a hand-rolled pattern that looked for atopic/segment anywhere in the string without requiring thedcid:prefix.dcid="topic/x"validated and reached the MCF unprefixed, as did"xtopic/y"and"notdcid:topic/x". Every other node type's id already required the prefix, andrename_variablemints one on lookup, so a topic stored under a bare id could not be found. Those values now raise, whitespace inside the id is rejected instead of being carried into the MCF, and"dcid: topic/x"is normalized to"dcid:topic/x". Add thedcid:prefix to theNodecolumn of any topic CSV; Data Commons rejects unprefixed node ids on load anyway.
Migration:
- Replace
add_implicit_schema_filecalls withadd_input_fileand supply acolumn_mappingsargument. Data must be in the variable-per-row format (one observation per row). See the Data Commons custom data documentation. - Drop any
redeploycalls, and update your settings: renameCLOUD_RUN_JOB_NAME→LOAD_JOB_NAMEandCLOUD_JOB_REGION→LOAD_JOB_REGION, addLOAD_JOB_SERVICE_ACCOUNTif the job runs under an impersonated service account. - Replace
entityonColumnMappingswithobservationAbout. - Rename
ExplicitSchemaFile→InputFileandadd_explicit_schema_file→add_input_file. Names only; behaviour is unchanged, and the arguments are the same ones in the snake_case spelling below. - Rename
export_mfc_file→export_mcf_file. - Check any
member_ofvalue you pass toadd_variable_to_mcf, or anymemberOfvalue you supply in a StatVar CSV (the CSV header keeps the camelCase spelling). It must now resolve to a group dcid containingg/, for exampleone/g/economyordcid:one/g/economy. A value such asdcid:economyis rejected instead of being written to the MCF as-is. - Replace direct calls to
build_stat_var_groups_from_stringswith eithercsv_metadata_to_nodes(..., parse_groups=True, group_namespace=...)orresolve_group_paths. - Drop the
MCFinfix from node model class names (MCFNode→Node,StatVarMCFNode→StatVarNode, and so on) and theMCFNodescontainer →Nodes. - Read a node's id via
.dcid(not.Node); the separatedcidproperty is gone. - Call
node.to_mcf()instead ofnode.mcf. - Convert builder keyword arguments, node/
Configattributes andset_*methods to snake_case (measuredProperty→measured_property,typeOf→type_of,set_importName→set_import_name, and so on). The exportedconfig.jsonand MCF are unchanged. - Drop
mcf_file_namesandoverridefromexport_allcalls: pass nothing for the full bundle, and useexport_mcf_filefor a single file.export_allnow overwrites what's already there. - Rename
override=→overwrite=onexport_mcf_file,Nodes.export_to_mcf_fileandcsv_metadata_to_mcf_file(all now overwrite by default). - Replace
csv2mcf --overridewith the default (overwrite), or--appendto add to an existing file. - In
add_source/add_provenancecalls, pass the identifier asdcid=(wasname=); optionally passname=for a human-readable label. - Rename
remove_indicator(...)calls toremove_variable(...); the positional id argument is unchanged, and the keyword is nowdcid(wasindicator_id).
0.1.1 - 2026-02-19
Added
--syncflag foruploadandpipelineCLI commands. When enabled, remote blobs that no longer have a local counterpart are deleted after uploading.sync_directory_to_gcsfunction instorage.pythat composes upload + stale blob cleanup.syncparameter onupload_to_cloud_storageinpipeline.py.
0.1.0 - 2026-02-13
Released for external preview and testing.
Added
- Support for Application Default Credentials (ADC) as an alternative to service account JSON keys.
GCP_CREDENTIALSis now optional — when not provided, Google client libraries automatically use ADC (e.g. viagcloud auth application-default login).
Changed
- Switched build system from Poetry to uv.
- Switched linter/formatter from Black to Ruff.
- Widened
google-cloud-runversion constraint from<0.11.0to<1.0.0. - Updated all package dependencies.
Fixed
- Config file merge order is now deterministic across platforms (sorted by path).
0.0.9 - 2025-09-17
Added
- New configuration options, including
set_customIdNamespace,set_customSvgPrefix,set_defaultCustomRootStatVarGroupNameandset_svHierarchyPropsBlocklist.
0.0.8 - 2025-09-03
Fixed
- White space between quoted items is removed, to defend against a bug with data loading on the DC side.
0.0.7 - 2025-08-27
Fixed
- Linebreaks and trailing spaces are removed. This prevents errors when serialising to MCF that could quietly break the data loading job.
0.0.6 - 2025-08-14
Changed
- Node name is now an optional attribute. This makes it easy to append data to existing Base DC Nodes.
0.0.5 - 2025-08-14
Added
- Nodes can now contain a single
dcidor a list ofdcids.
0.0.4 - 2025-07-22
Changed
- Group strings are transformed to camelCase more reliably, with additional special characters handled.
Removed
- Option to override input and output folders on the data load job.
0.0.3 - 2025-07-18
Fixed
- Two bugs related to MCF files. The
dcid:prefix is now enforced for Node, and spaces betweendcid:and the start of the id string are trimmed.
0.0.2 - 2025-07-07
Changed
- Minor update to documentation and release to PyPI.
0.0.1 - 2025-07-07
Added
- Initial release of
dcp-tools.