swarmsim.yaml#

YAML support for novel swarms

This module provides a custom YAML loader that defines some nice tags.

See also

See Our YAML module for how to use the custom YAML tags.

Functions#

swarmsim.yaml.load(stream, *, Loader=<class 'swarmsim.yaml.include.IncludeLoader'>)[source]#

Parse the first YAML document in a stream and produce the corresponding Python object.

By default, this function uses our IncludeLoader class which processes !include, !relpath, and !np tags.

swarmsim.yaml.safe_load(stream, *, Loader=<class 'swarmsim.yaml.NaiveLoader'>)[source]#

Parse the first YAML document in a stream and produce the corresponding Python object.

This loads YAML similarly to how ruamel.yaml’s safe loader does, in that it ignores non-standard tags. It also handles recursively defined anchors/aliases.

swarmsim.yaml.dump(data, stream=None, *, Dumper=<class 'swarmsim.yaml.CustomDumper'>, **kwds)[source]#

Serialize a Python object into a YAML stream. If stream is None, return the produced string instead.

By default, this function uses our CustomDumper class which provides a more human-readable representation of pathlib.Path and certain small numpy.ndarray objects.

Examples

import swarmsim.yaml as yaml

# load a YAML file
with open('foo.yaml', 'r') as f:
    data = yaml.load(f)

# dump a YAML file
with open('foo.yaml', 'w') as f:
    yaml.dump(data, f)

Classes

CustomDumper(stream[, default_style, ...])

NaiveLoader(stream)

Modules

include

Handles !include and !relpath tags

mathexpr

Handle !np yaml tag.

np_representer

Provides a slightly more human-readable YAML representer for numpy arrays.

pathlib_representer

Provides a custom representer for Path objects

unknown