Serialization¶
Workflow has
several methods for storing persistent data
to your workflow’s data and cache directories. By default these are stored as
Python pickle objects using CPickleSerializer (with
the file extension .cpickle).
You may, however, want to serialize your data in a different format, e.g. JSON,
to make it user-readable/-editable or to interface with other software, and
the SerializerManager and data storage/caching APIs enable
you to do this.
For more information on how to change the default serializers, specify alternative ones and register new ones, see Persistent data and Serialization of stored/cached data in the User Manual.
API¶
-
class
workflow.workflow.SerializerManager¶ Contains registered serializers.
New in version 1.8.
A configured instance of this class is available at
workflow.manager.Use
register()to register new (or replace existing) serializers, which you can specify by name when callingWorkflowdata storage methods.See Serialization of stored/cached data and Persistent data for further information.
-
register(name, serializer)¶ Register
serializerobject undername.Raises
AttributeErrorifserializerin invalid.Note
namewill be used as the file extension of the saved files.Parameters: - name (
unicodeorstr) – Name to registerserializerunder - serializer – object with
load()anddump()methods
- name (
-
serializer(name)¶ Return serializer object for
nameorNoneif no such serializer is registeredParameters: name ( unicodeorstr) – Name of serializer to returnReturns: serializer object or None
-
serializers¶ Return names of registered serializers
-
unregister(name)¶ Remove registered serializer with
nameRaises a
ValueErrorif there is no such registered serializer.Parameters: name ( unicodeorstr) – Name of serializer to removeReturns: serializer object
-
-
class
workflow.workflow.JSONSerializer¶ Wrapper around
json. Setsindentandencoding.New in version 1.8.
Use this serializer if you need readable data files. JSON doesn’t support Python objects as well as
cPickle/pickle, so be careful which data you try to serialize as JSON.-
classmethod
dump(obj, file_obj)¶ Serialize object
objto open JSON file.New in version 1.8.
Parameters: - obj (JSON-serializable data structure) – Python object to serialize
- file_obj (
fileobject) – file handle
-
classmethod
-
class
workflow.workflow.CPickleSerializer¶ Wrapper around
cPickle. Setsprotocol.New in version 1.8.
This is the default serializer and the best combination of speed and flexibility.
-
classmethod
dump(obj, file_obj)¶ Serialize object
objto open pickle file.New in version 1.8.
Parameters: - obj (Python object) – Python object to serialize
- file_obj (
fileobject) – file handle
-
classmethod
-
class
workflow.workflow.PickleSerializer¶ Wrapper around
pickle. Setsprotocol.New in version 1.8.
Use this serializer if you need to add custom pickling.
-
classmethod
dump(obj, file_obj)¶ Serialize object
objto open pickle file.New in version 1.8.
Parameters: - obj (Python object) – Python object to serialize
- file_obj (
fileobject) – file handle
-
classmethod