panaetius.config panaetius.config¶
-
class
panaetius.config.Config(path: str, header: str = 'panaetius')[source]¶ Bases:
objectHandles the config options for the module and stores config variables to be shared.
Variables: - config_file (dict) – Contains the config options. See
read_config()for the data structure. - deferred_messages (list) – A list containing the messages to be logged once the logger has been instantiated.
- Mask (panaetius.db.Mask) – Class to mask values in a config file.
- module_name (str) – A string representing the module name. This is added in front of all envrionment variables and is the title of the config.toml.
- path (str) – Path to config file
Parameters: path (str) – Path to config file
-
read_config(path: str, write: bool = False) → Optional[dict][source]¶ Reads the toml config file from path if it exists.
Parameters: - path (str) – Path to config file. Should not contain config.toml
- header (str) –
Header to overwrite if using in a module.
Example:
path = '~/.config/panaetius'
Returns: Returns a dict if the file is found else returns nothing.
The dict contains a key for each header. Each key corresponds to a dictionary containing a key, value pair for each config under that header.
Example:
[panaetius] [panaetius.foo] foo = bar
Returns a dict:
{'panaetius' : {foo: {'foo': 'bar'}}}Return type: Union[dict, None]
-
get(key: str, default: str = None, cast: Callable = None, mask: bool = False) → Optional[str][source]¶ Retrives the config variable from either the config.toml or an environment variable. Will default to the default value if nothing is found
Parameters: - key (str) – Key to the configuration variable. Should be in the form panaetius.variable or panaetius.header.variable. When loaded, it will be accessable at Config.panaetius_variable or Config.panaetius_header_variable.
- default (str, optional) – The default value if nothing is found. Defaults to None.
- cast (Callable, optional) – The type of the variable. E.g int or float. Should reference the type object and not as string. Defaults to None.
Returns: Will return the config variable if found, or the default.
Return type: Any
- config_file (dict) – Contains the config options. See