nvflare.fuel.flare_api.flare_api module

class Session(username: str | None = None, startup_path: str | None = None, secure_mode: bool = True, debug: bool = False)[source]

Bases: SessionSpec

Initializes a session with the NVFLARE system

Parameters:
  • username – string of username to log in with

  • startup_path – path to the provisioned startup kit, which contains endpoint of the system

  • secure_mode – whether to run in secure mode or not

abort_job(job_id: str)[source]

Abort the specified job

Parameters:

job_id – job to be aborted

Returns: dict of (status, info)

If the job is already done, no effect; If job is not started yet, it will be cancelled and won’t be scheduled If the job is being executed, it will be aborted

clone_job(job_id: str) str[source]

Create a new job by cloning a specified job

Parameters:

job_id – job to be cloned

Returns: ID of the new job

close()[source]

Close the session

Returns:

delete_job(job_id: str)[source]

Delete the specified job completely from the system

Parameters:

job_id – job to be deleted

Returns: None

The job will be deleted from the job store if the job is not currently running

download_job_result(job_id: str) str[source]

Download result of the job

Parameters:

job_id – ID of the job

Returns: folder path to the location of the job result

If the job size is smaller than the maximum size set on the server, the job will download to the download_dir set in Session through the admin config, and the path to the downloaded result will be returned. If the size of the job is larger than the maximum size, the location to download the job will be returned.

get_job_meta(job_id: str) dict[source]

Get the meta info of the specified job

Parameters:

job_id – ID of the job

Returns: a dict of job metadata

get_system_info()[source]
list_jobs(detailed: bool = False, limit: int | None = None, id_prefix: str | None = None, name_prefix: str | None = None, reverse: bool = False) List[dict][source]

Get the job info from the server

Parameters:
  • detailed – True to get the detailed information for each job, False by default

  • limit – maximum number of jobs to show, with 0 or None to show all (defaults to None to show all)

  • id_prefix – if included, only return jobs with the beginning of the job ID matching the id_prefix

  • name_prefix – if included, only return jobs with the beginning of the job name matching the name_prefix

  • reverse – if specified, list jobs in the reverse order of submission times

Returns: a dict of job metadata

monitor_job(job_id: str, timeout: float = 0.0, poll_interval: float = 2.0, cb=None, *cb_args, **cb_kwargs) MonitorReturnCode[source]
Monitor the job progress until one of the conditions occurs:
  • job is done

  • timeout

  • the status_cb returns False

Parameters:
  • job_id – the job to be monitored

  • timeout – how long to monitor. If 0, never time out.

  • poll_interval – how often to poll job status

  • cb – if provided, callback to be called after each status poll

Returns: a MonitorReturnCode

Every time the cb is called, it must return a bool indicating whether the monitor should continue. If False, this method ends.

submit_job(job_definition_path: str) str[source]

Submit a predefined job to the NVFLARE system

Parameters:

job_definition_path – path to the folder that defines a NVFLARE job

Returns: the job id if accepted by the system

If the submission fails, exception will be raised:

try_connect(timeout)[source]
basic_cb_with_print(session: Session, job_id: str, job_meta, *cb_args, **cb_kwargs) bool[source]

This is a sample callback to use with monitor_job that demonstrates how a custom callback can be used

new_insecure_session(startup_kit_location: str, debug: bool = False, timeout: float = 10.0) Session[source]

Create a new secure session with NVFLARE system

Parameters:
  • startup_kit_location – path to the provisioned startup folder

  • debug – enable debug mode

  • timeout – how long to try to establish the session

Returns: a Session object

The username for insecure session is always “admin”

new_secure_session(username: str, startup_kit_location: str, debug: bool = False, timeout: float = 10.0) Session[source]

Create a new secure session with NVFLARE system

Parameters:
  • username – username assigned to the user

  • startup_kit_location – path to the provisioned startup folder, the root admin dir containing the startup folder

  • debug – enable debug mode

  • timeout – how long to try to establish the session

Returns: a Session object