YAML conversion

The galactic.yaml module.

It defines yaml related classes and functions.

class YAMLObject(*args: Any, **kwargs: Any)

Allows inherited classes to have automatic yaml import and export capacities.

New in version 0.5.0.

__init__(*args: Any, **kwargs: Any)

Initialize a YamlObject instance.

classmethod __init_subclass__(**kwargs: Any)

Add a sub-class hook.

class Dumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)

The Dumper class is used to dump data to yaml format.

New in version 0.5.0.

class Loader(stream)

The Loader class is used to load data from yaml format.

New in version 0.5.0.

check_state_key(key)

Block special attributes/methods from being set in a newly created object, to prevent user-controlled methods from being called during deserialization

add_dictionary_like(cls: type) None

Add a class as a dictionary-like data.

Parameters:

cls (type) – The class to be considered as a dictionary-like data.

New in version 0.5.0.

add_sequence_like(cls: type) None

Add a class as a sequence-like data.

Parameters:

cls (type) – The class to be considered as a sequence-like data.

New in version 0.5.0.

add_tuple_like(cls: type) None

Add a class as a tuple-like data.

Parameters:

cls (type) – The class to be considered as a tuple-like data.

New in version 0.5.0.

load(stream: Union[str, IO[str]]) Any

Load data from yaml format.

Parameters:

stream (str, IO[str]) – A stream to load from.

Returns:

The loaded data.

Return type:

object

New in version 0.5.0.

dump(data: Any, stream: Optional[IO[str]] = None, sort_keys: bool = False, dump_defaults: bool = False) Any

Dump data to yaml format.

Parameters:
  • data – Any python data.

  • stream (IO[str]) – A stream to dump.

Keyword Arguments:
  • sort_keys (bool, optional) – The sort_keys parameter.

  • dump_defaults (bool, optional) – Are default values dumped?

Returns:

The dumped data.

Return type:

str, optional

New in version 0.5.0.