Skip to main content

Simple config supporting CLI modification

Project description

codecov PyPI - Python Version PyPI

sconf: Simple config system supporting CLI modification

sconf is yaml-based simple config library.


  • Supports merging multiple configs
  • Supports CLI modification with argparse-like interface
  • Supports coloring modified key-values
  • Supports global access to config objects


$ pip install sconf



A Minimal Example

from sconf import Config

cfg = Config(default="configs/defaults.yaml")  # load yaml
cfg.argv_update()  # apply CLI modification

You can modify cfg by CLI in the runtime, with argparse-like interface.

Init with argparse and multiple configs

import argparse
from sconf import Config

parser = argparse.ArgumentParser()
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")


python example configs/exp.yaml --lr 0.1

The resulting cfg is based on configs/defaults.yaml, merged with configs/exp.yaml, and updated by --lr 0.1.


sconf dumps contents with coloring modified items.


# If you do not want to colorize:


  • Item access with dictionary-like interfaces:
# access

# get
print(cfg.get('non-key', 'default-value'))

# unpacking
  • Attribute access:
  • Note that the attribute access returns method object for the duplicated key, unlike the item access.
cfg = Config({'get': 2})

print(cfg['get'])  # 2
print(cfg.get)  # method object

CLI modification

sconf supports CLI modification like argparse. Also you can access to the child key using dot.

# yaml example
batch_size: 64
        n_channels: 64
        n_channels: 64
  • CLI modification:
> python --batch_size 128 --model.encoder.n_channels 32
  • Accessing via partial key is also available:
> python --encoder.n_channels 32
  • Use triple dashs --- if you want to modify multiple keys:
# modifying encoder.n_channels and decoder.n_channels both.
> python ---n_channels 32

Global access to config object

Global access is useful in ML project, even though it can be anti-pattern in SW engineering.

cfg = Config({'weight_decay': 0.001})  # automatically registered first config to 'default' key

cfg = Config.from_registry()  # get 'default' config
print(cfg.weight_decay)  # 0.001

Note that registry_key helps global access to multiple configs.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for sconf, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size sconf-0.2.2-py3-none-any.whl (8.5 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page