Data Converter

Data converters are used in botoflow to serialize/deserialize Python objects and exceptions between botoflow and Amazon SWF.

Note

The naming data_converters and not serde or encoder/decoder was chosen to match closer with the naming in official Flow Java library, but behaves much like json.dumps() and json.loads() in one.

Abstract Data Converter

class botoflow.data_converter.abstract_data_converter.AbstractDataConverter

Subclasses of this data converter are used by the framework to serialize/deserialize method parameters that need to be sent over the wire.

dumps(obj)

Should return serialized string data

loads(data)

Should return deserialized string data

JSON Data Converter

class botoflow.data_converter.json_data_converter.JSONDataConverter

This is the recomended and default data converter. It (de)serializes most Python types as JSON data, which json cannot do, but allows you to have a more or less human readable view of the data (if you for example were using the AWS SWF console to check on the progress of your workflow activities).

It tries to serialize objects from new-style classes, moreover, it tries to follow the pickle's __setstate__ and __getstate__ methods for customizing serialization and deserialization.

Because it is not pickle, it will NOT work in all the situations that Pickle does and vice-versa. For example, bytes have to be encoded manually in Python2 (as there's no easy way to know what to do, and hence one of the big reasons for Python3).

We try to support most of the base types for ease of use, but the serialized data might be a bit 'chatty' and bump into SWF data limitations.

Warning

This data converter does not support old-style classes.

dumps(obj)

Serialize to object to JSON str format

Parameters
obj (object) -- Any serializable object (including classes)
Returns
JSON string
Return type
str
loads(data)

Deserialize a JSON string into Python object(s)

Parameters
data (str, unicode) -- Input streang
Returns
deserialized object
Return type
object

Pickle Data Converter

class botoflow.data_converter.pickle_data_converter.PickleDataConverter(protocol=0)

This is a pickling data converter. The data passed around with SWF will be in the pickle format. In addition, if the protocol version is not 0, the data will be base64 encoded (as any version other than 0 is binary).

Warning

This data converter is NOT recomended as it does not serialize exceptions well and can cause various hard to debug issues.

Parameters
protocol -- Pickle protocol version
dumps(obj)

Dumps object as pickle then base64 encodes it depending on the protocol version.

Parameters
obj -- object to serialize.
loads(data)

loads the pickle data

Parameters
data -- data to deserialize.