cfg_load
Loading configuration files is a common task in many projects. This package does the job.
Installation
The recommended way to install cfg_load is:
$ pip install cfg_load[all] --user
Note: You might have to escape [ and ] in some shells like ZSH.
If you want the latest version:
$ git clone https://github.com/MartinThoma/cfg_load.git; cd cfg_load
$ pip instell -e .[all] --user
Usage
cfg_load is intended to be used as a library. In your code, it will mostly
be used like this:
import cfg_load
config = cfg_load.load("some/path.yaml")
In order to check if it is doing what you expect, you can use it as a command line tool:
$ cfg_load tests/examples/cifar10_baseline.yaml
{ 'dataset': { 'script_path': '/home/moose/GitHub/cfg_loader/datasets/cifar10_keras.py'},
'evaluate': { 'augmentation_factor': 32,
'batch_size': 1000,
'data_augmentation': { 'channel_shift_range': 0,
'featurewise_center': False,
'height_shift_range': 0.15,
'horizontal_flip': True,
'rotation_range': 0,
'samplewise_center': False,
'samplewise_std_normalization': False,
'shear_range': 0,
'vertical_flip': False,
'width_shift_range': 0.15,
'zca_whitening': False,
'zoom_range': 0}},
'model': { 'script_path': '/home/moose/GitHub/cfg_loader/models/baseline.py'},
'optimizer': { 'initial_lr': 0.0001,
'script_path': '/home/moose/GitHub/cfg_loader/optimizers/adam_keras.py'},
'train': { 'artifacts_path': '/home/moose/GitHub/cfg_loader/artifacts/cifar10_baseline',
'batch_size': 64,
'data_augmentation': { 'channel_shift_range': 0,
'featurewise_center': False,
'height_shift_range': 0.1,
'horizontal_flip': True,
'rotation_range': 0,
'samplewise_center': False,
'samplewise_std_normalization': False,
'shear_range': 0,
'vertical_flip': False,
'width_shift_range': 0.1,
'zca_whitening': False,
'zoom_range': 0},
'epochs': 1000,
'script_path': '/home/moose/GitHub/cfg_loader/train/train_keras.py'}}
You can see that it automatically detected that the file is a YAML file and
when you compare it to cfg_load examples/cifar10_baseline.yaml --raw you can
also see that it made the paths absolute.
Good Application Practice
import cfg_load
# Load defaults
base_cfg = cfg_load.load("some/path.yaml")
# Overwrite defaults if user defined it
user_cfg = cfg_load.load("other/path.yaml")
user_cfg = base_cfg.update(user_cfg)
# Overwrite user default with environment variables
env_mapping = cfg_load.load("other/env_mapping.yaml")
cfg = user_cfg.apply_env(env_mapping)
Features
- You load your config like this:
cfg = cfg_load.load('examples/test.json') - No key that starts with
_will ever be touched. - Keys ending in
_pathwill be made absolute. - Don't worry about Unicode.
- Every key
[something]_module_pathtriggerscfg_loadto load the file found at[something]_module_pathas a Python module tocfg.modules['something']. - If an environment variable with the same name as a config key exists, the
take the value of the environment variable. Please note: If the type of
the overwritten key is not str, then
cfg_loadappliesjson.loadsto the environment variable. - Every key ending with
_load_urlhas to havesource_urlandsink_path. Files fromsource_urlwill be loaded automatically and stored in thesink_path. Apolicyparameter can specify if it should beload_alwaysorload_if_missing.
Not there, but planned fo the future:
- Every key
[something]_cfg_pathwill triggercfg_loadto search for another config file and append it at[something]. By this way you can define configuration files recursively.
Development
Check tests with tox.
Metadata
Release files for cfg-load 0.9.0
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 |
|---|---|---|---|---|
| cfg_load-0.9.0.tar.gz | 10.7 kB | Without provenance | Details for cfg_load-0.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cfg_load-0.9.0-py3-none-any.whl | Python 3 | none | any | Details for cfg_load-0.9.0-py3-none-any.whl |
Total release size: 21.3 kB
Release files / cfg_load-0.9.0.tar.gz
| Download URL | cfg_load-0.9.0.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dddd3c68db8a2eeefcfefd8d3554684bdfa8af5f5e62bf1a731da0d2c85d4585
|
|
BLAKE2b-256 checksum How to use checksums |
331919e813c5347b7f7e86e9f1ce58df18bfa839d6c7fde300a0980ff4926d91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10
|
Release files / cfg_load-0.9.0-py3-none-any.whl
| Download URL | cfg_load-0.9.0-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
989a6478d569c311da66188b1bb70c23b61b91d7bbe6a2b9be11684a7b78a1e0
|
|
BLAKE2b-256 checksum How to use checksums |
a8948e71b5ad8af827f42d89cdc30a2cd3934eef7368005d2a5d5f4eee4efb37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10
|
Security for cfg-load 0.9.0
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.