Skip to main content

Boosted dictionaries to make complex and nested configuration files easier

Project description

Kahnfigh

Load a yaml file:

from kahnfigh import Config
config = Config('sample.yaml')

Access keys using xpath syntax:

config['Model/Architecture/Dense/units']

Edit existing values:

config['Model/Architecture/Dense/units'] = 128

If the path doesn't exist, it will automatically create it:

config['Model/Architecture/MyNewLayer/units'] = 88

Moreover, you might want to find all paths matching a pattern. Use a wildcard:

config['Model/Architecture/*/units']

If there was a list in config['Model/Architecture'], then it will return all the value of key 'units' of all elements of the list which have that key

You can also do some more elaborate but handy things like:

config['Model/Architecture/*/[units=88]/name']

This will return the value of key name of all elements of the list in Architecture which have the pair key:value units:88

Sometimes it is really hard to work with nested dictionaries. Use to_shallow() and turn it into a depth-1 dictionary:

shallow = config.to_shallow()

Then, after some modifications, you might want to go back to a nested dictionary:

from kahnfigh.core import shallow_to_deep

nested = shallow_to_deep(shallow)

Also, you may want to create custom behaviours. For example, if we want a value to be replaced by a variable when the symbol $ appears, we can do:

config['Model/name']
# this returns: $model_name
config['Model/Architecture/ConvLayer/filters']
# this returns: $n_filters

params = {'model_name': 'CNN-LSTM',
          'n_filters': 64}
config.replace_on_symbol('$',lambda x: params[x])

config['Model/name']
#this now returns: CNN-LSTM
config['Model/Architecture/ConvLayer/filters']

#this now returns: 64

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

kahnfigh-0.0.4.tar.gz (6.6 kB view details)

Uploaded Source

File details

Details for the file kahnfigh-0.0.4.tar.gz.

File metadata

  • Download URL: kahnfigh-0.0.4.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for kahnfigh-0.0.4.tar.gz
Algorithm Hash digest
SHA256 067dd58fcf0675a55f3e1cb9c240a6602d754b79ab590c9c55c8415925866780
MD5 33ade859eb162d4ef9003b720339fcdc
BLAKE2b-256 5cbc2c5b52be7e426b12c64390e2885ce5017cc7111e74d5f56631fafcb5a361

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page