A simple configuration files manager package
Project description
ConfigDmanager
Installation
A simple pip install will do :
python -m pip install ConfigDmanager
Use
-
Suppose we have two Configuration files ( of json type ) :
-
ParentConfig.json :
{ "__name": "ParentConfig", "param1": "Value 1" }
-
MainConfig.json :
- The __parent parameter specifies the path to another configuration file that will give us default values ( Think of it as inheritance ).
- The text contained between brackets will be reinterpreted in runtime :
in the example below {param1} will be reinterpreted as "Value 1"
- The use of environment variables for sensitive data like passwords is also possible : through this text {os_environ[password]}
- You can also read the content of a text file with a simple : {read_file[file_path]} as shown in the example below.
{ "__name": "MainConfig", "__parent": "demo.ParentConfig", "param2": "Value 2 and {param1}", "user_info": {"user": "username", "password": "{os_environ[password]}"}, "long_text": "{read_file[./demo.py]}" }
-
-
To import those configuration using configDmanager, use this demo code :
from configDmanager import import_config
class RandomClass:
def __init__(self, param1, param2, user_info, long_text):
print(f"param1: {param1}")
print(f"param2: {param2}")
print(f'my user: {user_info.user}')
print(f'my user: {user_info.password}')
print(f'my long text: "{long_text[:40]}"')
config = import_config('MainConfig')
print("## Object 1")
obj = RandomClass(**config)
# You can also select specific keys
print("## Object 2")
another_obj = RandomClass(param2='Another Value', long_text="Not so long", **config[['param1', 'user_info']])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ConfigDmanager-0.0.3.tar.gz
(4.7 kB
view hashes)
Built Distribution
Close
Hashes for ConfigDmanager-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce370f7e63345750bf6dafe0237d0cce76399022c7703478c75cffdc0f843835 |
|
MD5 | eb55e98ccde46613db3f3a6bcb8e94cd |
|
BLAKE2b-256 | 00326a68e895d1a0350f272cdafd2128402a33e795239a300293b9b8fd6594e4 |