Class - DataSource#

class openfl.federated.data.sources.data_source.DataSource(type, name)[source]#

Bases: ABC

Base class for different types of data sources.

Parameters:
type#

The storage type of the data source

Type:

DataSourceType

name#

The name of the data source

Type:

str

__init__(type, name)[source]#

Initialize a DataSource.

Parameters:
  • type (DataSourceType) – The storage type of the data source.

  • name (str) – The name of the data source.

Methods

__init__(type, name)

Initialize a DataSource.

compute_file_hash(path)

Compute the hash of the object or file.

enumerate_files()

Enumerate all files in the data source.

from_dict(ds_dict)

Create a DataSource from a dictionary.

is_valid_hash_function(func)

read_blob(path)

Read a blob from the data source.

to_dict()

Convert the object to a dictionary using the serialization rules.

abstract compute_file_hash(path)[source]#

Compute the hash of the object or file.

Parameters:

path (str) – Path to the file.

Returns:

The file’s hash.

Return type:

str

abstract enumerate_files()[source]#

Enumerate all files in the data source.

Yields:

str – The file path.

Return type:

Generator[str, None, None]

abstract classmethod from_dict(ds_dict)[source]#

Create a DataSource from a dictionary.

Parameters:

ds_dict (dict) – The dictionary to convert.

Returns:

The created DataSource.

Return type:

DataSource

abstract read_blob(path)[source]#

Read a blob from the data source. :param path: Path to the file. :type path: str

Returns:

The file’s content.

Return type:

bytes

Parameters:

path (str)

to_dict()[source]#

Convert the object to a dictionary using the serialization rules.

Return type:

Dict[str, Any]