nvflare.fuel.f3.streaming.file_downloader module

DEFAULT_CHUNK_SIZE = 5242880

This package implements file downloading capability based on the ObjectDownloader framework. It provides implementation of the Downloadable and Consumer objects, required by ObjDownloader.

class FileDownloadable(file_name: str, chunk_size=None, file_downloaded_cb=None, **cb_kwargs)[source]

Bases: Downloadable

Constructor of FileDownloadable.

Parameters:
  • file_name – name of the file to be downloaded.

  • chunk_size – size of each chunk

  • file_downloaded_cb – if specified, the callback to be called when the file is downloaded to a receiver.

  • cb_kwargs – kwargs passed to the CB.

Notes: The file_downloaded_cb will be called as follows:

file_downloaded_cb(to_receiver, status, file_name, **cb_kwargs)

where: to_receiver is the name of the receiver that the file is just downloaded to; status is a value of DownloadStatus as defined in nvflare.fuel.f3.streaming.download_service; file_name is the name of the file downloaded.

The file_downloaded_cb is also called after it’s downloaded to all receivers. In this case, the value of “to_receiver” is empty, and the value of “status” is also empty.

downloaded_to_all()[source]

Called when the object is fully downloaded to all receivers.

downloaded_to_one(to_receiver: str, status: str)[source]

Called when an object is downloaded to a receiver.

Parameters:
  • to_receiver – name of the receiver that the object has been completely downloaded to.

  • status – the download status: DownloadStatus.SUCCESS or DownloadStatus.FAILED.

Returns: None

produce(state: dict, requester: str) Tuple[str, Any, dict][source]

Produce a small object to be sent (on object sender side).

Parameters:
  • state – current state of downloading, received from the downloading receiver

  • requester – the FQCN of the receiver that is downloading

Returns: a tuple of (return code, a small object to be sent, new state to be sent).

add_file(downloader: ObjectDownloader, file_name: str, chunk_size=None, ref_id=None, file_downloaded_cb=None, **cb_kwargs) str[source]

Add a file to be downloaded to the specified downloader.

Parameters:
  • downloader – the downloader to add to.

  • file_name – name of the file to be downloaded

  • chunk_size – chunk size in bytes

  • ref_id – ref id to be used, if provided

  • file_downloaded_cb – CB to be called when the file is done downloading

  • **cb_kwargs – args to be passed to the CB

Returns: reference id for the file.

The file_downloaded_cb must follow this signature:

cb(to_receiver: str, status: str, file_name: str, **cb_kwargs)

download_file(from_fqcn: str, ref_id: str, per_request_timeout: float, cell: Cell, location: str | None = None, secure=False, optional=False, abort_signal=None) Tuple[str, str | None][source]

Download the referenced file from the file owner.

Parameters:
  • from_fqcn – FQCN of the file owner.

  • ref_id – reference ID of the file to be downloaded.

  • per_request_timeout – timeout for requests sent to the file owner.

  • cell – cell to be used for communicating to the file owner.

  • location – dir for keeping the received file. If not specified, will use temp dir.

  • secure – P2P private mode for communication

  • optional – supress log messages of communication

  • abort_signal – signal for aborting download.

Returns: tuple of (error message if any, full path of the downloaded file).