merge multi level configurations
Project description
configmerger
merge multi level configurations.
Usage
from configmerger import Merger
# your configurations, read from app.json, machine.yaml, user.toml, or more
confs = [
read_from_app(),
read_from_machine(),
read_from_user(),
]
# merge all configurations into one.
runtime_conf = Merger().merge(confs)
Merge Rules
Here is the default merge rules:
merger = Merger()
# for dict, a little like Chainmap
merger.merge([
{'a': 1},
{'a': 2, 'b': 3},
{ 'b': 4}
])
# {'a': 2, 'b': 4}
# for list, default behavior is connect each
# change `merger.connect_list` to `False` can change this behavior
merger.merge([ [1, 2, 3], [4, 5] ]) # [4, 5, 1, 2, 3]
# for str, int and others, latest have highest priority
merger.merge([ 'first', 'last' ]) # 'last'
# basic, `None` is ignored
merger.merge([ 1, None ]) # 1
# but if all values is `None`, return `None`
merger.merge([ None, None ]) # None
# if type changed, merge will stop,
merger.merge([
{'a': 1}, # <--- ignored
1, # <--- type changed, ignore all before this
{'b': 2},
None, # <--- None is ignored
{'c': 3},
])# {'b': 2, 'c': 3}
Override any methods to modify the default behavior.
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
configmerger-0.2.0.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file configmerger-0.2.0.tar.gz
.
File metadata
- Download URL: configmerger-0.2.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.9.6 Linux/5.8.0-1040-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02e2b028f099bff6ac8ad032a34734f14383a3c999e2f7058b0d70536feffbad |
|
MD5 | 68bdb888ab6a0bdfae03c9cc8620ce67 |
|
BLAKE2b-256 | 804ab4cd29d02638c1da6665764b0cfb306f582d77cc908bd12c85ac7e198a46 |
File details
Details for the file configmerger-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: configmerger-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.9.6 Linux/5.8.0-1040-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | adb3203ed0f49baf5604a2f9c50ab27cdafcd3d2d226eaa0ba4f93fa22a41a6f |
|
MD5 | c52d79765c8445bcf7f3845e7a1f4d6b |
|
BLAKE2b-256 | 5720bdc453a241c1d86a424c1b76ea223656b900a54303c55449c927b43a11f6 |