smarts.core.configuration module
- class smarts.core.configuration.Config(config_file: str | Path, environment_prefix: str = '')[source]
A configuration utility that handles configuration from file and environment variable.
- Parameters:
config_file (Union[str, pathlib.Path]) – The path to the configuration file.
environment_prefix (str, optional) – The prefix given to the environment variables. Defaults to “”.
- Raises:
FileNotFoundError – If the configuration file cannot be found at the given file location.
- property environment_prefix
The prefix that environment variables configuration is provided with.
- get_setting(section: str, option: str, default: ~typing.Any = <object object>, cast: ~typing.Callable[[~typing.Any], ~typing.Any] = <function _passthrough_cast>) Any | None [source]
Finds the given configuration checking the following in order: environment variable, configuration file, and default.
- Parameters:
section (str) – The grouping that the configuration option is under.
option (str) – The specific configuration option.
default (Any, optional) – The default if the requested configuration option is not found. Defaults to _UNSET.
cast (Callable, optional) – A function that takes a string and returns the desired type. Defaults to str.
- Returns:
The value of the configuration.
- Return type:
Optional[str]
- Raises:
KeyError – If the configuration option is not found in the configuration file and no default is provided.
configparser.NoSectionError – If the section in the configuration file is not found and no default is provided.