hdf5manager

class seas.hdf5manager.hdf5manager(path: str, verbose: bool = False, create: bool = True)[source]

Bases: object

A class for managing saved artifacts in the hdf5 format. Only temporarily opens file for read/write operations, to avoid corruption. Abstracts away different data types and attributes, to simplify user experience.

Functions:

print: Prints all objects in hdf5 file. keys: Lists all keys currently in hdf5 file. open: Opens file for manual operation. close: Closes file after manual operation. load: Load a specific object, or all objects, from file. delete: Delete a specific object from hdf5 file. save: Save data to hdf5 file.

Methods Summary

close()

Close the file after manual access.

delete(target)

Deletes a specific objects from the hdf5 file.

keys()

List all keys within the file.

load([target, ignore])

Load a specific target, or all object from the hdf5 file.

open()

Open the object for manual access.

print()

Prints the contents of the file.

save(data)

Saves any data to the hdf5 file.

Methods Documentation

close()[source]

Close the file after manual access.

Parameters

None

Returns

None

delete(target: List[str])None[source]

Deletes a specific objects from the hdf5 file.

Parameters

target – Which object(s) to delete from the file.

Returns

None

keys()List[str][source]

List all keys within the file.

Parameters

None

Returns

All keys present with in the file.

Return type

keys

load(target: Optional[List[str]] = None, ignore: Optional[List[str]] = None)dict[source]

Load a specific target, or all object from the hdf5 file.

Parameters
  • target – Which object(s) to load from the file.

  • ignore – The object(s) to ignore when loading.

Returns

The data loaded from the file.

Return type

data

open()None[source]

Open the object for manual access. This takes away safety / anti-corruption features, and should be avoided if possible.

The raw file can be now accessed using h5py functionsd at self.f.

Parameters

None

Returns

None

print()None[source]

Prints the contents of the file.

Parameters

None

Returns

None

save(data: dict)None[source]

Saves any data to the hdf5 file. Uses various underlying save mechanisms, depending on the appropriate storage for the data type. If an appropriate data type is not supported, the object will be pickle dumped to file. In this case, be careful when loading that you have the same python libraries inported as you did when the object was initially created. Nested dictionaries are supported, and save within hdf5 as a nested object.

Parameters

data – The dictionary of data to be saved to the file.

Returns

None