nvflare.utils.configs module
Utilities for reading configuration files.
- get_client_config_value(fl_ctx: FLContext, key: str, default: Any | None = None, *, resolve_refs: bool = True) 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}). By default, secret references in the selected value are resolved recursively when it is read; dictionary keys are unchanged.
- Parameters:
fl_ctx – FLContext
key – The configuration key to read
default – Default value if key is not found or reading fails. Defaults to None.
resolve_refs – Whether to resolve secret references in the selected value. Defaults to True. Consumers that may serialize the returned value must disable resolution and reject references.
- Returns:
The configuration value if found, otherwise the default value.
- Raises:
ValueError – If
resolve_refsis True and the selected value contains a malformed reference, a referenced environment variable is unset, or a referenced file cannot be read.
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, *, resolve_refs: bool = True) Any[source]
Generic function to read from any job config file.
By default, secret references in the selected value are resolved recursively at this runtime boundary. This helper reads the exported JSON directly, so ordinary NVFlare placeholders such as
{SITE_NAME}are not expanded here and remain literal in the returned value, even when they appear alongside secret references.- 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.
resolve_refs – Whether to resolve secret references in the selected value. Defaults to True. Internal consumers that may serialize the value again must set this to False and reject references rather than persisting resolved secret material.
- Returns:
The configuration value if found, otherwise the default value.
- Raises:
ValueError – If
resolve_refsis True and the selected value contains a malformed reference, a referenced environment variable is unset, or a referenced file cannot be read.
- get_server_config_value(fl_ctx: FLContext, key: str, default: Any | None = None, *, resolve_refs: bool = True) 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}). By default, secret references in the selected value are resolved recursively when it is read; dictionary keys are unchanged.
- Parameters:
fl_ctx – FLContext
key – The configuration key to read
default – Default value if key is not found or reading fails. Defaults to None.
resolve_refs – Whether to resolve secret references in the selected value. Defaults to True. Consumers that may serialize the returned value must disable resolution and reject references.
- Returns:
The configuration value if found, otherwise the default value.
- Raises:
ValueError – If
resolve_refsis True and the selected value contains a malformed reference, a referenced environment variable is unset, or a referenced file cannot be read.
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”) ```