A config util package to flatten-reduce long keys
Project description
Config (YAML/JSON) Keys Flatten-Reducer
conduce - A simple config package which flatten-reduces all keys of either a YAML or JSON config
to allow a simple way to get values from long keys.
Installation
pip install conduce
some.yaml
alpha:
beta:
gamma: "hello"
some.json:
{"alpha": {"beta": {"gamma": "world"}}}
some_deep_nested.yaml:
alpha:
beta:
gamma:
delta:
theta:
phi:
"finally!!!"
hello:
- 1
- 2
- 3
- rho:
- 10
- 100
- fellow: "end of the road"
example.py:
from conduce import conduce
c1 = conduce.read_yaml(config_name="some.yaml", root_path="some/path/to/the/yaml")
c2 = conduce.read_json(config_name="some.json", root_path="some/path/to/the/json")
c3 = conduce.read_yaml(config_name="some_deep_nested.yaml", root_path="some/path/to/the/yaml")
c4 = conduce.read_config(config_type="json", config_name="some.json", root_path="some/path/to/the/yaml")
c1('alpha.beta.gamma') # returns value "hello"
c2('alpha.beta.gamma') # returns value "world"
c3('alpha.beta.gamma.delta.theta.phi') # returns value "finally!!!"
c4('alpha.beta.gamma') # returns value "world" (same as c2)
c4() # empty key returns full config dictionary of some.json
# NStruct (class object) example
c5 = conduce.read_yaml(config_name="some_deep_nested.yaml",
root_path="some/path/to/the/yaml",
type_obj=True)
c5.alpha.hello[3].rho[2].fellow # returns value "end of the road"
c5.value() # returns the full config dictionary
c5.alpha.hello[3].value() # returns the full dictionary of "rho"
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
conduce-1.1.3.tar.gz
(4.4 kB
view hashes)