panaetius.library panaetius.library¶
-
panaetius.library.set_config(config_inst: Type[config_inst_t], key: str, default: Optional[str] = None, cast: Optional[Any] = None, check: Union[None, List[T]] = None, mask: bool = False) → None[source]¶ Sets the config variable on the instance of a class.
Parameters: - config_inst (Type[config_inst_t]) – Instance of the
Configclass. - key (str) – The key referencing the config variable.
- default (str, optional) – The default value.
- mask (bool, optional) – Boolean to indiciate if a value in the config.toml should be masked. If this is set to True then the first time the variable is read from the config file the value will be replaced with a hash. Any time that value is then read the hash will be compared to the one stored and if they match the true value will be returned. This is stored in a sqlite .db next to the config file and is hidden by default. If the hash provided doesn’t match the default behaviour is to update the .db with the new value and hash the value again. If you delete the database file then you will need to set the value again in the config.toml.
- cast (Any, optional) – The type of the variable.
- check (Union[None, List], optional) –
Type of object to check against. This is useful if you want to use TOML to define a list, but want to make sure that a string representation of a list will be loaded properly if it set as an environment variable.
Example:
config.toml has the following attribute set:
[package.users] auth = ['user1', 'user2']
If set as an environment variable you can pass this list as a string and set
check=list:Environment variable: PACKAGE_USERS_AUTH = "['user1', 'user2']"
Usage in code:
set_config(CONFIG, 'users.auth', check=list)
- config_inst (Type[config_inst_t]) – Instance of the