All Projects → wbaek → theconf

wbaek / theconf

Licence: MIT license
Python Package for Managing Configurations

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to theconf

Config
📝 Go config manage(load,get,set). support JSON, YAML, TOML, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名
Stars: ✭ 225 (+542.86%)
Mutual labels:  config, yaml, config-management
Config
PHP library for simple configuration management
Stars: ✭ 39 (+11.43%)
Mutual labels:  config, yaml, config-management
parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (+145.71%)
Mutual labels:  config, yaml, argument-parser
Config
A lightweight yet powerful config package for Go projects
Stars: ✭ 126 (+260%)
Mutual labels:  config, config-management
Dynaconf
Configuration Management for Python ⚙
Stars: ✭ 2,082 (+5848.57%)
Mutual labels:  config, yaml
Gray Matter
Contributing Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Stars: ✭ 2,105 (+5914.29%)
Mutual labels:  config, yaml
Cfgdiff
diff(1) all your configs
Stars: ✭ 138 (+294.29%)
Mutual labels:  config, yaml
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (+371.43%)
Mutual labels:  config, yaml
Assh
💻 make your ssh client smarter
Stars: ✭ 2,340 (+6585.71%)
Mutual labels:  config, config-management
luban
你的最佳游戏配置解决方案 {excel, csv, xls, xlsx, json, bson, xml, yaml, lua, unity scriptableobject} => {json, bson, xml, lua, yaml, protobuf(pb), msgpack, flatbuffers, erlang, custom template} data + {c++, java, c#, go(golang), lua, javascript(js), typescript(ts), erlang, rust, gdscript, protobuf schema, flatbuffers schema, custom template} code。
Stars: ✭ 1,660 (+4642.86%)
Mutual labels:  config, yaml
Vscode Data Preview
Data Preview 🈸 extension for importing 📤 viewing 🔎 slicing 🔪 dicing 🎲 charting 📊 & exporting 📥 large JSON array/config, YAML, Apache Arrow, Avro, Parquet & Excel data files
Stars: ✭ 245 (+600%)
Mutual labels:  config, yaml
coqpit
Simple but maybe too simple config management through python data classes. We use it for machine learning.
Stars: ✭ 67 (+91.43%)
Mutual labels:  yaml, config-management
Config Lite
A super simple & flexible & useful config module.
Stars: ✭ 78 (+122.86%)
Mutual labels:  config, yaml
Hiyapyco
HiYaPyCo - A Hierarchical Yaml Python Config
Stars: ✭ 58 (+65.71%)
Mutual labels:  config, yaml
transfer
Converts from one encoding to another. Supported formats HCL ⇄ JSON ⇄ YAML⇄TOML⇄XML⇄plist⇄pickle⇄properties ...
Stars: ✭ 70 (+100%)
Mutual labels:  config, yaml
Mconfig
MCONFIG is a lightweight Golang library for integrating configs files like (json, yml, toml) and environment variables into one config struct.
Stars: ✭ 28 (-20%)
Mutual labels:  config, yaml
Home Assistant Config
Home Assistant config files, rewritten to use the latest features, 100+ documented automations, automatically generated ToC 🏠 🤖
Stars: ✭ 926 (+2545.71%)
Mutual labels:  config, yaml
exenv
Exenv makes loading environment variables from external sources easy.
Stars: ✭ 35 (+0%)
Mutual labels:  config, yaml
Strictyaml
Type-safe YAML parser and validator.
Stars: ✭ 836 (+2288.57%)
Mutual labels:  config, yaml
Config Rs
⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Stars: ✭ 915 (+2514.29%)
Mutual labels:  config, config-management

theconf

CodeFactor CircleCI

Python Package for Managing Configurations

python module 전역에서 쉽게 활용 가능한 global config util및 config를 쉽고 안전하게(실수를 예방하며) 활용가능한 Config전용 ArgumentParser확장 모듈

install

$ pip install git+https://github.com/wbaek/theconf.git

Config

Config는 main문에서 yaml 파일로 객체를 생성하고 어디서나 Config.get_instatnce()로 객체를 가져다 쓸 수 있다. (singleton pattern)

  • sample_config.yaml
value: string
foo:
    bar: text
    baz: 123
data:
    string: text
    int: 1
    float: 0.1
    list: [1, 2, 3]
    dict:
        key: value
>>> from theconf import Config
>>> _ = Config('sample_config.yaml')
>>> Config.get_instance()['value']
'string'
>>> Config.get_instance()['foo']
{'bar': 'text', 'baz': 123}
>>> Config.get_instance()['data']['float']
0.1
>>> _ = Config('sample_config.yaml')
Exception: This class is a singleton!

shorten

>>> from theconf import Config as C
>>> _ = C('sample_config.yaml')
>>> C.get()['value']
'string'

namedtuple

namedtuple are invalid if they are repeated or conflict with Python keywords.

>>> from theconf import Config as C
>>> _ = C('sample_config.yaml')
>>> C.get().value
'string'

extra infomations

  • git info

git 정보를 가져 올 수 있을때 config에 정보를 기본으로 가지고 있는다.

_git:
  branch: dev/implements
  commit:
    comment: 'fix some style

      '
    hash: 07564c36d2b3337597cbfebe0dbf1bf0f9a90bd0
  remote: https://github.com/wbaek/theconf.git
  status:
    diff:
    - path: README.md
      type: M
    untracked: []
  • version & timestamp

version정보는 dump할때마다 1씩 증가하며 timestamp는 Config객체가 생성 시점을 기록한다.

_timestamp: 2018/11/14 16:30:31
_version: 2

ConfigArgumentParser

Config에 있는 변수를 실행시점에 변경하거나 추가로 정의하고 싶을때 사용한다. 기존에 정의되어 있는 Config에 값을 overwrite하고 싶을때 --key value 형식으로 입력하면되고 기본적인 key의 존재여부 및 value의 type을 확인한다. ArgumentParser를 상속받아 구현하여 기본적으로 ArgumentParser와 사용법이 동일하다.

  • sample_config.py
from theconf import Config, ConfigArgumentParser
parser = ConfigArgumentParser(conflict_handler='resolve')
parser.add_argument('--added', type=str, default='NOT_EXIST_CONFIG', help='ADDED_FROM_ARGPARSER')
parser.add_argument('--dump', type=str, default=None, help='config dump filepath')
parsed_args = parser.parse_args()
print(parsed_args)
print(Config.get_instance())

if parsed_args.dump:
    Config.get_instance().dump(parsed_args.dump)
$ python sample_config.py -h
usage: sample_config.py -c CONFIG [CONFIG ...]
sample_config.py: error: the following arguments are required: -c/--config

$ python simple_config.py -c sample_config.yaml -h
usage: sample.py -c CONFIG [CONFIG ...] [-h] [--value VALUE] [--foo-bar FOO_BAR]
                 [--foo-baz FOO_BAZ] [--data-string DATA_STRING]
                 [--data-int DATA_INT] [--data-float DATA_FLOAT]
                 [--data-list [DATA_LIST [DATA_LIST ...]]]
                 [--data-dict-from DATA_DICT_FROM] [--added ADDED]
                 [--dump DUMP]

optional arguments:
  -c CONFIG [CONFIG ...], --config CONFIG [CONFIG ...]
                        set config filepath
  -h, --help            show this help message and exit
  --value VALUE         set str value (default:string)
  --foo-bar FOO_BAR     set str value (default:text)
  --foo-baz FOO_BAZ     set int value (default:123)
  --data-string DATA_STRING
                        set str value (default:text)
  --data-int DATA_INT   set int value (default:1)
  --data-float DATA_FLOAT
                        set float value (default:0.1)
  --data-list [DATA_LIST [DATA_LIST ...]]
                        set int list (default:[1, 2, 3])
  --data-dict-from DATA_DICT_FROM
                        set str value (default:to)
  --added ADDED         ADDED_FROM_ARGPARSER
  --dump DUMP           config dump filepath

$ python sample_config.py -c sample_config.yaml
Namespace(added='NOT_EXIST_CONFIG', config='sample_config.yaml', data_dict_from='to', data_float=0.1, data_int=1, data_list=[1, 2, 3], data_string='text', dump=None, foo_bar='text', foo_baz=123, value='string')
filename:sample_config.yaml
conf:{'value': 'string', 'foo': {'bar': 'text', 'baz': 123}, 'data': {'string': 'text', 'int': 1, 'float': 0.1, 'list': [1, 2, 3], 'dict': {'from': 'to'}}, 'config': 'sample_config.yaml', 'added': 'NOT_EXIST_CONFIG', 'dump': None}

$ python sample_config.py -c sample_config.yaml --data-float 10
Namespace(added='NOT_EXIST_CONFIG', config='sample_config.yaml', data_dict_from='to', data_float=10.0, data_int=1, data_list=[1, 2, 3], data_string='text', dump=None, foo_bar='text', foo_baz=123, value='string')
filename:sample_config.yaml
conf:{'value': 'string', 'foo': {'bar': 'text', 'baz': 123}, 'data': {'string': 'text', 'int': 1, 'float': 10.0, 'list': [1, 2, 3], 'dict': {'from': 'to'}}, 'config': 'sample_config.yaml', 'added': 'NOT_EXIST_CONFIG', 'dump': None}

$ python sample_config.py -c sample_config.yaml --data-float 10 --dump here.yaml
Namespace(added='NOT_EXIST_CONFIG', config='sample_config.yaml', data_dict_from='to', data_float=10.0, data_int=1, data_list=[1, 2, 3], data_string='text', dump='here.yaml', foo_bar='text', foo_baz=123, value='string')
filename:sample_config.yaml
conf:{'value': 'string', 'foo': {'bar': 'text', 'baz': 123}, 'data': {'string': 'text', 'int': 1, 'float': 10.0, 'list': [1, 2, 3], 'dict': {'from': 'to'}}, 'config': 'sample_config.yaml', 'added': 'NOT_EXIST_CONFIG', 'dump': 'here.yaml'}

$ cat here.yaml
added: NOT_EXIST_CONFIG
config: sample_config.yaml
data:
  dict: {from: to}
  float: 10.0
  int: 1
  list: [1, 2, 3]
  string: text
dump: here.yaml
foo: {bar: text, baz: 123}
value: string

$ python sample_config.py -c sample_config.yaml --not-exists
usage: sample_config.py -c CONFIG [CONFIG ...] [-h] [--value VALUE] [--foo-bar FOO_BAR]
                        [--foo-baz FOO_BAZ] [--data-string DATA_STRING]
                        [--data-int DATA_INT] [--data-float DATA_FLOAT]
                        [--data-list [DATA_LIST [DATA_LIST ...]]]
                        [--data-dict-from DATA_DICT_FROM] [--added ADDED]
                        [--dump DUMP]
sample_config.py: error: unrecognized arguments: --not-exists

Multiple Configs

Config파일을 여러개를 입력으로 받아 목적에 따라 나눠서 관리하고 합쳐서 사용한다. config파일에 동일한 key값이 존재하면 나중에 입력받은 config로 overwrite하고 key가 없다면 추가된다.

$ python sample.py -c config.yaml extra.yaml
Namespace(added='NOT_EXIST_CONFIG', config=['config.yaml', 'extra.yaml'], data_dict_from='to', data_float=0.1, data_float2=0.3, data_int=1, data_list=[1, 2, 3], data_string='new text', dump=None, foo_bar='text', foo_baz=123, value='string')
_timestamp: 2021/01/22 19:58:04
_version: 2
added: NOT_EXIST_CONFIG
config:
- config.yaml
- extra.yaml
data:
  dict:
    from: to
  float: 0.1
  float2: 0.3
  int: 1
  list:
  - 1
  - 2
  - 3
  string: new text
dump: null
foo:
  bar: text
  baz: 123
value: string

AverageMeter \w log for tensorboard & mlflow

import torch
import mlflow
from theconf import Config, ConfigArgumentParser, AverageMeter
parser = ConfigArgumentParser(conflict_handler='resolve')
parser.add_argument('--added', type=str, default='NOT_EXIST_CONFIG', help='ADDED_FROM_ARGPARSER')
parser.add_argument('--dump', type=str, default=None, help='config dump filepath')

# build model & dataloader

meter = AverageMeter('loss', tensorboard_path='./tensorboard', prefixs=['train', 'valid'])
with mlflow.start_run(run_name='test'):
    Config.get().mlflow_log_pararms() # log params
    for epoch in range(10):
        model.train()
        for inputs, targets in dataloader: 
            logit = model.forward(inputs)
            loss = criterion(logit, targets)
            meter.update('loss', loss)
        print(meter.get())
        meter.log('train', tensorboard=True, mlflow=True)
        meter.reset(step=epoch)
        
        model.eval()
        for inputs, targets in dataloader: 
            logit = model.forward(inputs)
            loss = criterion(logit, targets)
            meter.update('loss', loss)
        print(meter.get())
        meter.log('valid', tensorboard=True, mlflow=True)
        meter.reset(step=epoch)

        torch.save(model.state_dict(), 'last.pth.tar')
        mlflow.log_artifact('last.pth.tar', 'checkpoints')
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].