Package: el-config
Easily Launch Config (el_config)Python-box based custom config package for python projects.FeaturesLoad environment variables -https://pypi.org/project/python-dotenvPython-box based config -https://pypi.org/project/python-boxCerberus schema validation -https://pypi.org/project/CerberusCustom base config moduleYAML or JSON based configsUpdate with extra configsPre-load configValidate configFreeze configConfig as dictioaryInstallation1. PrerequisitesPython (>= v3.7)PyPi (>= v21)2. Install el-configA. [RECOMMENDED] PyPi install# Install or upgrade el-config package:pipinstall--upgradeel-config# To uninstall package:pipuninstall-yel-configB. Manually add to PYTHONPATH (Recommended for development)# Clone repository by git:gitclonegit@bitbucket.org:ellexiinc/el_config.gitcdel_config# Install python dependencies:pipinstall--upgradepip
catrequirements.txt|xargs-n1-L1pipinstall--no-cache-dir# Add current path to PYTHONPATH:exportPYTHONPATH="${PWD}:${PYTHONPATH}"C. Manually compile and setup (Not recommended)# Clone repository by git:gitclonegit@bitbucket.org:ellexiinc/el_config.gitcdel_config# Building python package:pipinstall--upgradepipsetuptoolswheel
pythonsetup.pybuild# Install python dependencies with built package to current python environment:pythonsetup.pyinstall--recordinstalled_files.txt# To remove only installed el-config package:head-n1installed_files.txt|xargsrm-vrf# Or to remove all installed files and packages:catinstalled_files.txt|xargsrm-vrfUsage/ExamplesSample python file -https://bitbucket.org/ellexiinc/el_config/src/master/sample.pyconfigs/app.yml:env: development

app:
    name: "My App"
    host: 0.0.0.0
    port: 80
    secret: "my-secret"
    debug: false.env:ENV=productionAPP_PORT=8080APP_SECRET="My_s3crEt_k3y"utils/validator_schemas.py:config_schema={'env':{'type':'string','allowed':['development','production'],'default':'development'},'app':{'type':'dict','schema':{'name':{'type':'string','minlength':2,'maxlength':255},'host':{'type':'string','minlength':2,'maxlength':255},'port':{'type':'integer','coerce':int,'min':1024,'max':65535},'secret':{'type':'string','minlength':12,'maxlength':255},'debug':{'type':'boolean'}}}}config.py:importosfromutils.validator_schemasimportconfig_schemafromel_configimportConfigBasedef_pre_load(config):try:config.env=os.getenv('ENV',config.env).strip().lower()ifconfig.env=='production':config.app.debug=Falseifos.getenv('APP_SECRET')isNone:raiseKeyError("Missing required `APP_SECRET` environment variable on 'production'!")config.app.port=os.getenv('APP_PORT',config.app.port)config.app.debug=os.getenv('APP_DEBUG',config.app.debug)config.app.secret=os.getenv('APP_SECRET',config.app.secret)exceptExceptionaserr:print(f"ERROR: Error occured while pre-loading config:\n{err}")exit(2)returnconfig_cb=ConfigBase(pre_load=_pre_load,valid_schema=config_schema)_cb.load()config=_cb.configprint(config)main.py:fromflaskimportFlaskfromconfigimportconfigapp=Flask(__name__)@app.route("/")defhello_world():return"<p>Hello, World!</p>"if__name__=='__main__':app.run(host=config.app.host,port=config.app.port)Running TestsTo run tests, run the following command:pytestReferenceshttps://saurabh-kumar.com/python-dotenvhttps://github.com/theskumar/python-dotenvhttps://github.com/cdgriffith/Box/wikihttps://github.com/cdgriffith/Boxhttps://docs.python-cerberus.org/en/stablehttps://github.com/pyeve/cerberus