nvflare.fuel.utils.config module¶
- class Config(conf: Any, fmt: ConfigFormat, file_path: str | None = None)[source]¶
Bases:
ABC
- get_format() ConfigFormat [source]¶
Returns the current config objects ConfigFormat.
- Returns:
return ConfigFormat
- get_location() str | None [source]¶
Returns the file path where this configuration is loaded from.
- Returns:
None if the config is not from file; else return file path
- get_native_conf()[source]¶
- Returns the original underline config object representation if you prefer to use it directly.
Pyhocon → ConfigTree JSON → Dict OMEGACONF → ConfigDict
- Returns:
A native config object
- abstract to_dict(resolve: bool | None = True) Dict [source]¶
Converts underline config object to dictionary.
- Parameters:
resolve – optional argument to indicate if the variable need to be resolved when convert to dictionary not all underline configuration format support this. If not supported, it is treated default valueTrue.
- Returns:
A converted configuration as dict
- abstract to_str(element: Dict | None = None) str [source]¶
- Converts dict element to the str representation of the underline configuration, if element is not None
For example, for JsonFormat, the method return json string for PyhoconFormat, the method return pyhocon string for OmegaconfFormat, the method returns YAML string representation
If the element is None, return the underline config to string presentation
- Parameters:
element – Optional[Dict]. default to None. dictionary representation of config
- Returns:
string representation of the configuration in given format for the element or config
- class ConfigFormat(value)[source]¶
Bases:
Enum
An enumeration.
- JSON = 'JSON'¶
- OMEGACONF = 'OMEGACONF'¶
- PYHOCON = 'PYHOCON'¶
- class ConfigLoader(fmt: ConfigFormat)[source]¶
Bases:
ABC
- get_format() ConfigFormat [source]¶
Returns the current ConfigLoader’s ConfigFormat.
- Returns:
A ConfigFormat
- abstract load_config(file_path: str) Config [source]¶
Load configuration from config file.
- Parameters:
file_path (str) – file path for configuration to be loaded
- Returns:
A Config
- load_config_from_dict(config_dict: dict) Config [source]¶
Load Configuration based on a given config dict.
- Parameters:
config_dict (dict) – dict for configuration to be loaded
- Returns:
A Config
- load_config_from_str(config_str: str) Config [source]¶
Load Configuration based on the string representation of the underline configuration.
For example, Json String for Jsonformat. python conf string or yaml string presentation
- Parameters:
config_str (str) – string for configuration to be loaded
- Returns:
A Config