flowpipe.utilities module

class flowpipe.utilities.NodeEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: json.encoder.JSONEncoder

Custom JSONEncoder to handle non-json serializable node values.

If the value is not json serializable, a sha256 hash of its bytes is encoded instead.

default(o)

Encode the object, handling type errors by encoding into sha256.

flowpipe.utilities.deserialize_graph(data)

De-serialize from the given json data.

flowpipe.utilities.deserialize_node(data)

De-serialize a node from the given json data.

flowpipe.utilities.get_hash(obj, hash_func=<function <lambda>>)

Safely get the hash of an object.

This function tries to compute the hash as safely as possible, dealing with json data and strings in a well-defined manner.

Parameters
  • obj – The object to hash

  • hash_func (func(obj) -> str) – The hashing function to use

Returns

A hash of the obj

Return type

(str)

flowpipe.utilities.import_class(module, cls_name, file_location=None)

Import and return the given class from the given module.

File location can be given to import the class from a location that is not accessible through the PYTHONPATH. This works from python 2.6 to python 3.