Easily Launch Config (el_config)
Python-box based custom config package for python projects.
Features
- Load environment variables - https://pypi.org/project/python-dotenv
- Python-box based config - https://pypi.org/project/python-box
- Cerberus schema validation - https://pypi.org/project/Cerberus
- Custom base config module
- YAML or JSON based configs
- Update with extra configs
- Pre-load config
- Validate config
- Freeze config
- Config as dictioary
Installation
1. Prerequisites
- Python (>= v3.7)
- PyPi (>= v21)
2. Install el-config
A. [RECOMMENDED] PyPi install
# Install or upgrade el-config package:
pip install --upgrade el-config
# To uninstall package:
pip uninstall -y el-config
B. Manually add to PYTHONPATH (Recommended for development)
# Clone repository by git:
git clone git@bitbucket.org:ellexiinc/el_config.git
cd el_config
# Install python dependencies:
pip install --upgrade pip
cat requirements.txt | xargs -n 1 -L 1 pip install --no-cache-dir
# Add current path to PYTHONPATH:
export PYTHONPATH="${PWD}:${PYTHONPATH}"
C. Manually compile and setup (Not recommended)
# Clone repository by git:
git clone git@bitbucket.org:ellexiinc/el_config.git
cd el_config
# Building python package:
pip install --upgrade pip setuptools wheel
python setup.py build
# Install python dependencies with built package to current python environment:
python setup.py install --record installed_files.txt
# To remove only installed el-config package:
head -n 1 installed_files.txt | xargs rm -vrf
# Or to remove all installed files and packages:
cat installed_files.txt | xargs rm -vrf
Usage/Examples
- Sample python file - https://bitbucket.org/ellexiinc/el_config/src/master/sample.py
configs/app.yml:
env: development
app:
name: "My App"
host: 0.0.0.0
port: 80
secret: "my-secret"
debug: false
.env:
ENV=production
APP_PORT=8080
APP_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:
import os
from utils.validator_schemas import config_schema
from el_config import ConfigBase
def _pre_load(config):
try:
config.env = os.getenv('ENV', config.env).strip().lower()
if config.env == 'production':
config.app.debug = False
if os.getenv('APP_SECRET') is None:
raise KeyError("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)
except Exception as err:
print(f"ERROR: Error occured while pre-loading config:\n {err}")
exit(2)
return config
_cb = ConfigBase(pre_load=_pre_load, valid_schema=config_schema)
_cb.load()
config = _cb.config
print(config)
main.py:
from flask import Flask
from config import config
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
if __name__ == '__main__':
app.run(host=config.app.host, port=config.app.port)
Running Tests
To run tests, run the following command:
pytest
References
Metadata
Release files for el-config 0.1.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| el_config-0.1.18.tar.gz | 5.9 kB | Without provenance | Details for el_config-0.1.18.tar.gz |
Release files / el_config-0.1.18.tar.gz
| Download URL | el_config-0.1.18.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0dc193b69f15d7824a49434341771620850bd121467faeee5d8af14e5d52f735
|
|
BLAKE2b-256 checksum How to use checksums |
6b6a6ade9021ed737edc648ee3362a5d8132ba702e724fb5f774d204dba3bf9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9
|
Security for el-config 0.1.18
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.