nvflare.utils.configs module

Utilities for reading configuration files.

get_client_config_value(fl_ctx: FLContext, key: str, default: Any | None = None) Any[source]

Read a value from config_fed_client.json.

This utility function reads top-level configuration values from the client config JSON file. Jobs can set these values using recipe.add_client_config({“key”: value}).

Parameters:
  • fl_ctx – FLContext

  • key – The configuration key to read

  • default – Default value if key is not found or reading fails. Defaults to None.

Returns:

The configuration value if found, otherwise the default value.

Example

```python from nvflare.utils.configs import get_client_config_value from nvflare.client.constants import EXTERNAL_PRE_INIT_TIMEOUT

# In your executor’s initialize method: timeout = get_client_config_value(fl_ctx, EXTERNAL_PRE_INIT_TIMEOUT, default=300.0) ```

get_job_config_value(fl_ctx: FLContext, config_file: str, key: str, default: Any | None = None) Any[source]

Generic function to read from any job config file.

Parameters:
  • fl_ctx – FLContext

  • config_file – Name of the config file (e.g., JobConstants.CLIENT_JOB_CONFIG)

  • key – The configuration key to read

  • default – Default value if key is not found or reading fails. Defaults to None.

Returns:

The configuration value if found, otherwise the default value.

get_server_config_value(fl_ctx: FLContext, key: str, default: Any | None = None) Any[source]

Read a value from config_fed_server.json.

This utility function reads top-level configuration values from the server config JSON file. Jobs can set these values using recipe.add_server_config({“key”: value}).

Parameters:
  • fl_ctx – FLContext

  • key – The configuration key to read

  • default – Default value if key is not found or reading fails. Defaults to None.

Returns:

The configuration value if found, otherwise the default value.

Example

```python from nvflare.utils.configs import get_server_config_value

# In your controller’s initialize method: custom_param = get_server_config_value(fl_ctx, “custom_param”, default=”default_value”) ```