{"id":21494095,"url":"https://github.com/grburgess/configya","last_synced_at":"2025-07-15T19:31:15.265Z","repository":{"id":41091941,"uuid":"252127734","full_name":"grburgess/configya","owner":"grburgess","description":"A yaml configuration file generator. ","archived":false,"fork":false,"pushed_at":"2022-06-29T12:45:02.000Z","size":285,"stargazers_count":2,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-02T23:34:28.285Z","etag":null,"topics":["config","configuration","yaml","yaml-configuration"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grburgess.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}},"created_at":"2020-04-01T09:18:39.000Z","updated_at":"2024-04-30T08:32:30.000Z","dependencies_parsed_at":"2022-07-30T21:07:59.113Z","dependency_job_id":null,"html_url":"https://github.com/grburgess/configya","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/grburgess/configya","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grburgess%2Fconfigya","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grburgess%2Fconfigya/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grburgess%2Fconfigya/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grburgess%2Fconfigya/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grburgess","download_url":"https://codeload.github.com/grburgess/configya/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grburgess%2Fconfigya/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264192131,"owners_count":23570715,"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":["config","configuration","yaml","yaml-configuration"],"created_at":"2024-11-23T15:49:01.106Z","updated_at":"2025-07-15T19:31:14.986Z","avatar_url":"https://github.com/grburgess.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Travis CI w/ Logo](https://img.shields.io/travis/grburgess/configya/master.svg?logo=travis)](https://travis-ci.org/grburgess/configya)\r\n[![codecov](https://codecov.io/gh/grburgess/configya/branch/master/graph/badge.svg)](https://codecov.io/gh/grburgess/configya)\r\n![PyPI](https://img.shields.io/pypi/v/configya?style=plastic)\r\n## status\r\n![GitHub last commit (branch)](https://img.shields.io/github/last-commit/grburgess/configya/master?style=for-the-badge)\r\n![GitHub issues](https://img.shields.io/github/issues/grburgess/configya?style=for-the-badge)\r\n![GitHub pull requests](https://img.shields.io/github/issues-pr/grburgess/configya?style=for-the-badge)\r\n![GitHub contributors](https://img.shields.io/github/contributors/grburgess/configya?style=for-the-badge)\r\n\r\n\r\n# configya\r\n\r\n![alt text](https://raw.githubusercontent.com/grburgess/configya/master/logo.png)\r\n\r\n```bash\r\npip install configya\r\n```\r\n\r\n## What is this?\r\n\r\nI often make YAML configuration files for codes to input default parameters. I kept repeating myself and wanting more robustness to the structure required in the file... so I decided to make a generic one. \r\n\r\n## What it does?\r\n\r\n* Inherit the **YAMLConfig** class and pass to the super  class a dict with the structure of your config and default values as well as the location and name of the config file.\r\n* Upon creating a config object, it will check if there is an existing config, and if not create a default one\r\n* If there is an existing config, it makes sure the structure and value types conform to default file structure and types\r\n* If it finds errors, it yells at you, backs yours up and tries to correct the corrupted one. \r\n* Only simple values like strings and numbers are checked... but maybe more in the future\r\n\r\n## What next?\r\n\r\nfork it and add more... I'm sure this could be better\r\n\r\n### Check it out\r\n\r\n\r\n```python\r\nfrom configya import YAMLConfig\r\n```\r\n\r\nCreate a dictionary with the (nested) structure you desire and give it some default values\r\n\r\n\r\n```python\r\nmy_structure = {}\r\nmy_structure['n_workers'] = 4\r\nmy_structure['server'] = dict(name='supercomputer', address='10.10.1.1')\r\nmy_structure['my_iq'] = 80\r\nmy_structure['hours_spent_this'] = 'too many'\r\n\r\n\r\n```\r\n\r\nCreate your class somewhere in your package\r\n\r\n\r\n```python\r\nclass MyConfig(YAMLConfig):  \r\n    def __init__(self):\r\n\r\n        super(MyConfig, self).__init__(my_structure,\r\n                                       '~/.my_cool_program',\r\n                                       'config.yml')\r\n    \r\n```\r\n\r\nThe first time you make it, the default config will be written. It will yell at you.\r\n\r\n\r\n```python\r\nconfig = MyConfig()\r\n\r\n```\r\n\r\n    /Users/jburgess/.environs/yaml_config/lib/python3.7/site-packages/configya-0.3.0-py3.7.egg/configya/yaml_config.py:84: NoConfigurationWarning: No configuration file found! Making one in /Users/jburgess/.my_cool_program/config.yml\r\n\r\n\r\n\r\n```python\r\n!ls /Users/jburgess/.my_cool_program/\r\n```\r\n\r\n    config.yml\r\n\r\n\r\n\r\nYes, it is there.\r\n\r\n\r\n```python\r\nconfig\r\n```\r\n\r\n    /Users/jburgess/.my_cool_program/config.yml\r\n\r\n\r\n\r\n\r\n\r\n    hours_spent_this: too many\r\n    my_iq: 80\r\n    n_workers: 4\r\n    server:\r\n      address: 10.10.1.1\r\n      name: supercomputer\r\n\r\n\r\n\r\n\r\n```python\r\nconfig['server']['name']\r\n```\r\n\r\n\r\n\r\n\r\n    'supercomputer'\r\n\r\n\r\n\r\n\r\n```python\r\nconfig['my_iq']\r\n```\r\n\r\n\r\n\r\n\r\n    80\r\n\r\n\r\n\r\nWell...\r\n\r\nWe can modify with class access\r\n```python\r\nconfig.my_iq = 200\r\nconfig['my_iq']\r\n```\r\n\r\n\r\n\r\n\r\n    200\r\n\r\n\r\n\r\n### Safety first\r\nIt will not allow you to clobber nested dicts\r\n\r\n\r\n```python\r\nconfig['server'] = 5\r\n```\r\n\r\n\r\n    ---------------------------------------------------------------------------\r\n\r\n    AssertionError                            Traceback (most recent call last)\r\n\r\n    \u003cipython-input-10-3d0b32c9a17b\u003e in \u003cmodule\u003e\r\n    ----\u003e 1 config['server'] = 5\r\n    \r\n\r\n    ~/.environs/yaml_config/lib/python3.7/site-packages/configya-0.3.0-py3.7.egg/configya/yaml_config.py in __setitem__(self, key, item)\r\n        294         if key in self._configuration:\r\n        295 \r\n    --\u003e 296             assert not isinstance(self._configuration[key], dict), f\"Woah, you are going to overwrite the structure\"\r\n        297 \r\n        298             self._configuration[key] = item\r\n\r\n\r\n    AssertionError: Woah, you are going to overwrite the structure\r\n\r\n\r\nCannot add things that are not there\r\n\r\n\r\n```python\r\nconfig['ooops'] = 10\r\n```\r\n\r\nOr find them\r\n\r\n\r\n```python\r\nconfig['what?'] \r\n```\r\n\r\nWhat if I manually change the config in my github repo, and the one on my local computer is not up to date?\r\n\r\n\r\n```python\r\nmy_structure = {}\r\nmy_structure['n_workers'] = 4\r\nmy_structure['server'] = dict(name='supercomputer', address='10.10.1.1')\r\nmy_structure['my_iq'] = 80\r\nmy_structure['hours_spent_this'] = 'too many'\r\n# Added a new number!\r\nmy_structure['total_number_of_postdocs'] = 1e5\r\n\r\n\r\n```\r\n\r\n\r\n```python\r\nclass MyConfig(YAMLConfig):  \r\n    def __init__(self):\r\n\r\n        super(MyConfig, self).__init__(my_structure,\r\n                                       '~/.my_cool_program',\r\n                                       'config.yml')\r\n    \r\n```\r\n\r\n\r\n```python\r\nconfig = MyConfig()\r\n```\r\n\r\n    /Users/jburgess/.environs/yaml_config/lib/python3.7/site-packages/configya-0.3.0-py3.7.egg/configya/yaml_config.py:109: BadStructureWarning: The user config file /Users/jburgess/.my_cool_program/config.yml was corrupt\r\n      BadStructureWarning,\r\n    /Users/jburgess/.environs/yaml_config/lib/python3.7/site-packages/configya-0.3.0-py3.7.egg/configya/yaml_config.py:113: BadStructureWarning: and has been backed up to /Users/jburgess/.my_cool_program/config.yml.bak and replaced\r\n      BadStructureWarning,\r\n    /Users/jburgess/.environs/yaml_config/lib/python3.7/site-packages/configya-0.3.0-py3.7.egg/configya/yaml_config.py:117: BadStructureWarning: with the default config. The CURRENT config is now default\r\n      BadStructureWarning,\r\n\r\n\r\n\r\n```python\r\nconfig\r\n```\r\n\r\n    /Users/jburgess/.my_cool_program/config.yml\r\n\r\n\r\n\r\n\r\n\r\n    hours_spent_this: too many\r\n    my_iq: 80\r\n    n_workers: 4\r\n    server:\r\n      address: 10.10.1.1\r\n      name: supercomputer\r\n    total_number_of_postdocs: 100000.0\r\n\r\n\r\n\r\n\r\n```python\r\n!ls /Users/jburgess/.my_cool_program/\r\n```\r\n\r\n    config.yml     config.yml.bak\r\n\r\n\r\n\r\nAlso, if you manually edit the config in an editor, it will check if the types are correct. If not, it will replace that value with the default value and backup your config\r\n\r\n\r\n```python\r\n\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrburgess%2Fconfigya","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrburgess%2Fconfigya","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrburgess%2Fconfigya/lists"}