nvflare.app_common.storages.filesystem_storage module

class FilesystemStorage(root_dir='/', uri_root='/')[source]

Bases: StorageSpec

Init FileSystemStorage.

Uses local filesystem to persist objects, with absolute paths as object URIs.

Parameters:
  • root_dir – the absolute path on the filesystem to store things

  • uri_root – serving as the root of the storage. All URIs are rooted at this uri_root.

clone_object(from_uri: str, to_uri: str, meta: dict, overwrite_existing: bool = False)[source]

Create a new object by cloning an existing one

Parameters:
  • from_uri – the existing object’s uri

  • to_uri – the uri for the new object

  • meta – meta info for the new object

  • overwrite_existing – whether to overwrite the new uri if already exists

Returns:

create_object(uri: str, data, meta: dict, overwrite_existing: bool = False)[source]

Creates an object.

Parameters:
  • uri – URI of the object

  • data – content of the object; bytes or file name that contains data

  • meta – meta of the object

  • overwrite_existing – whether to overwrite the object if already exists

Raises:
  • TypeError – if invalid argument types

  • StorageException

    • if error creating the object - if object already exists and overwrite_existing is False - if object will be at a non-empty directory

  • IOError – if error writing the object

delete_object(uri: str)[source]

Deletes the specified object.

Parameters:

uri – URI of the object

Raises:
  • TypeError – if invalid argument types

  • StorageException – if object does not exist

get_data(uri: str, component_name: str = 'data') bytes[source]

Gets data of the specified object.

Parameters:
  • uri – URI of the object

  • component_name – storage component name

Returns:

data of the object.

Raises:
  • TypeError – if invalid argument types

  • StorageException – if object does not exist

get_data_for_download(uri: str, component_name: str = 'data', download_file: str = None)[source]

Gets data of the specified object.

Parameters:
  • uri – URI of the object

  • component_name – storage component name

  • download_file – component file_name for download

Raises StorageException when:
  • invalid args

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 and data of the object.

Raises:
  • TypeError – if invalid argument types

  • StorageException – if object does not exist

get_meta(uri: str) dict[source]

Gets meta of the specified object.

Parameters:

uri – URI of the object

Returns:

meta of the object.

Raises:
  • TypeError – if invalid argument types

  • StorageException – if object does not exist

is_valid_component()
list_objects(path: str, without_tag=None) List[str][source]

List all objects in the specified path.

Parameters:
  • path – the path uri to the objects

  • without_tag – if set, skip the objects with this specified tag

Returns:

list of URIs of objects

Raises:
  • TypeError – if invalid argument types

  • StorageException – if path does not exist or is not a valid directory.

tag_object(uri: str, tag: str, data=None)[source]

Tag an object with specified tag and data.

Parameters:
  • uri – URI of the object

  • tag – tag to be placed on the object

  • data – data associated with the tag.

Returns: None

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

Updates the meta of the specified object.

Parameters:
  • uri – URI of the object

  • meta – value of new meta

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

Raises:
  • TypeError – if invalid argument types

  • StorageException – if object does not exist

  • IOError – if error writing the object

update_object(uri: str, data, component_name: str = 'data')[source]

Update the object

Parameters:
  • uri – URI of the object

  • data – content data of the component

  • component_name – component name

Raises StorageException when the object does not exit.