yaml-configuration


Nameyaml-configuration JSON
Version 0.2.6 PyPI version JSON
download
home_pagehttps://github.com/DLR-RM/python-yaml-configuration
SummaryA python module to easily read from and write to yaml config files.
upload_time2024-01-19 09:20:13
maintainerSebastian Brunner
docs_urlNone
authorSebastian Brunner
requires_python>=2.6
licenseBSD
keywords yaml configuration
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
yaml\_configuration
===================

This module offers easy configuration for a other modules or startup
scripts. It offers an easy way to load and save config files and read
and write config values to it. Also trying to read a config value by
passing an optional default value if the real config value is not
present is supported.

Usage
=====

The class DefaultConfig provides the basic functionality of the package.
A custom configuration class is meant to derive from it.

.. code:: python

    import os
    import logging
    from pytest import raises
    from yaml_configuration.config import DefaultConfig, ConfigError


    def read_file(file_path, filename):
        file_path = os.path.join(file_path, filename)
        with open(file_path, 'r') as file_pointer:
            file_content = file_pointer.read()
        return file_content


    class BasicConfig(DefaultConfig):

        def __init__(self, config_string, config_file, logger_object=None):
            super(BasicConfig, self).__init__(config_string, logger_object)
            # this is already done in the init
            # self.load(config_file, path=os.path.dirname(__file__))


    if __name__ == '__main__':
        config_file = "basic_config.yaml"
        config_string = read_file(os.path.dirname(__file__), config_file)
        basic_config = BasicConfig(config_string, config_file, logging.getLogger("TestLogger"))
        basic_config.set_config_value("number_value", 10)
        basic_config.set_config_value("string_value", "test_string")
        assert basic_config.get_config_value("string_value") == "test_string"
        assert basic_config.get_config_value("not_existing_config_value", default=42) == 42
        with raises(ConfigError):
            if not basic_config.get_config_value("value_that_should_exist"):
                raise ConfigError("The config value with key 'value_that_should_exist' should exist")

..




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/DLR-RM/python-yaml-configuration",
    "name": "yaml-configuration",
    "maintainer": "Sebastian Brunner",
    "docs_url": null,
    "requires_python": ">=2.6",
    "maintainer_email": "sebastian.brunner@dlr.de",
    "keywords": "yaml,configuration",
    "author": "Sebastian Brunner",
    "author_email": "sebastian.brunner@dlr.de",
    "download_url": "https://files.pythonhosted.org/packages/26/c7/da74d944be5a3f371a7c4df165912b46e524316b490b136d7420792a86bd/yaml_configuration-0.2.6.tar.gz",
    "platform": null,
    "description": "\nyaml\\_configuration\n===================\n\nThis module offers easy configuration for a other modules or startup\nscripts. It offers an easy way to load and save config files and read\nand write config values to it. Also trying to read a config value by\npassing an optional default value if the real config value is not\npresent is supported.\n\nUsage\n=====\n\nThe class DefaultConfig provides the basic functionality of the package.\nA custom configuration class is meant to derive from it.\n\n.. code:: python\n\n    import os\n    import logging\n    from pytest import raises\n    from yaml_configuration.config import DefaultConfig, ConfigError\n\n\n    def read_file(file_path, filename):\n        file_path = os.path.join(file_path, filename)\n        with open(file_path, 'r') as file_pointer:\n            file_content = file_pointer.read()\n        return file_content\n\n\n    class BasicConfig(DefaultConfig):\n\n        def __init__(self, config_string, config_file, logger_object=None):\n            super(BasicConfig, self).__init__(config_string, logger_object)\n            # this is already done in the init\n            # self.load(config_file, path=os.path.dirname(__file__))\n\n\n    if __name__ == '__main__':\n        config_file = \"basic_config.yaml\"\n        config_string = read_file(os.path.dirname(__file__), config_file)\n        basic_config = BasicConfig(config_string, config_file, logging.getLogger(\"TestLogger\"))\n        basic_config.set_config_value(\"number_value\", 10)\n        basic_config.set_config_value(\"string_value\", \"test_string\")\n        assert basic_config.get_config_value(\"string_value\") == \"test_string\"\n        assert basic_config.get_config_value(\"not_existing_config_value\", default=42) == 42\n        with raises(ConfigError):\n            if not basic_config.get_config_value(\"value_that_should_exist\"):\n                raise ConfigError(\"The config value with key 'value_that_should_exist' should exist\")\n\n..\n\n\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "A python module to easily read from and write to yaml config files.",
    "version": "0.2.6",
    "project_urls": {
        "Homepage": "https://github.com/DLR-RM/python-yaml-configuration"
    },
    "split_keywords": [
        "yaml",
        "configuration"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f13e734517a07ede92acafb0d19a547b572489ef72fa7c6b89350f690a6576a1",
                "md5": "8b7da8391a416c4d7fb5566b66950773",
                "sha256": "cc8bc7df52dda33b8773f438ec92e519038a332750db4353dcd530daf11566dd"
            },
            "downloads": -1,
            "filename": "yaml_configuration-0.2.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8b7da8391a416c4d7fb5566b66950773",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=2.6",
            "size": 6993,
            "upload_time": "2024-01-19T09:20:11",
            "upload_time_iso_8601": "2024-01-19T09:20:11.581492Z",
            "url": "https://files.pythonhosted.org/packages/f1/3e/734517a07ede92acafb0d19a547b572489ef72fa7c6b89350f690a6576a1/yaml_configuration-0.2.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "26c7da74d944be5a3f371a7c4df165912b46e524316b490b136d7420792a86bd",
                "md5": "1f93d720e40972aeda1fc34c0b342528",
                "sha256": "95b40efb608457ae447902c7353a4555cccbdb634c9c03ab56a8cc80fb858526"
            },
            "downloads": -1,
            "filename": "yaml_configuration-0.2.6.tar.gz",
            "has_sig": false,
            "md5_digest": "1f93d720e40972aeda1fc34c0b342528",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.6",
            "size": 6679,
            "upload_time": "2024-01-19T09:20:13",
            "upload_time_iso_8601": "2024-01-19T09:20:13.232827Z",
            "url": "https://files.pythonhosted.org/packages/26/c7/da74d944be5a3f371a7c4df165912b46e524316b490b136d7420792a86bd/yaml_configuration-0.2.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-19 09:20:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "DLR-RM",
    "github_project": "python-yaml-configuration",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "yaml-configuration"
}
        
Elapsed time: 0.15980s