yaml_decode()

def yaml_decode(yaml_string)

Parse a YAML string into a Starlark dictionary.

This function takes a YAML-formatted string and converts it into a Starlark dictionary that you can easily work with. YAML is a human-readable configuration file format that maps well to Starlark data structures. The YAML must be valid or this function will raise an error.

Raises: Raises an error if the YAML string is malformed or invalid

Args

  • yaml_string: string: A valid YAML-formatted string to parse

Returns

A Starlark dictionary representing the parsed YAML data

yaml_dumps()

def yaml_dumps(value)

Dump a dictionary into a YAML-formatted string.

This is an alias for yaml_encode() following common Python naming conventions. It converts Starlark dictionaries and other values into YAML-formatted strings suitable for configuration files or output.

Raises: Raises an error if the value cannot be serialized to YAML

Args

  • value: The dictionary or Starlark value to dump as YAML

Returns

A YAML-formatted string representation of the input value

yaml_encode()

def yaml_encode(value)

Convert a dictionary into a YAML-formatted string.

This function serializes Starlark dictionaries and other values into YAML-formatted strings suitable for configuration files or output. By default, YAML is naturally formatted in a human-readable way.

Raises: Raises an error if the value cannot be serialized to YAML

Args

  • value: The dictionary or Starlark value to encode as YAML

Returns

A YAML-formatted string representation of the input value

yaml_encode_compact()

def yaml_encode_compact(value)

Convert a value into a compact YAML string.

This is a convenience function for encoding with minimal whitespace when needed, though YAML is typically compact by default. Equivalent to calling yaml_encode(value).

Args

  • value: The dictionary or Starlark value to encode

Returns

A compact YAML string

yaml_encode_pretty()

def yaml_encode_pretty(value)

Convert a value into a formatted YAML string with proper indentation.

This is a convenience function for creating human-readable YAML output. Since YAML is inherently readable, this currently produces the same formatted output as yaml_encode().

Args

  • value: The dictionary or Starlark value to encode

Returns

A formatted YAML string with proper indentation

yaml_is_valid()

def yaml_is_valid(yaml_string)

Check whether a string is valid YAML without raising an error.

This is a quick validation helper: it returns True if the string parses as YAML (single-document) and False otherwise. No decoded data is returned.

Args

  • yaml_string: string: The string to validate.

Returns

True if the string is valid YAML, False otherwise.

yaml_loads()

def yaml_loads(yaml_string)

Load a YAML string into a Starlark dictionary.

This is an alias for yaml_decode() following common Python naming conventions. It parses a YAML-formatted string and converts it into a Starlark dictionary.

Raises: Raises an error if the YAML string is malformed or invalid

Args

  • yaml_string: string: A valid YAML-formatted string to parse

Returns

A Starlark dictionary representing the parsed YAML data

yaml_merge()

def yaml_merge(base_dict, override_dict)

Merge two dictionaries, with values from override_dict replacing base_dict values.

This utility function performs a shallow merge of two dictionaries, commonly used when combining default configuration with user-provided YAML overrides. Values from override_dict take precedence over those in base_dict. For deep merging of nested structures, consider applying this function recursively.

Args

  • base_dict: The base/default dictionary.
  • override_dict: The dictionary with overrides. Its values replace base_dict’s values.

Returns

A new dictionary with merged values where override_dict values take precedence.

yaml_parse_string()

def yaml_parse_string(content)

Parse a YAML formatted string into a dictionary.

This function is the original backwards-compatible name for parsing YAML strings. New code should use yaml_decode() instead.

Raises: Raises an error if the YAML string is malformed or invalid

Args

  • content: string: The YAML-formatted string to parse

Returns

A dictionary representation of the YAML data

yaml_to_string()

def yaml_to_string(value)

Convert a dictionary to a YAML-formatted string.

This function is the original backwards-compatible name for encoding YAML. New code should use yaml_encode() instead.

Raises: Raises an error if the value cannot be serialized to YAML

Args

  • value: The dictionary or Starlark value to serialize

Returns

The YAML string representation of the input value

yaml_try_decode()

def yaml_try_decode(yaml_string, default)

Attempt to decode a YAML string, returning a default value on failure.

This function provides safe YAML parsing with graceful error handling. If the string is not valid YAML, it returns the default value instead of raising an exception.

Args

  • yaml_string: string: The YAML string to decode.
  • default: The value to return if decoding fails. Default is None.

Returns

The decoded dictionary if successful, or the default value if decoding fails.