The codec module contains classes used by clients to marshall PDM classes to and from JSON. This saves the clients having to instantiate and manipulate the Marshmallow schema directly.

class MarshmallowCodec[source]

MarshmallowCodec marshalls and unmarshalls PDM classes.

The mapping of PDM classes to Marshmallow schema is defined in this class.


Return a string JSON representation of a PDM instance.

Parameters:obj – the instance to marshall to JSON
Returns:a JSON string
load_from_file(cls, path)[source]

Load an instance of a PDM class from disk.

  • cls – the class to create from the file
  • path – the path to the file

an instance of cls

loads(pdm_class, json_data)[source]

Create an instance of a PDM class from a JSON string.

  • pdm_class – the class to create from the JSON
  • json_data – the JSON to unmarshall

an instance of cls


A decorator that is used to register the mapping between a Marshmallow schema and the PDM class it serialises.

Parameters:pdm_class – the PDM class this schema maps to
set_schema(pdm_class, schema_class)[source]

Set the schema for a PDM class.

  • schema_class – Marshmallow schema to map
  • pdm_class – PDM class the schema maps to