Settings¶
Settings enables all parts of pytlas to read config data and is already covered in Settings.
Settings store¶
The settings store holds config data. The global store is available as pytlas.settings.CONFIG property.
-
class
pytlas.settings.
SettingsStore
(config: configparser.ConfigParser = None, additional_lookup: Dict[str, object] = None)¶ Hold application settings with an internal ConfigParser instance. It provides a lot of utility methods to convert settings to particular representations.
Why? You may ask. Because it starts by looking for the given settings into an optional additional lookup dict, if its not found, it will look in the system environment and finally, it will use the ConfigParser instance which is probably loaded from a configuration file.
And since everything in the env are considered as strings, you can use the provided methods to make things easier.
-
get
(setting: str, default: str = None, section='pytlas') → str¶ Gets a setting value, if an environment variable is defined, it will take precedence over the value hold in the inner config object.
For example, if you got a setting ‘lang’ in the ‘pytlas’ section, defining the environment varialbe PYTLAS_LANG will take precedence.
Parameters: - setting (str) – Name of the configuration option
- default (str) – Fallback value
- section (str) – Section to look in
Returns: Value of the setting
Return type: str
-
getbool
(setting: str, default=False, section='pytlas') → bool¶ Gets a boolean value for a setting. It uses the get under the hood so the same rules applies.
Parameters: - setting (str) – Name of the configuration option
- default (bool) – Fallback value
- section (str) – Section to look in
Returns: Value of the setting
Return type: bool
-
getfloat
(setting: str, default=0.0, section='pytlas') → float¶ Gets a float value for a setting. It uses the get under the hood so the same rules applies.
Parameters: - setting (str) – Name of the configuration option
- default (float) – Fallback value
- section (str) – Section to look in
Returns: Value of the setting
Return type: float
-
getint
(setting: str, default=0, section='pytlas') → int¶ Gets a int value for a setting. It uses the get under the hood so the same rules applies.
Parameters: - setting (str) – Name of the configuration option
- default (int) – Fallback value
- section (str) – Section to look in
Returns: Value of the setting
Return type: int
-
getlist
(setting: str, default=[], section='pytlas') → list¶ Gets a list for a setting. It will split values separated by a comma.
It uses the get under the hood so the same rules applies.
Parameters: - setting (str) – Name of the configuration option
- default (list) – Fallback value
- section (str) – Section to look in
Returns: Value of the setting
Return type: list
-
getpath
(setting: str, default: str = None, section='pytlas') → str¶ Gets an absolute path for a setting. If the value is not an absolute path, it will be resolved based on the loaded config file directory.
It uses the get under the hood so the same rules applies.
Parameters: - setting (str) – Name of the configuration option
- default (str) – Fallback value
- section (str) – Section to look in
Returns: Value of the setting
Return type: str
-
load_from_file
(path: str) → None¶ Load settings from a file.
Parameters: path (str) – Name of the file to read
-
set
(setting: str, value: object, section='pytlas') → None¶ Sets a setting value in the _data dictionary so it will take precedence over all the others.
Value will be stringified by this method (since all value can be read from env variables).
Parameters: - setting (str) – Setting key to write
- value (object) – Value to write
- section (str) – Section to write to
-
to_dict
() → Dict[str, str]¶ Gets a flat dictionary representation of this store (combining settings from the config and the ones in additional_data).
Each keys will be converted to an env one so it can be used in an agent meta for example.
Returns: Flat dictionary representing this store Return type: dict
-
write_to_file
(path: str) → None¶ Write this settings store to a file.
Parameters: path (str) – Path to a file to store the resut.
-