nvflare.apis.storage module

exception StorageException[source]

Bases: Exception

Base class for Storage exceptions.

class StorageSpec[source]

Bases: ABC

Functional spec of object storage.

An object is identified by a URI (unique resource identifier). Each object contains:

  • content (data)

  • meta info that describes the control info of the object.

abstract create_object(uri: str, data: bytes, meta: dict, overwrite_existing: bool)[source]

Creates an object.

Examples of URI:

/state/engine/… /runs/approved/covid_exam.3 /runs/pending/spleen_seg.1

Parameters
  • uri – URI of the object

  • data – content of the object

  • meta – meta info of the object

  • overwrite_existing – whether to overwrite the object if already exists

Raises StorageException when:
  • invalid args

  • object already exists and overwrite_existing is False

  • error creating the object

abstract delete_object(uri: str)[source]

Deletes specified object.

Parameters

uri – URI of the object

abstract get_data(uri: str) bytes[source]

Gets data of the specified object.

Parameters

uri – URI of the object

Returns

data of the object. if object does not exist, return None

Raises StorageException when:
  • invalid args

abstract get_detail(uri: str) Tuple[dict, bytes][source]

Gets both data and meta of the specified object.

Parameters

uri – URI of the object

Returns

meta info and data of the object.

Raises StorageException when:
  • invalid args

  • no such object

abstract get_meta(uri: str) dict[source]

Gets user defined meta info of the specified object.

Parameters

uri – URI of the object

Returns

meta info of the object. if object does not exist, return empty dict {}

Raises StorageException when:
  • invalid args

abstract list_objects(path: str) List[str][source]

Lists all objects in the specified path.

Parameters

path – the path to the objects

Returns

list of URIs of objects

abstract update_data(uri: str, data: bytes)[source]

Updates the data of the specified object.

Parameters
  • uri – URI of the object

  • data – value of new data

Raises StorageException when:
  • invalid args

  • no such object

  • error updating the object

abstract update_meta(uri: str, meta: dict, replace: bool)[source]

Updates the meta info of the specified object.

Parameters
  • uri – URI of the object

  • meta – value of new meta info

  • replace – whether to replace the current meta completely or partial update

Raises StorageException when:
  • invalid args

  • no such object

  • error updating the object