Dict Codec

Codec for serialising and de-serialising Dictionary and List objects.

Methods

odin.codecs.dict_codec.load(d: Dict[str, Any], resource: Type[R] | None = None, full_clean: bool = True, copy_dict: bool = True, default_to_not_supplied: bool = False) R

Load a dict into a Resource structure.

This method is an alias of :py:func:`odin.

Parameters:
  • d – Dict to load

  • resource – A resource type, resource name or list of resources and names to use as the base for creating a resource. If a list is supplied the first item will be used if a resource type is not supplied.

Raises:

ValidationError – During building of the object graph and issues discovered are raised as a ValidationError.

odin.codecs.dict_codec.dump(resource, cls=<class 'odin.codecs.dict_codec.OdinEncoder'>, **kwargs)[source]

Dump a resource structure into a nested dict.

While a resource includes a to_dict method this method is not recursive. The dict codec recursively iterates through the resource structure to produce a full dict. This is useful for testing for example.

Parameters:
  • resource – The root resource to dump

  • cls – Encoder class to utilise

Returns:

Example usage

Loading a resource from a file:

from odin.codecs import dict_codec

my_dict = {}

resource = dict_codec.load(my_dict, MyResource)