FLARE API

The FLARE API (nvflare.fuel.flare_api.flare_api) is the Python interface for administering a running NVIDIA FLARE system: submitting jobs, monitoring them, downloading results, and inspecting or operating sites. It authenticates with an admin startup kit, exactly like the nvflare job and nvflare system CLI commands, and is what PocEnv and ProdEnv use internally. This page covers creating a session, the main methods, monitoring, and exceptions.

Creating a Session

from nvflare.fuel.flare_api.flare_api import new_secure_session

sess = new_secure_session(
    "[email protected]",
    "/tmp/nvflare/poc/example_project/prod_00/[email protected]",
)
Function Parameters
new_secure_session(username, startup_kit_location, debug=False, timeout=10.0, study="default", command_timeout=None, auto_login_max_tries=None) Standard mTLS login with the user's certificate.
new_session(username, startup_kit_location, secure_mode=True, ...) General form.
new_insecure_session(startup_kit_location, debug=False, timeout=10.0, study="default") For insecure (non-TLS) deployments.

startup_kit_location is the admin kit directory itself (the folder containing startup/), not the prod_00 root. study scopes study-aware commands (submit_job, list_jobs, get_job_meta, ...); it defaults to "default".

There is no logout(). Always close the session:

try:
    job_id = sess.submit_job("/tmp/nvflare/jobs/hello-pt")
    print(f"{job_id} was submitted")
    sess.monitor_job(job_id)
    print(sess.download_job_result(job_id))
finally:
    sess.close()

Job Methods

Method Returns Notes
submit_job(job_definition_path, submit_token=None) job ID The folder must exist (or exist under the kit's upload directory). Its name may contain only letters, numbers, dots, underscores, and hyphens.
list_jobs(detailed=False, limit=None, id_prefix=None, name_prefix=None, reverse=False, submit_token=None) list of dicts Legacy keyword aliases max_num, job_id_prefix, job_name_prefix, id, name are still accepted.
get_job_meta(job_id) dict Job metadata including status.
get_job_status(job_id) str or None Status only.
monitor_job(job_id, timeout=0, poll_interval=2.0, cb=None, *cb_args, **cb_kwargs) MonitorReturnCode See below.
wait_for_job(job_id, timeout=0.0, poll_interval=2.0) final meta dict Raises JobTimeout on timeout.
download_job_result(job_id, destination=None, outputs_only=False) path Without destination, the result stays in the kit's download directory; with it, the folder is moved there.
abort_job(job_id) —
delete_job(job_id) —
clone_job(job_id) new job ID Deprecated since 2.10.0; resubmit the original folder instead.
get_job_logs(...), configure_job_log(job_id, config, target="all") Job log access and runtime log level.
show_stats(job_id, target_type, targets=None), show_errors(...), reset_errors(job_id) Running job statistics and errors.
do_app_command(job_id, topic, cmd_data) dict Send a JSON-serializable command to a running job.

Monitoring

monitor_job() polls get_job_meta() every poll_interval seconds until the job reaches a terminal state, the timeout passes (timeout=0 means never), or the callback returns False. It returns a MonitorReturnCode: JOB_FINISHED (0), TIMEOUT (1), or ENDED_BY_CB (2). Note that it returns JOB_FINISHED for every terminal state, successful or not; inspect the status in the job meta to tell them apart.

A callback receives (session, job_id, job_meta, *cb_args, **cb_kwargs) and must return True to continue:

def print_status(session, job_id, job_meta, *args, **kwargs):
    print(job_meta.get("status"))
    return True

sess.monitor_job(job_id, timeout=3600, cb=print_status)

basic_cb_with_print in the same module is a ready-made example callback. Use monitor_job_and_return_job_meta() when you also need the final meta.

System Methods

Method Description
get_system_info() Server info, connected clients, and running jobs.
get_connected_client_list() List of ClientInfo.
get_client_job_status(client_names=None) Job status on clients.
check_status(target_type, targets=None) / report_resources(...) / report_version(...) Status, resources, versions.
restart(...) / shutdown(...) / shutdown_system() Process control.
remove_client(name), disable_client(name), enable_client(name) Client access control.
ls_target, cat_target, tail_target, tail_target_log, head_target, head_target_log, grep_target, get_working_directory Shell-like inspection of a site's workspace (requires shell_commands rights).
configure_site_log(config, target="all") Change site logging.
set_timeout(value) / unset_timeout() Per-session command timeout.
register_study, add_study_site, remove_study_site, remove_study, list_studies, show_study, add_study_user, remove_study_user Multi-study management.

Exceptions

The FLARE API raises instead of returning error statuses. Exceptions are defined in nvflare.fuel.flare_api.api_spec:

Exception Meaning
NoConnection Cannot reach the server.
AuthenticationError / AuthorizationError Login failed / not permitted.
SessionClosed, SessionExpired The session is no longer usable.
InvalidJobDefinition Bad job folder (missing, wrong type, or unsupported name).
InvalidArgumentError Bad argument type or value.
JobNotFound, JobNotRunning, JobNotDone Job state errors.
JobTimeout wait_for_job timed out.
SubmitTokenConflict, SubmitTokenJobDeleted Retry-token conflicts (see nvflare job submit).
InternalError The server returned an unexpected response, for example no job ID.
NoClientsAvailable, ClientsStillRunning, InvalidTarget, NoReply, CommandError Operational errors.

See Also