Skip to content

YAMLSpec

YAMLSpec(spec, path='', filename='')

Class for decoding and accessing specification data from YAML.

PARAMETER DESCRIPTION
spec

The YAML specification data or file name.

TYPE: str | dict | None

path

The path for a sub-specification within the YAML data, using dot notation. "" indicates the top level.

TYPE: str DEFAULT: ''

get(key, default_value=None, required=False, value_type=None)

Get a value from the YAML specification.

PARAMETER DESCRIPTION
key

The key to get.

TYPE: str

default_value

The default value to return if the key is not found.

TYPE: Any DEFAULT: None

required

Whether the key is required.

TYPE: bool DEFAULT: False

value_type

The expected type of the value.

TYPE: type_spec | None DEFAULT: None

RETURNS DESCRIPTION
Any

The value.

RAISES DESCRIPTION
KeyError

If the key is required but not found.

TypeError

If the value is not of the expected type.

get_bool(key, default_value=False, required=False)

Get a boolean value from the YAML specification.

PARAMETER DESCRIPTION
key

The key to get.

TYPE: str

default_value

The default value to return if the key is not found.

TYPE: bool DEFAULT: False

required

Whether the key is required.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
bool

The boolean value.

RAISES DESCRIPTION
KeyError

If the key is required but not found.

TypeError

If the value is not a boolean.

get_dict(key, key_type=None, value_type=None, default_value=None, required=False)

Get a dictionary value from the YAML specification.

PARAMETER DESCRIPTION
key

The key to get.

TYPE: str

key_type

The expected type of the dictionary keys.

TYPE: type_spec | None DEFAULT: None

value_type

The expected type of the dictionary values.

TYPE: type_spec | None DEFAULT: None

default_value

The default value to return if the key is not found.

TYPE: dict | None DEFAULT: None

required

Whether the key is required.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
dict

The dictionary value.

RAISES DESCRIPTION
KeyError

If the key is required but not found.

TypeError

If the value is not a dictionary or if any key or value is not of the expected type.

get_float(key, default_value=0.0, required=False)

Get a float value from the YAML specification.

PARAMETER DESCRIPTION
key

The key to get.

TYPE: str

default_value

The default value to return if the key is not found.

TYPE: float DEFAULT: 0.0

required

Whether the key is required.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
float

The float value.

RAISES DESCRIPTION
KeyError

If the key is required but not found.

TypeError

If the value is not a float.

get_int(key, default_value=0, required=False)

Get an integer value from the YAML specification.

PARAMETER DESCRIPTION
key

The key to get.

TYPE: str

default_value

The default value to return if the key is not found.

TYPE: int DEFAULT: 0

required

Whether the key is required.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
int

The integer value.

RAISES DESCRIPTION
KeyError

If the key is required but not found.

TypeError

If the value is not an integer.

get_list(key, item_type=None, default_value=None, required=False)

Get a list value from the YAML specification.

PARAMETER DESCRIPTION
key

The key to get.

TYPE: str

item_type

The expected type of the list elements.

TYPE: type_spec | None DEFAULT: None

default_value

The default value to return if the key is not found.

TYPE: list | None DEFAULT: None

required

Whether the key is required.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
list

The list value.

RAISES DESCRIPTION
KeyError

If the key is required but not found.

TypeError

If the value is not a list or if any element is not of the expected type.

get_optional_int(key, default_value=None)

Get an optional integer value from the YAML specification.

PARAMETER DESCRIPTION
key

The key to get.

TYPE: str

RETURNS DESCRIPTION
int | None

The integer value, or None if not found.

RAISES DESCRIPTION
TypeError

If the value is not an integer.

get_optional_str(key, default_value=None)

Get an optional string value from the YAML specification.

PARAMETER DESCRIPTION
key

The key to get.

TYPE: str

RETURNS DESCRIPTION
str | None

The string value, or None if not found.

RAISES DESCRIPTION
TypeError

If the value is not a string.

get_palette(key, default_value=None, required=False)

Get a Palette value from the YAML specification.

PARAMETER DESCRIPTION
key

The key to get.

TYPE: str

default_value

The default value to return if the key is not found.

TYPE: Palette | None DEFAULT: None

required

Whether the key is required.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Palette

The Palette value.

RAISES DESCRIPTION
KeyError

If the key is required but not found.

TypeError

If the value is not a valid Palette specification.

get_spec(key)

Get a nested YAML specification.

PARAMETER DESCRIPTION
key

The key to get.

TYPE: str

RETURNS DESCRIPTION
YAMLSpec

The nested YAML specification.

RAISES DESCRIPTION
KeyError

If the key is required but not found.

TypeError

If the value is not a dictionary or keys are not strings.

get_spec_list(key, allow_single=False)

Get a list of nested YAML specifications.

PARAMETER DESCRIPTION
key

The key to get.

TYPE: str

allow_single

Whether to allow a single specification instead of a list.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
list[YAMLSpec]

The list of nested YAML specifications.

RAISES DESCRIPTION
KeyError

If the key is required but not found.

TypeError

If the value is not a a valid specification or list of specifications.

get_str(key, default_value='', required=False)

Get a string value from the YAML specification.

PARAMETER DESCRIPTION
key

The key to get.

TYPE: str

default_value

The default value to return if the key is not found.

TYPE: str DEFAULT: ''

required

Whether the key is required.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
str

The string value.

RAISES DESCRIPTION
KeyError

If the key is required but not found.

TypeError

If the value is not a string.

get_type(key)

Get the type of a value in the YAML specification.

PARAMETER DESCRIPTION
key

The key to get the type for.

TYPE: str

RETURNS DESCRIPTION
type | None

The type of the value, or None if the key does not exist.

unknown_keys()

Return list of unknown keys in the YAML specification.

RETURNS DESCRIPTION
list[str]

List of keys that have not been accessed.