class documentation

Class for storing configuration.

Class Method get_config Load config from a yaml file or a dictionary.
Method __repr__ Undocumented
Method __str__ Undocumented
Method get Return a value from the config based on the given key.
Method get_json_schema Return the JSON schema of the config.
Method save_data Save the config to a YAML file.
Static Method _merge_overrides Merge the config dictionary with the CLI overrides.

Inherited from BaseModelExtraForbid:

Instance Variable model_config Pydantic model configuration with extra set to "forbid".
@classmethod
def get_config(cls, cfg: PathType | Params | None = None, overrides: Params | dict[str, Any] | list[str] | tuple[str, ...] | None = None) -> Self:

Load config from a yaml file or a dictionary.

Parameters
cfg:PathType | Params | NonePath to a config file or a dictionary.
overrides:Params | dict[str, Any] | list[str] | tuple[str, ...] | NoneCLI overrides. Can be a dictionary mapping "dotted" keys to unparsed string or Python values, or a list or a tuple of alternating key-value pairs.
Returns
SelfInstance of the config class.
Raises
ValueErrorIf neither cfg nor overrides is provided, or if overrides is a list or a tuple with an odd number of items.
def __repr__(self) -> str:

Undocumented

def __str__(self) -> str:

Undocumented

def get(self, key_merged: str, default: Any = None) -> Any:

Return a value from the config based on the given key.

If the key doesn't exist, the default value is returned.

Parameters
key_merged:strKey as a string with levels separated by dots.
default:AnyDefault value to return if the key doesn't exist.
Returns
AnyValue of the key, or the default value.
Raises
ValueErrorIf a list is accessed with a non-integer key.
@deprecated('Use `model_json_schema(mode=\'validation\')` instead.')
def get_json_schema(self) -> Params:

Return the JSON schema of the config.

Deprecated since version 0.9.0: Use model_json_schema(mode='validation') instead.
Returns
ParamsDictionary with the JSON schema.
def save_data(self, path: PathType):

Save the config to a YAML file.

Parameters
path:PathTypePath to the file where the config should be saved.
@staticmethod
def _merge_overrides(data: Params, overrides: Params):

Merge the config dictionary with the CLI overrides.

The overrides are a dictionary mapping "dotted" keys to either final or unparsed values.

Parameters
data:ParamsDictionary with config data.
overrides:ParamsDictionary with CLI overrides.
Raises
ValueErrorIf the overrides contain an invalid option.