{"id":13738326,"url":"https://github.com/MartinThoma/cfg_load","last_synced_at":"2025-05-08T16:33:15.772Z","repository":{"id":37677870,"uuid":"122778656","full_name":"MartinThoma/cfg_load","owner":"MartinThoma","description":"Load config files the right way","archived":false,"fork":false,"pushed_at":"2023-03-15T21:01:17.000Z","size":143,"stargazers_count":41,"open_issues_count":20,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-08T00:26:39.418Z","etag":null,"topics":["configuration-files","mit-license","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MartinThoma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-02-24T20:50:32.000Z","updated_at":"2024-10-16T16:59:16.000Z","dependencies_parsed_at":"2024-01-08T17:20:17.490Z","dependency_job_id":"72242e87-02c5-467b-8fb8-b9e2c4eca801","html_url":"https://github.com/MartinThoma/cfg_load","commit_stats":{"total_commits":62,"total_committers":4,"mean_commits":15.5,"dds":0.06451612903225812,"last_synced_commit":"8bddfd80f7382a7d440eaaf3fdf383ae8e9f4d94"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinThoma%2Fcfg_load","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinThoma%2Fcfg_load/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinThoma%2Fcfg_load/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinThoma%2Fcfg_load/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MartinThoma","download_url":"https://codeload.github.com/MartinThoma/cfg_load/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224746562,"owners_count":17363073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration-files","mit-license","python3"],"created_at":"2024-08-03T03:02:18.694Z","updated_at":"2024-11-15T07:30:46.114Z","avatar_url":"https://github.com/MartinThoma.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"[![PyPI version](https://badge.fury.io/py/cfg-load.svg)](https://badge.fury.io/py/cfg-load)\n[![Python Support](https://img.shields.io/pypi/pyversions/cfg_load.svg)](https://pypi.org/project/cfg_load/)\n[![Documentation Status](https://readthedocs.org/projects/cfg_load/badge/?version=latest)](http://cfg-load.readthedocs.io/en/latest/)\n[![Build Status](https://travis-ci.org/MartinThoma/cfg_load.svg?branch=master)](https://travis-ci.org/MartinThoma/cfg_load)\n[![Coverage Status](https://coveralls.io/repos/github/MartinThoma/cfg_load/badge.svg?branch=master)](https://coveralls.io/github/MartinThoma/cfg_load?branch=master)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n# cfg_load\n\nLoading configuration files is a common task in many projects. This package\ndoes the job.\n\n\n## Installation\n\nThe recommended way to install cfg_load is:\n\n```bash\n$ pip install cfg_load[all] --user\n```\n\nNote: You might have to escape `[` and `]` in some shells like ZSH.\n\nIf you want the latest version:\n\n```bash\n$ git clone https://github.com/MartinThoma/cfg_load.git; cd cfg_load\n$ pip install -e .[all] --user\n```\n\n\n## Usage\n\n`cfg_load` is intended to be used as a library. In your code, it will mostly\nbe used like this:\n\n```python\nimport cfg_load\n\nconfig = cfg_load.load(\"some/path.yaml\")\n```\n\nIn order to check if it is doing what you expect, you can use it as a command\nline tool:\n\n```bash\n$ cfg_load tests/examples/cifar10_baseline.yaml\n\n{   'dataset': {   'script_path': '/home/moose/GitHub/cfg_loader/datasets/cifar10_keras.py'},\n    'evaluate': {   'augmentation_factor': 32,\n                    'batch_size': 1000,\n                    'data_augmentation': {   'channel_shift_range': 0,\n                                             'featurewise_center': False,\n                                             'height_shift_range': 0.15,\n                                             'horizontal_flip': True,\n                                             'rotation_range': 0,\n                                             'samplewise_center': False,\n                                             'samplewise_std_normalization': False,\n                                             'shear_range': 0,\n                                             'vertical_flip': False,\n                                             'width_shift_range': 0.15,\n                                             'zca_whitening': False,\n                                             'zoom_range': 0}},\n    'model': {   'script_path': '/home/moose/GitHub/cfg_loader/models/baseline.py'},\n    'optimizer': {   'initial_lr': 0.0001,\n                     'script_path': '/home/moose/GitHub/cfg_loader/optimizers/adam_keras.py'},\n    'train': {   'artifacts_path': '/home/moose/GitHub/cfg_loader/artifacts/cifar10_baseline',\n                 'batch_size': 64,\n                 'data_augmentation': {   'channel_shift_range': 0,\n                                          'featurewise_center': False,\n                                          'height_shift_range': 0.1,\n                                          'horizontal_flip': True,\n                                          'rotation_range': 0,\n                                          'samplewise_center': False,\n                                          'samplewise_std_normalization': False,\n                                          'shear_range': 0,\n                                          'vertical_flip': False,\n                                          'width_shift_range': 0.1,\n                                          'zca_whitening': False,\n                                          'zoom_range': 0},\n                 'epochs': 1000,\n                 'script_path': '/home/moose/GitHub/cfg_loader/train/train_keras.py'}}\n```\n\nYou can see that it automatically detected that the file is a YAML file and\nwhen you compare it to `cfg_load examples/cifar10_baseline.yaml --raw` you can\nalso see that it made the paths absolute.\n\n\n## Good Application Practice\n\n```python\nimport cfg_load\n\n# Load defaults\nbase_cfg = cfg_load.load(\"some/path.yaml\")\n\n# Overwrite defaults if user defined it\nuser_cfg = cfg_load.load(\"other/path.yaml\")\nuser_cfg = base_cfg.update(user_cfg)\n\n# Overwrite user default with environment variables\nenv_mapping = cfg_load.load(\"other/env_mapping.yaml\")\ncfg = user_cfg.apply_env(env_mapping)\n```\n\n\n## Features\n\n* You load your config like this: `cfg = cfg_load.load('examples/test.json')`\n* No key that starts with `_` will ever be touched.\n* Keys ending in `_path` will be made absolute.\n* Don't worry about Unicode.\n* Every key `[something]_module_path` triggers `cfg_load` to load the\n  file found at `[something]_module_path` as a Python module to\n  `cfg.modules['something']`.\n* If an environment variable with the same name as a config key exists, the\n  take the value of the environment variable. *Please note*: If the type of\n  the overwritten key is not str, then `cfg_load` applies `json.loads` to the\n  environment variable.\n* Every key ending with `_load_url` has to have `source_url` and `sink_path`.\n  Files from `source_url` will be loaded automatically and stored in the\n  `sink_path`. A `policy` parameter can specify if it should be `load_always`\n  or `load_if_missing`.\n\nNot there, but planned fo the future:\n\n* Every key `[something]_cfg_path` will trigger `cfg_load` to search for\n  another config file and append it at `[something]`. By this way you can\n  define configuration files recursively.\n\n\n## Development\n\nCheck tests with `tox`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMartinThoma%2Fcfg_load","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMartinThoma%2Fcfg_load","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMartinThoma%2Fcfg_load/lists"}