easy-configer


Nameeasy-configer JSON
Version 2.5.7 PyPI version JSON
download
home_pagehttps://github.com/HuangChiEn/easy_config
SummaryAn easy way for configurating python program by the given config file or config str
upload_time2025-01-28 05:49:05
maintainerNone
docs_urlNone
authorJosefHuang
requires_python>=3.6
licenseMIT
keywords configuration commendline argument argument
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Project description
#### easy_configer version : 2.5.6
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/HuangChiEn/easy_config/main.yaml)
[![PyPI version](https://badge.fury.io/py/easy-configer.svg?icon=si%3Apython)](https://badge.fury.io/py/easy-configer)
[![Documentation](https://img.shields.io/badge/documentation-link-blue.svg)](https://easy-configer.readthedocs.io/)

![easy-configer logo](https://raw.githubusercontent.com/HuangChiEn/easy_config/master/assets/logo.png)

---

#### pypi v2.5.7 just update README.md..

### ๐Ÿšง TODO list :
0. Release known issue area in v2.5.6 and hot-fix in v2.6.
1. Tag v2.6 as stable version.
2. Next version v3.0 is under development, stateless interface will be introduced as one of new features
3. Nested argument intepolation may be one of features in v3.0
4. You can preview the v3.0 prototype of codebase under ./dev folder 

---

### ๐Ÿž Known issues : 
1. allow_overwrite flag also allow you overwrite the entire section by a config value, most of case it should not a expected behavior (pitfall)
2. Commendline argument CAN NOT update the arguments in sub_config (bug)

---

### Configeruating the program in an easy-way 
I'm willing to provide a light-weight solution for configurating your python program. Hope this repository make every user control their large project more easier ~ ~ 

### Easy-configer document
**Check the documentation released in ReadTheDoc[๐Ÿ”—](https://easy-configer.readthedocs.io/en/latest/), to learn more!**

Easy-config cover the following features :
1. **Hierachical section config (nested dict-like config)**

2. **Accept multiple config file in dynamic loading manner (similar with omegaconf)**

3. **Support customized class (initialized by list or keyword arguments)**

4. **Commend-line add/update declared arguments/sections (even in hierachical section)**

5. **Support the absl style FLAGS functionality (declare once, use anywhere)** 

And, of course the following attributes are supported :

* dot-access of any config argument (even in nested dictionary)

* inline comment '#', now you can write comment in everyline ~

* support config argument interpolation (even in nested dictionary)!

* support config conversion, feel free to use easy_config or the other config tools (omegaconf, argparse, ..., etc.)

* support omegaconf-like dynamic config loading system ~

---

### Newly update features ๐Ÿš€
0. v2.5.4 is basically fine, but it still have several known issues, so we plane to release v2.6 as stable version.
1. Apply \${cfg}, ${env} as argument and enviroment intepolation notation, respectively.
2. Apply AttributeDict container (it inherit pure python dict) to store non-flatten arguments!

---

### Bug Fixed ๐Ÿ›
#### Hot-fix Container bug in v2.5.3, now it'll raise AttributeError while attribute doesn't exists..(fixed in v2.5.4)

---

### Dependencies ๐Ÿ—๏ธ
This package is written for Python 3.8. After refactor in this version, this package also support down to python 3.6!!
Of course, light-weight solution **do not** contain any 3-rd package complex dependencies.
The python standard package (such as pathlib, sys, .., etc) is the only source of dependencies, so you don't need to worry about that ~ ~
> However, if you want to use the IO_Converter for converting config into omegaconf, you still need to install omegaconf for this functionality ~

---

### Installation โš™๏ธ<br>
1. **pypi install** <br>
    simply type the `pip install easy_configer` (due to name conflict of pypi pkg, we use different pkg name)

2. **install from source code** <br>
    clone the project from github : `git clone https://github.com/HuangChiEn/easy_config.git` 
    Chage to the root directory of the cloned project, and type `pip install -e .`

3. **import syntax** <br>
    Wherever you install, pypi or source. Now, you just need a simple import : `from easy_configer.Configer import Configer`
    
---

### Quick start ๐Ÿฅ‚

#### **1. Handy example of config file**
Let's say we have an easy-config for development enviroment on jupyter notebook. we want to define several variable for configurating a simple math calculation.

```python
# config string
cfg_str = '''
title = 'math calculation'@str
coef = 1e-3@float
with_intercept = True@bool
intercept = 3@int
'''

# look's good, let's get the config!
from easy_configer.Configer import Configer
# `cmd_args=False` disable any commendline args 
cfg = Configer(description="math calculation config!", cmd_args=False)
cfg.cfg_from_str(cfg_str)

# oh.. wait, could we do it more easier ?
ez_cfg_str = '''
# opps.. let's change some value
title = 'linear equation'
coef = 15        
'''
# By default, we don't encourage you to overwrite the predefined arguments,  
#        if you want to overwrite it in 'convenient way', you should set `allow_overwrite=True`..
cfg.cfg_from_str(ez_cfg_str, allow_overwrite=True)

lin_equ = lambda x : cfg.coef * x + cfg.intercept if cfg.with_intercept else (cfg.coef * x)
x = 15
print( f"Linear equation with x={x} : { lin_equ(x) }" )
```
> If you want to overwrite previous config, *apply twice* `cfg.cfg_from_str` with `allow_overwrite=True` flag IS NOT a recommended way. In easy-configer, we provide 2 way to do that. The standard way is *declaring 2 config and apply config merging method* to get the updated config. The other way is similar with omegaconf to import sub-config in dynamic manner,  however you still need to set flag `allow_overwrite=True` in `cfg.cfg_from_ini`.

Although writing a string config in python is convenient, it only suitable for the project in smaller scale. In large project, we may write a config file to control the program, so that we will be easy to trace, check and debug the config. We are going to prepare a sample config called `test_cfg.ini` in the working directory and describe how we work with chatbot roughly. 

#### In easy-configer, there're two type of argument in config : flatten argument, hierachical argument. You will see that the flatten arguments are directly placed in config and doesn't belong any section (namely in first level). In contrast, the hierachical arguments will be placed in section (i.e. `[db_setup]`) with any kind of depth, the arguments under the section will be wrapped by a container (`easy_configer.utils.Container.AttributeDict`) similar with pure python `dict`. 

#### To form a hierachical argument in nested section, we apply toml-like syntax to describe the nested section (i.e. `[bknd_srv.mod_params]` is belong to `[bknd_srv]` parent section). The arguments in nested section are also wrapped by nested AttributeDict. Besides you can access all kind of arguments by the simple dot-operator, however, we still recommend you to use key-string as pure python dict.
> Note that the recommended way to access the argument is **still** key-string access `cfger.args['#4$%-var']`, as you may notice, dot-access doesn't support **ugly** variable name (`cfger.#4$%-var`, as variable name is invalid in python intepreter). 
    
```ini
# ./test_cfg.ini
# '#' denote comment line, the inline comment is also supported!

# define 'flatten' arguments :
serv_host = '127.0.0.1'  
serv_port = 9478@int    # specific type is also allowed!!
api_keys = {'TW_REGION':'SV92VS92N20', 'US_REGION':'W92N8WN029N2'}

# define 'hierachical' arguments :
# the 'section' is the key of accessing AttributeDict's value and could be defined as follows :
[db_setup]
    db_host = ${cfg.serv_host}:80@str
    # first `export mongo_port=5566` in your bash, then support os.env interpolation!
    db_port = ${env.mongo_port}  
    snap_shot = True

# and then define second section for backend server..
[bknd_srv]
    load_8bit = True
    async_req = True
    chat_mode = 'inference'
    model_type = 'LlaMa2.0'
    [bknd_srv.mod_params]
        log_hist = False
        tempeture = 1e-4
        model_mode = ${cfg.bknd_srv.chat_mode}  # hierachical args interpolation
```

<br>

Now, we're free to launch the chatbot via `python quick_start.py` (*quick_start.py in work directory*)!
However, you can also overwrite the arguemnts via commendline `python quick_start.py serv_port=7894 bknd_srv.chat_mode=predict@str`
> Note that **update argument** from commendline is naturally permitted, but overwrite **the section** IS NOT! If you also want to overwrite the section, you need to set flag `allow_overwrite=True`. 

```python
import sys

# main_block 
if __name__ == "__main__":
    from easy_configer.Configer import Configer

    cfger = Configer(description="chat-bot configuration", cmd_args=True)
    # we have defined a config file, let's try to load it!
    cfger.cfg_from_ini("./test_cfg.ini")
    
    # Display the Namespace, it will display all flatten arguemnts and first-level sections
    print(cfger)
    
    ... # for building chat-bot instance `Chat_server`
    chat_serv = Chat_server(host=cfger.serv_host, port=cfger.serv_port, api_keys=cfger.api_keys)

    ... # build mongo-db instance `mongo_serv` for logging chat history..
    # un-roll section arguments as unzip python dict for kwargs ~
    mongo_serv.init_setup( **cfger.db_setup )

    ... # loading llm model instance `Llama` ~
    llm_mod = Llama(
        ld_8bit=cfger.bknd_srv.load_8bit, 
        chat_mode=cfger.chat_mode, 
        model_type=cfger.model_type
    )

    # you can access nested-dict by dot access ~
    llm_mod.init_mod_param( **cfger.bknd_srv.mod_params )

    # or you can keep the dict fashion ~
    if cfger.bknd_srv['async_req']:
        chat_serv.chat_mod = llm_mod
        chat_serv.hist_db = mongo_serv
    else:
        ... # write sync conversation by yourself..

    sys.exit( chat_serv.server_forever() )
```

<br>

---

### More detail tutorial about each topic is as follows :

#### **2. How to declare hierachical config**
There have two kind of way to prepare the arguments in easy-configer as we described. In practices, we consider the flatten arguments as global setup, and grouping the rest of arguments into the corresponding section for assigning it according to the subroutine.  

Let's give a deep-learning example, suppose you have created a *hier_cfg.ini in work directory*
```ini
root_dir = '/workspace'
glb_seed = 42
exp_id = '0001'

# we call '...' in [...] as section name,
# i.e. we can assign dict dataset to subroutine by `build_dataset(**cfg.dataset)`, just such easy!!
[dataset]   
    service_port = 65536
    path = "${cfg.root_dir}/data/kitti"
    # of course, nested dict is also supported! it just the native python dictionary in dictionary!
    [dataset.loader]
        batch_size = 32

[model]
    [model.backbone]
        mod_typ = 'resnet'
        [model.backbone.optimizer]
            lay_seed = 42  

[train_cfg]
    batch_size = 32
    [train_cfg.opt]
        opt_typ = 'Adam'
        lr = 1e-4
        sched = 'cos_anneal'
```

We have defined the config file, **now let's see how to access any argument!** Execute `python quick_hier.py` in work directory.

```python
from easy_configer.Configer import Configer

if __name__ == "__main__":
    cfger = Configer(cmd_args=True)
    
    # omit cfg_from_str, hier-config also could be declared in str though ~
    cfger.cfg_from_ini("./hier_cfg.ini")
    
    print(cfger.dataset)  
    # output nested dict : { 'service_port':65536, 'path':'/data/kitti', 'loader':{'batch_size':32} }
    
    print(f"key-string access bz : {cfger.dataset['loader']['batch_size']}")
    # output - "key-string access bz : 32"

    print(f"bz : {cfger.dataset.loader.batch_size}")
    # output - "dot-access bz : 32"

    # we usually conduct initialization such simple & elegant!
    ds = build_dataset(**cfger.dataset)
    mod = build_model(**cfger.model)
    ... # get torch Trainer
    Trainer(mod).fit(ds)
```

However, the syntax in config could be improved, isn't it !? For example, *the batch_size is defined twice under `dataset.loader` and `train_cfg`, so as layer seed.* Moreover, *path is defined as python string, it need to be further converted by Path object* in python standard package. Could we regist our customized data type for easy-config ?
#### Glade to say : Yes! it's possible to elegantly deal with above mentioned issue. We can solve the first issue by using argument interpolation, and solve the second issue by using the customized register!!

#### Thanks to *python format-string ${...}* and  *customized register method `regist_cnvtor`*. **See below example**
> Currently we support interpolation mechanism to interpolate *ANY* arguemnts even beloning to nested section by simply using **\${cfg}** notation. Moreover, we also support **\${env}** for accessing enviroment variables exported in bash!!

```python
# For convience, we define string-config!
def get_str_cfg():
    ''' # `export glb_seed=42` in bash!!
        glb_seed = ${env.glb_seed}@int   # or ${env.glb_seed} for short
        exp_id = '0001'

        [dataset]   
            service_port = 65536

            # Don't forgot to regist Path object first and the typename will be the given name!!
            path = ['/data/kitti']@pyPath
            
            [dataset.loader]
                batch_size = 32
                secrete_seed = 55688

        [model]
            [model.backbone]
                mod_typ = 'resnet'
                [model.backbone.optimizer]
                    # aweason! but we can do more crazy stuff ~
                    lay_seed = ${cfg.glb_seed}
                    # 'cfg' is used to access the config, feel free to access any arguments defined previsouly!!
                    string_seed = "The secrete string in data loader is ${cfg.dataset.loader.secrete_seed}!!"
        
        [train_cfg]
            batch_size = ${cfg.dataset.loader.batch_size}
            exp_id = "${cfg.exp_id}"  # or ${cfg.exp_id}@str, quote can not be omitted!
            [train_cfg.opt]
                opt_typ = 'Adam'
                lr = 1e-4
                sched = 'cos_anneal'
    '''

# main_block 
if __name__ == "__main__":
    from pathlib import Path

    cfger = Configer(description="sample for arguments interpolation")
    cfger.regist_cnvtor("pyPath", Path)  # regist customer class 'Path'

    cfg_str = get_str_cfg()
    cfger.cfg_from_str(cfg_str)
    # do whatever you want to do!
```

---

#### **3. Access all arguments flexibly**
For `easy_configer>=v2.4.0`, each argument declared under section will be stored in a special dictionary object, called `AttributeDict` (Inhert from native python `dict`). It's a new container allowing dot-operator for accessing any nested object.
The only pitfall about AttributeDict is that **you should never access its `__dict__` property**, since it's disabled..
We simple set a breakpoint to feel how flexible does `easy_configer.utils.Container.AttributeDict` support.

```python
from easy_configer.Configer import Configer

if __name__ == "__main__":
    cfger = Configer()
    cfger.cfg_from_ini("./hier_cfg.ini")
    breakpoint()
```
> We write a special example `hier_cfg.ini`!!
```ini
# nested-dict
[secA] # test depth ((sub^4)-section under secA)
    lev = 1
    [secA.secB]
        lev = 2
        [secA.secB.secC]
            lev = 3
            [secA.secB.secC.secD]
                lev = 4
```
Now you can access each `lev` :
1. `(pdb) cfger.secA.lev `, output `lev : 1`
2. `(pdb) cfger['secA'].secB['lev'] `, output `lev : 2`, and so on..
3. Most crazy one ~ `(pdb) cfger.secA.['secB'].secC['secD'].lev `, output `lev : 4`

---

#### **4. Commmend-line Support**
> We also take `hier_cfg.ini` as example!
```ini
# hier_cfg.ini
glb_var = 42@int
[dataset]         
    ds_type = None
    path = ['/data/kitti']@pyPath
    [dataset.loader]
        batch_size = 32@int
```

Execute python program and print out the helper information <br>
`python quick_hier.py -h`

Update flatten argument and print out the helper information <br>
`python quick_hier.py glb_var=404 -h`

Especially update **non-flatten argument**, you can access any argument at any level by dot-access in commend-line!! (with combining any argument update). Now, try to change any nested argument <br>
`python quick_hier.py dataset.ds_type="'kitti'" dataset.path=['/root/ds'] dataset.loader.batch_size=48`

( Note that the commendline declaration for string is tricky, but currently we only support two way for that : 
    `dataset.ds_type="'kitti'"` or `dataset.ds_type=kitti@str`, pick up one of you like ~ )

---

#### **5. Import Sub-Config**
Like `omegaconf`, most of user expect to seperate the config based on their category and dynamically merge it in runtime. It's a rational requirement and the previous version of easy-config provide two way to conduct it, but both have it's limit : 
1. you can call the `cfg_from_ini` twice, for example, `cfg.cfg_from_ini('./base_cfg') ; cfg.cfg_from_ini('./override_cfg', allow_overwrite=True)`. But it's not explicitly load the config thus reducing readability.
2. you can use the config merging, for example, `new_cfg = base_cfg | override_cfg`. But it's not elegant solution while you have to merge several config..

#### Now, we provide the thrid way : **sub-config**. you can import the sub-config in any depth of hierachical config by simply placing the `>` symbol at the beginning of line. Also note that sub-config doesn't allow you overwrite the declared argument by default, since dynamically overwrite the arguments made your config hard to trace..

```ini
# ./base_cfg.ini
glb_seed = 42@int
[dataset]         
    > ./config/ds_config.ini

[model]
    > ./root/config/model_config.ini

# ./config/ds_config.ini
ds_type = None
path = ['/data/kitti']@pyPath
[dataset.loader]
    batch_size = 32@int

# ./root/config/model_config.ini
[model.backbone]
    mod_typ = 'resnet'
    [model.backbone.optimizer]
    # and yes, interpolation is still valid "after" the reference argument is declared!
        lay_seed = ${cfg.glb_seed}
```

#### Also note that we still recommend you create several config instance and merge it in 2. way, if you want to merge it with overwriting manner. Instead of acting like omegaconf, it dynamically overwrite your config silently..
> If you **still** want to overwrite the config (act like omegaconf), turn the flag allow_overwrite as True. i.e. `cfg.cfg_from_ini(..., allow_overwrite=True)`, `cfg.cfg_from_str(..., allow_overwrite=True)`. The sub-config will follow the flag setting to overwrite the config. Be careful of the order, the **imported sub-configs** are considered as **'default setup'**, the main config (which import sub-configs) setup will overwrite its.  

```ini
# ./base_cfg.ini

# note that the order between defined arguments and imported sub-config do affect the final value of arguments!
glb_seed = 42

# import several default setup :
> ./config/ds_config.ini
> ./config/model_config.ini

[dataset]       
    n_worker = 8

[model]
    n_blk = 2

# ./config/ds_config.ini
[dataset]
    n_worker = 1
    path = ['/data/kitti']@pyPath
    [dataset.loader]
        batch_size = 32@int

# ./root/config/model_config.ini
[model]
    mod_typ = 'resnet'
    n_blk = 1
    [model.optimizer]
    # and yes, interpolation is still valid "after" the reference argument is declared!
        lay_seed = ${cfg.glb_seed}
```

#### After dynamic loading :
```ini
glb_seed = 42

[dataset]       
    n_worker = 8  # overwrited by base_cfg.ini
    path = ['/data/kitti']@pyPath
    [dataset.loader]
        batch_size = 32@int

[model]
    n_blk = 2 # overwrited by base_cfg.ini
    mod_typ = 'resnet'
    [model.optimizer]
        lay_seed = 42
```

---

#### **6. Config Operation**
Config operation is one of the core technique for dynamic configuration system!!
In the following example, you can see that the merging config system already provided a impressive hierachical merging funtionality! 
> For example, `ghyu.opop.add` in cfg_a can be replaced by the cfg_b in **same** section with the same variable name, while the different namespace keep their variable safely ~ so the value of `ghyu.opop.add` will be 67 and `ghyu.opop.tueo.inpo` refer the flatten variable `inpo` and the value will be 46.

```python
from easy_configer.Configer import Configer

def build_cfg_text_a():
    return '''
    # Initial config file :
    inpo = 46@int
    [test]         
        mrg_var_tst = [1, 3, 5]@list
        [test.ggap]
            gtgt = haha@str

    [ghyu]
        [ghyu.opop]
            add = 32@int
            [ghyu.opop.tueo]
                salt = ${cfg.inpo}

    # Cell cfg written by Josef-Huang..
    '''

def build_cfg_text_b():
    return '''
    # Initial config file :
    inop = 32@int
    [test]         
        mrg_var_tst = [1, 3, 5]@list
        [test.ggap]
            gtgt = overrides@str
            [test.ggap.conf]
                secert = 42@int

    [ghyu]
        [ghyu.opop]
            add = 67@int
            div = 1e-4@float

    [new]
        [new.new]
            newsec = wpeo@str
    # Cell cfg written by Josef-Huang..
    '''

if __name__ == "__main__":
    cfg_a = Configer(cmd_args=True)
    cfg_a.cfg_from_str(build_cfg_text_a())  
    

    cfg_b = Configer()
    cfg_b.cfg_from_str(build_cfg_text_b())
    
    # default, overwrite flag is turn off ~
    cfg_a.merge_conf(cfg_b, overwrite=True)

    # `cfg_b = cfg_b | cfg_a`, operator support, warn to decrease the read-ability...
    # cfg_a will overwrite the argument of cfg_b which share the identitical variable name in cfg_b!
    # operator support : `cfg_b |= cfg_a` == `cfg_b = cfg_b | cfg_a`
```

---

### **Miscellnous features**
#### **7. IO Converter**
To convert the `easy_configer` type config into the other config instance, we provide a IO converter to serve for this requirement. IO converter support several well-know config type.. Just simple call the method with the proper arguments as the following example. 

```python
from dataclasses import dataclass
from typing import Optional

@dataclass
class TableConfig:
    rows: int = 1

@dataclass
class DatabaseConfig:
    table_cfg: TableConfig = TableConfig()

@dataclass
class ModelConfig:
    data_source: Optional[TableConfig] = None

@dataclass
class ServerConfig:
    db: DatabaseConfig = DatabaseConfig()
    model: ModelConfig = ModelConfig()

if __name__ == '__main__':
    from easy_configer.IO_Converter import IO_Converter

    # first import the IO_converter
    from easy_config.IO_Converter import IO_Converter
    cnvt = IO_Converter()

    # convert easy_config instance into the argparse instance
    argp_cfg = cnvt.cnvt_cfg_to(cfger, 'argparse')

    uargp_cfg = cnvt.cnvt_cfg_to(cfger, 'argparse', parse_arg=False)
    argp_cfg = uargp_cfg.parse_args()

    ## convert config INTO..
    # convert easy_config instance into the omegaconf instance
    ome_cfg = cnvt.cnvt_cfg_to(cfger, 'omegaconf')

    # convert easy_config instance into the "yaml string"
    yaml_cfg = cnvt.cnvt_cfg_to(cfger, 'yaml')

    # convert easy_config instance into the "dict"
    yaml_cfg = cnvt.cnvt_cfg_to(cfger, 'dict')

    ## convert into easy-config FROM..
    # argparse, omegaconf, yaml, dict ... is supported
    ez_cfg = cnvt.cnvt_cfg_from(argp_cfg, 'omegaconf')

    # Especially, it support "dataclass"!
    ds_cfg = ServerConfig()
    ez_cfg = cnvt.cnvt_cfg_from(ds_cfg, 'dataclass')
```

---

#### **8. Absl style flag**
easy_config also support that you can access the 'same' config file in different python file without re-declare the config. test_flag.py under the same work directory

Suppose you have executed `main.py`:
```python
from easy_configer.Configer import Configer
from utils import get_var_from_flag

if __name__ == "__main__":
    cfg = Configer()
    cfg.cfg_from_str("var = 32")

    # both should output 32 ~
    print(f"var from main : {cfg.var}")
    print(f"var from flag : { get_var_from_flag() }")
```

Now, when you step in `get_var_from_flag` function in different file..
```python
from easy_configer.Configer import Configer

def get_var_from_flag():
    new_cfger = Configer()
    flag = new_cfger.get_cfg_flag()
    # test to get the pre-defined 'var'
    return flag.var
```
---

### Simple Unittest ๐Ÿงช
If you clone this repo and built from source, you can check the unittest.
`python -m unittest discover`
> I have placed all test file under test folder.

---

### License
MIT License. More information of each term, please see LICENSE.md

### Author 
Josef-Huang, a3285556aa@gmail.com 

### Footer
~ Hope God bless everyone in the world to know his word ~ <br>
**The fear of the LORD is the beginning of knowledge; fools despise wisdom and instruction. by Proverbs 1:7**

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/HuangChiEn/easy_config",
    "name": "easy-configer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "configuration, commendline argument, argument",
    "author": "JosefHuang",
    "author_email": "a3285556aa@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/3e/d2/d25a4d4e3362d0dc54c9613b3e91d6b22cb03accbfc6ec73facc080a932b/easy_configer-2.5.7.tar.gz",
    "platform": null,
    "description": "# Project description\n#### easy_configer version : 2.5.6\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/HuangChiEn/easy_config/main.yaml)\n[![PyPI version](https://badge.fury.io/py/easy-configer.svg?icon=si%3Apython)](https://badge.fury.io/py/easy-configer)\n[![Documentation](https://img.shields.io/badge/documentation-link-blue.svg)](https://easy-configer.readthedocs.io/)\n\n![easy-configer logo](https://raw.githubusercontent.com/HuangChiEn/easy_config/master/assets/logo.png)\n\n---\n\n#### pypi v2.5.7 just update README.md..\n\n### \ud83d\udea7 TODO list :\n0. Release known issue area in v2.5.6 and hot-fix in v2.6.\n1. Tag v2.6 as stable version.\n2. Next version v3.0 is under development, stateless interface will be introduced as one of new features\n3. Nested argument intepolation may be one of features in v3.0\n4. You can preview the v3.0 prototype of codebase under ./dev folder \n\n---\n\n### \ud83d\udc1e Known issues : \n1. allow_overwrite flag also allow you overwrite the entire section by a config value, most of case it should not a expected behavior (pitfall)\n2. Commendline argument CAN NOT update the arguments in sub_config (bug)\n\n---\n\n### Configeruating the program in an easy-way \nI'm willing to provide a light-weight solution for configurating your python program. Hope this repository make every user control their large project more easier ~ ~ \n\n### Easy-configer document\n**Check the documentation released in ReadTheDoc[\ud83d\udd17](https://easy-configer.readthedocs.io/en/latest/), to learn more!**\n\nEasy-config cover the following features :\n1. **Hierachical section config (nested dict-like config)**\n\n2. **Accept multiple config file in dynamic loading manner (similar with omegaconf)**\n\n3. **Support customized class (initialized by list or keyword arguments)**\n\n4. **Commend-line add/update declared arguments/sections (even in hierachical section)**\n\n5. **Support the absl style FLAGS functionality (declare once, use anywhere)** \n\nAnd, of course the following attributes are supported :\n\n* dot-access of any config argument (even in nested dictionary)\n\n* inline comment '#', now you can write comment in everyline ~\n\n* support config argument interpolation (even in nested dictionary)!\n\n* support config conversion, feel free to use easy_config or the other config tools (omegaconf, argparse, ..., etc.)\n\n* support omegaconf-like dynamic config loading system ~\n\n---\n\n### Newly update features \ud83d\ude80\n0. v2.5.4 is basically fine, but it still have several known issues, so we plane to release v2.6 as stable version.\n1. Apply \\${cfg}, ${env} as argument and enviroment intepolation notation, respectively.\n2. Apply AttributeDict container (it inherit pure python dict) to store non-flatten arguments!\n\n---\n\n### Bug Fixed \ud83d\udc1b\n#### Hot-fix Container bug in v2.5.3, now it'll raise AttributeError while attribute doesn't exists..(fixed in v2.5.4)\n\n---\n\n### Dependencies \ud83c\udfd7\ufe0f\nThis package is written for Python 3.8. After refactor in this version, this package also support down to python 3.6!!\nOf course, light-weight solution **do not** contain any 3-rd package complex dependencies.\nThe python standard package (such as pathlib, sys, .., etc) is the only source of dependencies, so you don't need to worry about that ~ ~\n> However, if you want to use the IO_Converter for converting config into omegaconf, you still need to install omegaconf for this functionality ~\n\n---\n\n### Installation \u2699\ufe0f<br>\n1. **pypi install** <br>\n    simply type the `pip install easy_configer` (due to name conflict of pypi pkg, we use different pkg name)\n\n2. **install from source code** <br>\n    clone the project from github : `git clone https://github.com/HuangChiEn/easy_config.git` \n    Chage to the root directory of the cloned project, and type `pip install -e .`\n\n3. **import syntax** <br>\n    Wherever you install, pypi or source. Now, you just need a simple import : `from easy_configer.Configer import Configer`\n    \n---\n\n### Quick start \ud83e\udd42\n\n#### **1. Handy example of config file**\nLet's say we have an easy-config for development enviroment on jupyter notebook. we want to define several variable for configurating a simple math calculation.\n\n```python\n# config string\ncfg_str = '''\ntitle = 'math calculation'@str\ncoef = 1e-3@float\nwith_intercept = True@bool\nintercept = 3@int\n'''\n\n# look's good, let's get the config!\nfrom easy_configer.Configer import Configer\n# `cmd_args=False` disable any commendline args \ncfg = Configer(description=\"math calculation config!\", cmd_args=False)\ncfg.cfg_from_str(cfg_str)\n\n# oh.. wait, could we do it more easier ?\nez_cfg_str = '''\n# opps.. let's change some value\ntitle = 'linear equation'\ncoef = 15        \n'''\n# By default, we don't encourage you to overwrite the predefined arguments,  \n#        if you want to overwrite it in 'convenient way', you should set `allow_overwrite=True`..\ncfg.cfg_from_str(ez_cfg_str, allow_overwrite=True)\n\nlin_equ = lambda x : cfg.coef * x + cfg.intercept if cfg.with_intercept else (cfg.coef * x)\nx = 15\nprint( f\"Linear equation with x={x} : { lin_equ(x) }\" )\n```\n> If you want to overwrite previous config, *apply twice* `cfg.cfg_from_str` with `allow_overwrite=True` flag IS NOT a recommended way. In easy-configer, we provide 2 way to do that. The standard way is *declaring 2 config and apply config merging method* to get the updated config. The other way is similar with omegaconf to import sub-config in dynamic manner,  however you still need to set flag `allow_overwrite=True` in `cfg.cfg_from_ini`.\n\nAlthough writing a string config in python is convenient, it only suitable for the project in smaller scale. In large project, we may write a config file to control the program, so that we will be easy to trace, check and debug the config. We are going to prepare a sample config called `test_cfg.ini` in the working directory and describe how we work with chatbot roughly. \n\n#### In easy-configer, there're two type of argument in config : flatten argument, hierachical argument. You will see that the flatten arguments are directly placed in config and doesn't belong any section (namely in first level). In contrast, the hierachical arguments will be placed in section (i.e. `[db_setup]`) with any kind of depth, the arguments under the section will be wrapped by a container (`easy_configer.utils.Container.AttributeDict`) similar with pure python `dict`. \n\n#### To form a hierachical argument in nested section, we apply toml-like syntax to describe the nested section (i.e. `[bknd_srv.mod_params]` is belong to `[bknd_srv]` parent section). The arguments in nested section are also wrapped by nested AttributeDict. Besides you can access all kind of arguments by the simple dot-operator, however, we still recommend you to use key-string as pure python dict.\n> Note that the recommended way to access the argument is **still** key-string access `cfger.args['#4$%-var']`, as you may notice, dot-access doesn't support **ugly** variable name (`cfger.#4$%-var`, as variable name is invalid in python intepreter). \n    \n```ini\n# ./test_cfg.ini\n# '#' denote comment line, the inline comment is also supported!\n\n# define 'flatten' arguments :\nserv_host = '127.0.0.1'  \nserv_port = 9478@int    # specific type is also allowed!!\napi_keys = {'TW_REGION':'SV92VS92N20', 'US_REGION':'W92N8WN029N2'}\n\n# define 'hierachical' arguments :\n# the 'section' is the key of accessing AttributeDict's value and could be defined as follows :\n[db_setup]\n    db_host = ${cfg.serv_host}:80@str\n    # first `export mongo_port=5566` in your bash, then support os.env interpolation!\n    db_port = ${env.mongo_port}  \n    snap_shot = True\n\n# and then define second section for backend server..\n[bknd_srv]\n    load_8bit = True\n    async_req = True\n    chat_mode = 'inference'\n    model_type = 'LlaMa2.0'\n    [bknd_srv.mod_params]\n        log_hist = False\n        tempeture = 1e-4\n        model_mode = ${cfg.bknd_srv.chat_mode}  # hierachical args interpolation\n```\n\n<br>\n\nNow, we're free to launch the chatbot via `python quick_start.py` (*quick_start.py in work directory*)!\nHowever, you can also overwrite the arguemnts via commendline `python quick_start.py serv_port=7894 bknd_srv.chat_mode=predict@str`\n> Note that **update argument** from commendline is naturally permitted, but overwrite **the section** IS NOT! If you also want to overwrite the section, you need to set flag `allow_overwrite=True`. \n\n```python\nimport sys\n\n# main_block \nif __name__ == \"__main__\":\n    from easy_configer.Configer import Configer\n\n    cfger = Configer(description=\"chat-bot configuration\", cmd_args=True)\n    # we have defined a config file, let's try to load it!\n    cfger.cfg_from_ini(\"./test_cfg.ini\")\n    \n    # Display the Namespace, it will display all flatten arguemnts and first-level sections\n    print(cfger)\n    \n    ... # for building chat-bot instance `Chat_server`\n    chat_serv = Chat_server(host=cfger.serv_host, port=cfger.serv_port, api_keys=cfger.api_keys)\n\n    ... # build mongo-db instance `mongo_serv` for logging chat history..\n    # un-roll section arguments as unzip python dict for kwargs ~\n    mongo_serv.init_setup( **cfger.db_setup )\n\n    ... # loading llm model instance `Llama` ~\n    llm_mod = Llama(\n        ld_8bit=cfger.bknd_srv.load_8bit, \n        chat_mode=cfger.chat_mode, \n        model_type=cfger.model_type\n    )\n\n    # you can access nested-dict by dot access ~\n    llm_mod.init_mod_param( **cfger.bknd_srv.mod_params )\n\n    # or you can keep the dict fashion ~\n    if cfger.bknd_srv['async_req']:\n        chat_serv.chat_mod = llm_mod\n        chat_serv.hist_db = mongo_serv\n    else:\n        ... # write sync conversation by yourself..\n\n    sys.exit( chat_serv.server_forever() )\n```\n\n<br>\n\n---\n\n### More detail tutorial about each topic is as follows :\n\n#### **2. How to declare hierachical config**\nThere have two kind of way to prepare the arguments in easy-configer as we described. In practices, we consider the flatten arguments as global setup, and grouping the rest of arguments into the corresponding section for assigning it according to the subroutine.  \n\nLet's give a deep-learning example, suppose you have created a *hier_cfg.ini in work directory*\n```ini\nroot_dir = '/workspace'\nglb_seed = 42\nexp_id = '0001'\n\n# we call '...' in [...] as section name,\n# i.e. we can assign dict dataset to subroutine by `build_dataset(**cfg.dataset)`, just such easy!!\n[dataset]   \n    service_port = 65536\n    path = \"${cfg.root_dir}/data/kitti\"\n    # of course, nested dict is also supported! it just the native python dictionary in dictionary!\n    [dataset.loader]\n        batch_size = 32\n\n[model]\n    [model.backbone]\n        mod_typ = 'resnet'\n        [model.backbone.optimizer]\n            lay_seed = 42  \n\n[train_cfg]\n    batch_size = 32\n    [train_cfg.opt]\n        opt_typ = 'Adam'\n        lr = 1e-4\n        sched = 'cos_anneal'\n```\n\nWe have defined the config file, **now let's see how to access any argument!** Execute `python quick_hier.py` in work directory.\n\n```python\nfrom easy_configer.Configer import Configer\n\nif __name__ == \"__main__\":\n    cfger = Configer(cmd_args=True)\n    \n    # omit cfg_from_str, hier-config also could be declared in str though ~\n    cfger.cfg_from_ini(\"./hier_cfg.ini\")\n    \n    print(cfger.dataset)  \n    # output nested dict : { 'service_port':65536, 'path':'/data/kitti', 'loader':{'batch_size':32} }\n    \n    print(f\"key-string access bz : {cfger.dataset['loader']['batch_size']}\")\n    # output - \"key-string access bz : 32\"\n\n    print(f\"bz : {cfger.dataset.loader.batch_size}\")\n    # output - \"dot-access bz : 32\"\n\n    # we usually conduct initialization such simple & elegant!\n    ds = build_dataset(**cfger.dataset)\n    mod = build_model(**cfger.model)\n    ... # get torch Trainer\n    Trainer(mod).fit(ds)\n```\n\nHowever, the syntax in config could be improved, isn't it !? For example, *the batch_size is defined twice under `dataset.loader` and `train_cfg`, so as layer seed.* Moreover, *path is defined as python string, it need to be further converted by Path object* in python standard package. Could we regist our customized data type for easy-config ?\n#### Glade to say : Yes! it's possible to elegantly deal with above mentioned issue. We can solve the first issue by using argument interpolation, and solve the second issue by using the customized register!!\n\n#### Thanks to *python format-string ${...}* and  *customized register method `regist_cnvtor`*. **See below example**\n> Currently we support interpolation mechanism to interpolate *ANY* arguemnts even beloning to nested section by simply using **\\${cfg}** notation. Moreover, we also support **\\${env}** for accessing enviroment variables exported in bash!!\n\n```python\n# For convience, we define string-config!\ndef get_str_cfg():\n    ''' # `export glb_seed=42` in bash!!\n        glb_seed = ${env.glb_seed}@int   # or ${env.glb_seed} for short\n        exp_id = '0001'\n\n        [dataset]   \n            service_port = 65536\n\n            # Don't forgot to regist Path object first and the typename will be the given name!!\n            path = ['/data/kitti']@pyPath\n            \n            [dataset.loader]\n                batch_size = 32\n                secrete_seed = 55688\n\n        [model]\n            [model.backbone]\n                mod_typ = 'resnet'\n                [model.backbone.optimizer]\n                    # aweason! but we can do more crazy stuff ~\n                    lay_seed = ${cfg.glb_seed}\n                    # 'cfg' is used to access the config, feel free to access any arguments defined previsouly!!\n                    string_seed = \"The secrete string in data loader is ${cfg.dataset.loader.secrete_seed}!!\"\n        \n        [train_cfg]\n            batch_size = ${cfg.dataset.loader.batch_size}\n            exp_id = \"${cfg.exp_id}\"  # or ${cfg.exp_id}@str, quote can not be omitted!\n            [train_cfg.opt]\n                opt_typ = 'Adam'\n                lr = 1e-4\n                sched = 'cos_anneal'\n    '''\n\n# main_block \nif __name__ == \"__main__\":\n    from pathlib import Path\n\n    cfger = Configer(description=\"sample for arguments interpolation\")\n    cfger.regist_cnvtor(\"pyPath\", Path)  # regist customer class 'Path'\n\n    cfg_str = get_str_cfg()\n    cfger.cfg_from_str(cfg_str)\n    # do whatever you want to do!\n```\n\n---\n\n#### **3. Access all arguments flexibly**\nFor `easy_configer>=v2.4.0`, each argument declared under section will be stored in a special dictionary object, called `AttributeDict` (Inhert from native python `dict`). It's a new container allowing dot-operator for accessing any nested object.\nThe only pitfall about AttributeDict is that **you should never access its `__dict__` property**, since it's disabled..\nWe simple set a breakpoint to feel how flexible does `easy_configer.utils.Container.AttributeDict` support.\n\n```python\nfrom easy_configer.Configer import Configer\n\nif __name__ == \"__main__\":\n    cfger = Configer()\n    cfger.cfg_from_ini(\"./hier_cfg.ini\")\n    breakpoint()\n```\n> We write a special example `hier_cfg.ini`!!\n```ini\n# nested-dict\n[secA] # test depth ((sub^4)-section under secA)\n    lev = 1\n    [secA.secB]\n        lev = 2\n        [secA.secB.secC]\n            lev = 3\n            [secA.secB.secC.secD]\n                lev = 4\n```\nNow you can access each `lev` :\n1. `(pdb) cfger.secA.lev `, output `lev : 1`\n2. `(pdb) cfger['secA'].secB['lev'] `, output `lev : 2`, and so on..\n3. Most crazy one ~ `(pdb) cfger.secA.['secB'].secC['secD'].lev `, output `lev : 4`\n\n---\n\n#### **4. Commmend-line Support**\n> We also take `hier_cfg.ini` as example!\n```ini\n# hier_cfg.ini\nglb_var = 42@int\n[dataset]         \n    ds_type = None\n    path = ['/data/kitti']@pyPath\n    [dataset.loader]\n        batch_size = 32@int\n```\n\nExecute python program and print out the helper information <br>\n`python quick_hier.py -h`\n\nUpdate flatten argument and print out the helper information <br>\n`python quick_hier.py glb_var=404 -h`\n\nEspecially update **non-flatten argument**, you can access any argument at any level by dot-access in commend-line!! (with combining any argument update). Now, try to change any nested argument <br>\n`python quick_hier.py dataset.ds_type=\"'kitti'\" dataset.path=['/root/ds'] dataset.loader.batch_size=48`\n\n( Note that the commendline declaration for string is tricky, but currently we only support two way for that : \n    `dataset.ds_type=\"'kitti'\"` or `dataset.ds_type=kitti@str`, pick up one of you like ~ )\n\n---\n\n#### **5. Import Sub-Config**\nLike `omegaconf`, most of user expect to seperate the config based on their category and dynamically merge it in runtime. It's a rational requirement and the previous version of easy-config provide two way to conduct it, but both have it's limit : \n1. you can call the `cfg_from_ini` twice, for example, `cfg.cfg_from_ini('./base_cfg') ; cfg.cfg_from_ini('./override_cfg', allow_overwrite=True)`. But it's not explicitly load the config thus reducing readability.\n2. you can use the config merging, for example, `new_cfg = base_cfg | override_cfg`. But it's not elegant solution while you have to merge several config..\n\n#### Now, we provide the thrid way : **sub-config**. you can import the sub-config in any depth of hierachical config by simply placing the `>` symbol at the beginning of line. Also note that sub-config doesn't allow you overwrite the declared argument by default, since dynamically overwrite the arguments made your config hard to trace..\n\n```ini\n# ./base_cfg.ini\nglb_seed = 42@int\n[dataset]         \n    > ./config/ds_config.ini\n\n[model]\n    > ./root/config/model_config.ini\n\n# ./config/ds_config.ini\nds_type = None\npath = ['/data/kitti']@pyPath\n[dataset.loader]\n    batch_size = 32@int\n\n# ./root/config/model_config.ini\n[model.backbone]\n    mod_typ = 'resnet'\n    [model.backbone.optimizer]\n    # and yes, interpolation is still valid \"after\" the reference argument is declared!\n        lay_seed = ${cfg.glb_seed}\n```\n\n#### Also note that we still recommend you create several config instance and merge it in 2. way, if you want to merge it with overwriting manner. Instead of acting like omegaconf, it dynamically overwrite your config silently..\n> If you **still** want to overwrite the config (act like omegaconf), turn the flag allow_overwrite as True. i.e. `cfg.cfg_from_ini(..., allow_overwrite=True)`, `cfg.cfg_from_str(..., allow_overwrite=True)`. The sub-config will follow the flag setting to overwrite the config. Be careful of the order, the **imported sub-configs** are considered as **'default setup'**, the main config (which import sub-configs) setup will overwrite its.  \n\n```ini\n# ./base_cfg.ini\n\n# note that the order between defined arguments and imported sub-config do affect the final value of arguments!\nglb_seed = 42\n\n# import several default setup :\n> ./config/ds_config.ini\n> ./config/model_config.ini\n\n[dataset]       \n    n_worker = 8\n\n[model]\n    n_blk = 2\n\n# ./config/ds_config.ini\n[dataset]\n    n_worker = 1\n    path = ['/data/kitti']@pyPath\n    [dataset.loader]\n        batch_size = 32@int\n\n# ./root/config/model_config.ini\n[model]\n    mod_typ = 'resnet'\n    n_blk = 1\n    [model.optimizer]\n    # and yes, interpolation is still valid \"after\" the reference argument is declared!\n        lay_seed = ${cfg.glb_seed}\n```\n\n#### After dynamic loading :\n```ini\nglb_seed = 42\n\n[dataset]       \n    n_worker = 8  # overwrited by base_cfg.ini\n    path = ['/data/kitti']@pyPath\n    [dataset.loader]\n        batch_size = 32@int\n\n[model]\n    n_blk = 2 # overwrited by base_cfg.ini\n    mod_typ = 'resnet'\n    [model.optimizer]\n        lay_seed = 42\n```\n\n---\n\n#### **6. Config Operation**\nConfig operation is one of the core technique for dynamic configuration system!!\nIn the following example, you can see that the merging config system already provided a impressive hierachical merging funtionality! \n> For example, `ghyu.opop.add` in cfg_a can be replaced by the cfg_b in **same** section with the same variable name, while the different namespace keep their variable safely ~ so the value of `ghyu.opop.add` will be 67 and `ghyu.opop.tueo.inpo` refer the flatten variable `inpo` and the value will be 46.\n\n```python\nfrom easy_configer.Configer import Configer\n\ndef build_cfg_text_a():\n    return '''\n    # Initial config file :\n    inpo = 46@int\n    [test]         \n        mrg_var_tst = [1, 3, 5]@list\n        [test.ggap]\n            gtgt = haha@str\n\n    [ghyu]\n        [ghyu.opop]\n            add = 32@int\n            [ghyu.opop.tueo]\n                salt = ${cfg.inpo}\n\n    # Cell cfg written by Josef-Huang..\n    '''\n\ndef build_cfg_text_b():\n    return '''\n    # Initial config file :\n    inop = 32@int\n    [test]         \n        mrg_var_tst = [1, 3, 5]@list\n        [test.ggap]\n            gtgt = overrides@str\n            [test.ggap.conf]\n                secert = 42@int\n\n    [ghyu]\n        [ghyu.opop]\n            add = 67@int\n            div = 1e-4@float\n\n    [new]\n        [new.new]\n            newsec = wpeo@str\n    # Cell cfg written by Josef-Huang..\n    '''\n\nif __name__ == \"__main__\":\n    cfg_a = Configer(cmd_args=True)\n    cfg_a.cfg_from_str(build_cfg_text_a())  \n    \n\n    cfg_b = Configer()\n    cfg_b.cfg_from_str(build_cfg_text_b())\n    \n    # default, overwrite flag is turn off ~\n    cfg_a.merge_conf(cfg_b, overwrite=True)\n\n    # `cfg_b = cfg_b | cfg_a`, operator support, warn to decrease the read-ability...\n    # cfg_a will overwrite the argument of cfg_b which share the identitical variable name in cfg_b!\n    # operator support : `cfg_b |= cfg_a` == `cfg_b = cfg_b | cfg_a`\n```\n\n---\n\n### **Miscellnous features**\n#### **7. IO Converter**\nTo convert the `easy_configer` type config into the other config instance, we provide a IO converter to serve for this requirement. IO converter support several well-know config type.. Just simple call the method with the proper arguments as the following example. \n\n```python\nfrom dataclasses import dataclass\nfrom typing import Optional\n\n@dataclass\nclass TableConfig:\n    rows: int = 1\n\n@dataclass\nclass DatabaseConfig:\n    table_cfg: TableConfig = TableConfig()\n\n@dataclass\nclass ModelConfig:\n    data_source: Optional[TableConfig] = None\n\n@dataclass\nclass ServerConfig:\n    db: DatabaseConfig = DatabaseConfig()\n    model: ModelConfig = ModelConfig()\n\nif __name__ == '__main__':\n    from easy_configer.IO_Converter import IO_Converter\n\n    # first import the IO_converter\n    from easy_config.IO_Converter import IO_Converter\n    cnvt = IO_Converter()\n\n    # convert easy_config instance into the argparse instance\n    argp_cfg = cnvt.cnvt_cfg_to(cfger, 'argparse')\n\n    uargp_cfg = cnvt.cnvt_cfg_to(cfger, 'argparse', parse_arg=False)\n    argp_cfg = uargp_cfg.parse_args()\n\n    ## convert config INTO..\n    # convert easy_config instance into the omegaconf instance\n    ome_cfg = cnvt.cnvt_cfg_to(cfger, 'omegaconf')\n\n    # convert easy_config instance into the \"yaml string\"\n    yaml_cfg = cnvt.cnvt_cfg_to(cfger, 'yaml')\n\n    # convert easy_config instance into the \"dict\"\n    yaml_cfg = cnvt.cnvt_cfg_to(cfger, 'dict')\n\n    ## convert into easy-config FROM..\n    # argparse, omegaconf, yaml, dict ... is supported\n    ez_cfg = cnvt.cnvt_cfg_from(argp_cfg, 'omegaconf')\n\n    # Especially, it support \"dataclass\"!\n    ds_cfg = ServerConfig()\n    ez_cfg = cnvt.cnvt_cfg_from(ds_cfg, 'dataclass')\n```\n\n---\n\n#### **8. Absl style flag**\neasy_config also support that you can access the 'same' config file in different python file without re-declare the config. test_flag.py under the same work directory\n\nSuppose you have executed `main.py`:\n```python\nfrom easy_configer.Configer import Configer\nfrom utils import get_var_from_flag\n\nif __name__ == \"__main__\":\n    cfg = Configer()\n    cfg.cfg_from_str(\"var = 32\")\n\n    # both should output 32 ~\n    print(f\"var from main : {cfg.var}\")\n    print(f\"var from flag : { get_var_from_flag() }\")\n```\n\nNow, when you step in `get_var_from_flag` function in different file..\n```python\nfrom easy_configer.Configer import Configer\n\ndef get_var_from_flag():\n    new_cfger = Configer()\n    flag = new_cfger.get_cfg_flag()\n    # test to get the pre-defined 'var'\n    return flag.var\n```\n---\n\n### Simple Unittest \ud83e\uddea\nIf you clone this repo and built from source, you can check the unittest.\n`python -m unittest discover`\n> I have placed all test file under test folder.\n\n---\n\n### License\nMIT License. More information of each term, please see LICENSE.md\n\n### Author \nJosef-Huang, a3285556aa@gmail.com \n\n### Footer\n~ Hope God bless everyone in the world to know his word ~ <br>\n**The fear of the LORD is the beginning of knowledge; fools despise wisdom and instruction. by Proverbs 1:7**\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An easy way for configurating python program by the given config file or config str",
    "version": "2.5.7",
    "project_urls": {
        "Homepage": "https://github.com/HuangChiEn/easy_config"
    },
    "split_keywords": [
        "configuration",
        " commendline argument",
        " argument"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "369dbc20f67ef1b07ec42f282b00a32790384ed4b028a724ea459af7191cef57",
                "md5": "3b0ce05f1c1eb5b582e5c4af176407f2",
                "sha256": "528b17270f8af15f982071505e7cc3f158a5e6d3b1ebadaacb87bdd2ac5b71a0"
            },
            "downloads": -1,
            "filename": "easy_configer-2.5.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3b0ce05f1c1eb5b582e5c4af176407f2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 23751,
            "upload_time": "2025-01-28T05:49:03",
            "upload_time_iso_8601": "2025-01-28T05:49:03.080737Z",
            "url": "https://files.pythonhosted.org/packages/36/9d/bc20f67ef1b07ec42f282b00a32790384ed4b028a724ea459af7191cef57/easy_configer-2.5.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3ed2d25a4d4e3362d0dc54c9613b3e91d6b22cb03accbfc6ec73facc080a932b",
                "md5": "40c3367545df3ba4941370c034c29864",
                "sha256": "102329931f1890459e12a931331637e0c778812d54b509b9eff00629067c4384"
            },
            "downloads": -1,
            "filename": "easy_configer-2.5.7.tar.gz",
            "has_sig": false,
            "md5_digest": "40c3367545df3ba4941370c034c29864",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 30501,
            "upload_time": "2025-01-28T05:49:05",
            "upload_time_iso_8601": "2025-01-28T05:49:05.534736Z",
            "url": "https://files.pythonhosted.org/packages/3e/d2/d25a4d4e3362d0dc54c9613b3e91d6b22cb03accbfc6ec73facc080a932b/easy_configer-2.5.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-28 05:49:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "HuangChiEn",
    "github_project": "easy_config",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "easy-configer"
}
        
Elapsed time: 0.70124s