nvflare.app_common.streamers.file_retriever module

class FileRetriever(source_dir: str, topic: str | None = None, stream_msg_optional=False, stream_msg_secure=False, dest_dir=None, chunk_size=None, chunk_timeout=None)[source]

Bases: ObjectRetriever

Init FLComponent.

The FLComponent is the base class of all FL Components. (executors, controllers, responders, filters, aggregators, and widgets are all FLComponents)

FLComponents have the capability to handle and fire events and contain various methods for logging.

do_stream(target: str, request: Shareable, fl_ctx: FLContext, stream_ctx: dict, validated_data: Any)[source]

Stream the file to the peer. Called on the stream sending side.

Parameters:
  • target – the receiving site

  • request – data to be sent

  • fl_ctx – FLContext object

  • stream_ctx – the stream context

  • validated_data – the file full path returned from the validate_request method

Returns:

get_result(stream_ctx: dict) -> (<class 'str'>, typing.Any)[source]

Called on the stream receiving side. Get the final result of the streaming. The result is the location of the received file.

Parameters:

stream_ctx – the StreamContext

Returns:

register_stream_processing(channel: str, topic: str, fl_ctx: FLContext, stream_done_cb, **cb_kwargs)[source]

Called on the stream sending side.

Parameters:
  • channel

  • topic

  • fl_ctx

  • stream_done_cb

  • **cb_kwargs

Returns:

retrieve_file(from_site: str, fl_ctx: ~nvflare.apis.fl_context.FLContext, timeout: float, file_name: str) -> (<class 'str'>, <class 'str'>)[source]

Retrieve a file from the specified site. This method is to be called by the app.

Parameters:
  • from_site – the site that has the file to be retrieved

  • fl_ctx – FLContext object

  • timeout – how long to wait for the file

  • file_name – name of the file to be retrieved

Returns: a tuple of (ReturnCode, location of the file received)

validate_request(request: ~nvflare.apis.shareable.Shareable, fl_ctx: ~nvflare.apis.fl_context.FLContext) -> (<class 'str'>, typing.Any)[source]

Object sending side. Called to validate the received retrieval request.

Parameters:
  • request – the request to be validated

  • fl_ctx – FLContext object

Returns: tuple of (ReturnCode, Validation Data) This method should do as much as possible so that the do_stream method won’t be called if any error is detected (the do_stream method is called in a separate thread). The validation data produced by this method will be passed to the do_stream method.