Simple config supporting CLI modification
Project description
sconf: Simple config system supporting CLI modification
sconf is yaml-based simple config library.
Features
- Supports merging multiple configs
- Supports CLI modification
- Supports coloring modified key-values
Install
$ pip install sconf
Usage
Initialize
Basic init
from sconf import Config
cfg = Config(default="configs/defaults.yaml")
cfg.argv_update() # apply CLI modification
Init with argparse and multiple configs
import argparse
from sconf import Config
parser = argparse.ArgumentParser()
parser.add_argument("name")
parser.add_argument("config_paths", nargs="*")
parser.add_argument("--show", action="store_true", default=False)
args, left_argv = parser.parse_known_args()
# merging multiple configs if given
cfg = Config(*args.config_paths, default="configs/defaults.yaml")
cfg.argv_update(left_argv)
Dumps
sconf has two dumping methods, dumps
and yaml
. dumps
return colorized contents for modified items without comments and yaml
return contents and comments without coloring.
# dump with coloring modified items
print(cfg.dumps())
# dump with comments
print(cfg.yamls())
Access
sconf has same interface with dictionary:
# access
print(cfg['key'])
print(cfg['key1']['key2'])
# get
print(cfg.get('non-key', 'default-value'))
# unpacking
function(**cfg['model'])
CLI modification
sconf supports CLI modification like argparse. Also you can access to the child key using dot.
# yaml example
batch_size: 64
model:
encoder:
n_channels: 64
decoder:
n_channels: 64
- CLI modification:
> python train.py --batch_size 128 --model.encoder.n_channels 32
- Accessing via partial key is also available:
> python train.py --encoder.n_channels 32
- Use triple dashs
---
if you want to modify multiple keys:
# modifying encoder.n_channels and decoder.n_channels both.
> python train.py ---n_channels 32
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
sconf-0.1.2-py3-none-any.whl
(6.9 kB
view hashes)