write_metadata#

caf.toolkit.log_helpers.write_metadata(output_path, details, *, datetime_comment=True, other_comment=None, format_comment=False, **metadata)[source]#

Write metadata YAML to specified path.

Parameters:
  • output_path (Path) – Path to output location, if a folder is given filename will be “metadata.yml”.

  • details (ToolDetails) – Information about the current tool.

  • datetime_comment (bool) – Whether to include a comment at the top of the config file with the current date and time (default True).

  • other_comment (str | None) – Additional comments to add to the top of the config file, “#” will be added to the start of each new line if it isn’t already there.

  • format_comment (bool) – Whether to remove newlines from other_comment and format lines to a specific character length (default False).

  • **metadata (str | int | float | bool | BaseModel | _Dataclass | Collection[_MetadataTypes] | Mapping[Hashable, _MetadataTypes]) – Any additional keyword arguments are used to define specific items to include in the output metadata file. These can be single values (str, int, etc.), collections of values or dataclasses.

Return type:

Path

See also

save_yaml()

for details on how the metadata is written to YAML.

Examples

A basic example to write a simple metadata YAML file, with an example of the text written.

>>> write_metadata(
...     path,
...     ToolDetails("name", "0.1.0"),
...     year=2026,
...     project="Test Project",
...     scenario="Test",
...     parameters={"a": 1, "b": 2},
... )
Example of the metadata file created#
# Metadata config written on 2026-01-23 at 14:44
tool_details:
  name: test tool
  version: 1.2.3
  full_version: v1.2.3
system_information:
  user: Test User
  pc_name: Test PC
  python_version: 3.0.0
  operating_system: Test System 10 (10.0.1)
  architecture: AMD64
  processor: Intel64 Family 6 Model 85 Stepping 7, GenuineIntel
  cpu_count: 10
  total_ram: 30000
metadata:
  year: 2026
  project: Test Project
  scenario: Test
  parameters:
    a: 1
    b: 2