Wrappers

class Packable_Array[source]

Bases: humpack.packing.Packable

Wrapper to allow saving numpy arrays. Aside from being rather useful, this serves as an example for how to write a Packable wrapper.

Note the necessary Packable methods are all static, and the use of “use_cls” in the class declaration.

static __create__(data)[source]

Creates an empty np.array

Parameters

data – packed data

Returns

empty array with the correct size

static __pack__(obj)[source]

Pack the np.array data.

Note: that the information necessary for creating thet instance (shape, dtype) is not packed, but still valid json objects

Parameters

obj – instance of numpy.ndarray to be packed

Returns

packed data

static __unpack__(obj, data)[source]

Unpack the data and save the data to the created object

Parameters
  • obj – instance with empty data to populate with the unpacked data

  • data – packed data

Returns

None

class ObjectWrapper(obj)[source]

Bases: humpack.transactions.Transactionable, humpack.packing.Packable, ObjectProxy

Wrapper to transform an object to be transactionable.

Note: wrapped object must be copyable (shallow copy using .copy())

WARNING: It is NOT recommended to use this wrapper, unless you need a transactionable features

__init__(obj)[source]
begin()[source]
in_transaction()[source]
commit()[source]
abort()[source]
__repr__()[source]
__str__()[source]
__setattr__(key, value)[source]
__delattr__(item)[source]
__unpack__(data)[source]
__pack__()[source]

Save all the necessary data from the internal state (and pack any subdata)

Returns

packed data

__build__(data)[source]

Recover the wrapped object in the correct state from data and return wrapped object

Parameters

data – packed data

Returns

wrapped object with the loaded state

class Array(obj)[source]

Bases: humpack.wrappers.ObjectWrapper

This is an example of how to use the ObjectWrapper. Wraps numpy arrays.

WARNING: it is NOT recommended to use this wrapper for numpy arrays (they are already registered).

begin()[source]
commit()[source]
abort()[source]
__pack__()[source]

Pack data to restore numpy array.

Returns

packed data

__build__(data=None)[source]

Restore state of numpy array by unpacking data

Parameters

data – packed data

Returns

restored state