extended_data.io.exporters

This module provides utilities for exporting raw data in various formats.

Module Contents

Functions

wrap_raw_data_for_export

Wraps raw data for export, optionally encoding it.

make_raw_data_export_safe

Make raw data safe for export by converting complex types to primitives.

API

extended_data.io.exporters.wrap_raw_data_for_export(raw_data: collections.abc.Mapping[str, Any] | Any, allow_encoding: bool | str = True, **format_opts: Any) str

Wraps raw data for export, optionally encoding it.

Args: raw_data (Mapping[str, Any] | Any): The raw data to wrap. allow_encoding (bool | str): The encoding format or flag (default is ‘yaml’). format_opts (Any): Additional options for formatting the output.

Returns: str: The wrapped and encoded data.

Raises: ValueError: If an invalid or unsupported encoding is provided.

extended_data.io.exporters.make_raw_data_export_safe(raw_data: Any, export_to_yaml: bool = False) Any

Make raw data safe for export by converting complex types to primitives.

Recursively processes data structures (dicts, lists, sets, tuples, frozensets) and converts:

  • datetime.date/datetime.datetime → ISO format strings

  • pathlib.Path → strings

  • For YAML export: applies special string formatting for GitHub Actions syntax

Args: raw_data: The data to make export-safe (dict, list, set, tuple, frozenset, or primitive). Sets, tuples, and frozensets are converted to lists. export_to_yaml: If True, apply YAML-specific formatting (e.g., literal strings for multiline)

Returns: Export-safe version of the data with all complex types converted

Examples: >>> from datetime import datetime >>> from pathlib import Path >>> data = {“date”: datetime(2025, 1, 1), “path”: Path(“/tmp”)} >>> make_raw_data_export_safe(data) {‘date’: ‘2025-01-01T00:00:00’, ‘path’: ‘/tmp’}

>>> multiline = {"script": "echo 'line1'\\necho 'line2'"}
>>> result = make_raw_data_export_safe(multiline, export_to_yaml=True)
>>> type(result["script"]).__name__
'LiteralScalarString'