Simple Configs Manager
Project description
Python SimpUtils Config
Simplifies working with configs and params.
Description
Class simputils.config.models.ConfigStore
is the keystone of the library.
Object of it represents config, that could be used to sequentially apply different sets of key-value
pairs from different sources (other dicts, files of different kinds, environment variables, etc.).
Object will store the latest values of the applied sets, where the earliest applied values could be overriden by the following ones. Basically, just a dictionary.
But besides being like a dictionary, it records the "history" of applied configs, so it's easier to debug and control from where which value came from.
The major purpose of the functionality comes from using multiple files as sources for your config, but it still allows to apply sets directly from the code.
[!CAUTION]
ConfigStore
object is behaving like adict
, so if you need to check if the variable with this object is None, always check it likeif conf is None:
, and never check it likeif not conf:
!The check is implicit, so when you use
not
or simple boolean check, it will check if the object is empty (does not contain any value)
[!NOTE] To check if
ConfigStore
object contains at least one key-value pair, you can use simpleif conf:
When working with files, keep in mind that the only supported files are .yml
, .env
and .json
.
If you need support for other types, you will have to implement your custom handler for those file-types.
Documentation
Generic examples
Simple Config and EnvVars
import os
from simputils.config.components import ConfigHub
# Sequence of files/values matter!
app_conf = ConfigHub.aggregate(
"data/app-conf.yml",
# This one does not exist, and used only for local redefinitions of developer or stage
"data/app-conf-local.yml",
)
# Sequence of files/values matter!
app_env_vars = ConfigHub.aggregate(
"data/production.env",
# This one does not exist, and used only for local redefinitions of developer or stage
"data/production-local.env",
# This one does not exist, and used only for local redefinitions of developer or stage
".env",
# Environment Variables from OS
os.environ,
)
print("App Conf: ", app_conf)
print("App EnvVars: ", app_env_vars)
App Conf: {
'val-1': 'My conf value 1',
'val-2': 'My conf value 2',
'val-3': 'My conf value 3'
}
App EnvVars: {
'APP_MY_ENV_VAR_1': '1',
'APP_MY_ENV_VAR_2': '2',
'APP_MY_ENV_VAR_3': '3',
...(values from OS env-vars are here)
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for simputils_config-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b30ca2b96788668b5039b21908b725118b44d29369ac63f623f85a53954c217f |
|
MD5 | 7134d6cb30cf6cf0c4e7161285af49a9 |
|
BLAKE2b-256 | 3cc658b672693fe2b5d006a29ecef88bba2db30f7f90521cba6372b5ce8a604c |