{ "info": { "author": "Tiago Requeijo", "author_email": "tiago.requeijo.dev@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# python-configuration\n> A library to load configuration parameters from multiple sources and formats\n\n[![version](https://img.shields.io/pypi/v/python-configuration)](https://pypi.org/project/python-configuration/)\n![python](https://img.shields.io/pypi/pyversions/python-configuration)\n![wheel](https://img.shields.io/pypi/wheel/python-configuration)\n![license](https://img.shields.io/pypi/l/python-configuration)\n[![build](https://img.shields.io/travis/tr11/python-configuration)](https://travis-ci.org/tr11/python-configuration)\n[![codecov](https://codecov.io/gh/tr11/python-configuration/branch/master/graph/badge.svg)](https://codecov.io/gh/tr11/python-configuration)\n[![Documentation Status](https://readthedocs.org/projects/python-configuration/badge/?version=latest)](https://python-configuration.readthedocs.io/en/latest/?badge=latest)\n\nThis library is intended as a helper mechanism to load configuration files\nhierarchically. Current format types are:\n* Python files\n* Dictionaries\n* Environment variables\n* Filesystem paths\n* JSON files\n* INI files\n\nand optionally\n* YAML files\n* TOML files\n\n## Installing\n\nTo install the library:\n```shell\npip install python-configuration\n```\n\nTo include the optional TOML and/or YAML loaders, install the optional\ndependencies `toml` and ` yaml`. For example,\n```shell\npip install python-configuration[toml, yaml]\n```\n\n## Getting started\n\nThis library converts the config types above into dictionaries with \ndotted-based keys. That is, given a config `cfg` from the structure\n```python\n{\n 'a': {\n 'b': 'value'\n }\n}\n```\nwe are able to refer to the parameter above as any of \n```python\ncfg['a.b']\ncfg['a']['b']\ncfg['a'].b\ncfg.a.b\n```\nand extract specific data types such as dictionaries:\n```python\ncfg['a'].as_dict == {'b': 'value'}\n```\nThis is particularly useful in order to isolate group parameters.\nFor example, with the JSON configuration\n```json\n{\n \"database.host\": \"something\",\n \"database.port\": 12345,\n \"database.driver\": \"name\",\n \"app.debug\": true,\n \"app.environment\": \"development\",\n \"app.secrets\": \"super secret\",\n \"logging\": {\n \"service\": \"service\",\n \"token\": \"token\",\n \"tags\": \"tags\"\n }\n}\n```\none can retrieve the dictionaries as \n```python\ncfg.database.as_dict()\ncfg.app.as_dict()\ncfg.logging.as_dict()\n```\nor simply as \n```python\ndict(cfg.database)\ndict(cfg.app)\ndict(cfg.logging)\n```\n## Configuration\nThere are two general types of objects in this library. The first one is the `Configuration`,\nwhich represents a single config source. The second is a `ConfigurationSet` that allows for\nmultiple `Configuration` objects to be specified.\n\n### Single Config\n\n#### Python Files\nTo load a configuration from a Python module, the `config_from_python` can be used.\nThe first parameter must be a Python module and can be specified as an absolute path to the Python file or as an importable module.\n\nOptional parameters are the `prefix` and `separator`. The following call \n```python\nconfig_from_python('foo.bar', prefix='CONFIG', separator='__')\n```\nwill read every variable in the `foo.bar` module that starts with `CONFIG__` and replace\nevery occurrence of `__` with a `.`. For example,\n```python\n# foo.bar\nCONFIG__AA__BB_C = 1\nCONFIG__AA__BB__D = 2\nCONF__AA__BB__D = 3\n```\nwould result in the configuration\n```python\n{\n 'aa.bb_c': 1,\n 'aa.bb.d': 2,\n}\n```\nNote that the single underscore in `BB_C` is not replaced and the last line is not\nprefixed by `CONFIG`. \n\n#### Dictionaries\nDictionaries are loaded with `config_from_dict` and are converted internally to a \nflattened `dict`. \n```python\n{\n 'a': {\n 'b': 'value'\n }\n}\n```\nbecomes\n```python\n{\n 'a.b': 'value'\n}\n```\n\n#### Environment Variables\nEnvironment variables starting with `prefix` can be read with `config_from_env`:\n```python\nconfig_from_env(prefix, separator='_')\n```\n\n#### Filesystem Paths\nFolders with files named as `xxx.yyy.zzz` can be loaded with the `config_from_path` function. This format is useful to load mounted\nKubernetes [ConfigMaps](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#populate-a-volume-with-data-stored-in-a-configmap)\nor [Secrets](https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#create-a-pod-that-has-access-to-the-secret-data-through-a-volume).\n\n#### JSON, INI, YAML, TOML\nJSON, INI, YAML, TOML files are loaded respectively with\n`config_from_json`,\n`config_from_ini`,\n`config_from_yaml`, and\n`config_from_toml`.\nThe parameter `read_from_file` controls\nwhether a string should be interpreted as a filename.\n\n###### Caveats\nIn order for `Configuration` objects to act as `dict` and allow the syntax\n`dict(cfg)`, the `keys()` method is implemented as the typical `dict` keys.\nIf `keys` is an element in the configuration `cfg` then the `dict(cfg)` call will fail.\nIn that case, it's necessary to use the `cfg.as_dict()` method to retrieve the\n`dict` representation for the `Configuration` object.\n\nThe same applies to the methods `values()` and `items()`.\n \n\n### Configuration Sets\nConfiguration sets are used to hierarchically load configurations and merge\nsettings. Sets can be loaded by constructing a `ConfigurationSet` object directly or\nusing the simplified `config` function.\n\nTo construct a `ConfigurationSet`, pass in as many of the simple `Configuration` objects as needed:\n```python\ncfg = ConfigurationSet(\n config_from_env(prefix=PREFIX),\n config_from_json(path, read_from_file=True),\n config_from_dict(DICT),\n)\n```\nThe example above will read first from Environment variables prefixed with `PREFIX`, \nand fallback first to the JSON file at `path`, and finally use the dictionary `DICT`.\n\nThe `config` function simplifies loading sets by assuming some defaults.\nThe example above can also be obtained by\n```python\ncfg = config(\n ('env', PREFIX),\n ('json', path, True),\n ('dict', DICT),\n)\n```\nor, even simpler if `path` points to a file with a `.json` suffix:\n```python\ncfg = config('env', path, DICT, prefix=PREFIX)\n```\nThe `config` function automatically detects the following:\n* extension `.py` for python modules\n* dot-separated python identifiers as a python module (e.g. `foo.bar`)\n* extension `.json` for JSON files\n* extension `.yaml` for YAML files\n* extension `.toml` for TOML files\n* extension `.ini` for INI files\n* filesystem folders as Filesystem Paths\n* the strings `env` or `environment` for Environment Variables\n\n###### Caveats\nAs long as the data types are consistent across all the configurations that are\npart of a `ConfigurationSet`, the behavior should be straightforward. When different\nconfiguration objects are specified with competing data types, the first configuration to\ndefine the elements sets its datatype. For example, if in the example above \n`element` is interpreted as a `dict` from environment variables, but the \nJSON file specifies it as anything else besides a mapping, then the JSON value will be\ndropped automatically. \n\n## Developing\n\nTo develop this library, download the source code and install a local version.\n\n\n## Features\n\n* Load multiple configuration types\n* Hierarchical configuration\n* Ability to override with environment variables\n* Merge parameters from different configuration types\n\n## Contributing\n\nIf you'd like to contribute, please fork the repository and use a feature\nbranch. Pull requests are welcome.\n\n## Links\n\n- Repository: https://github.com/tr11/python-configuration\n- Issue tracker: https://github.com/tr11/python-configuration/issues\n- Documentation: https://python-configuration.readthedocs.io\n\n## Licensing\n\nThe code in this project is licensed under MIT license.\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/tr11/python-configuration", "keywords": "configuration,settings,json,yaml,toml,ini", "license": "MIT", "maintainer": "Tiago Requeijo", "maintainer_email": "tiago.requeijo.dev@gmail.com", "name": "python-configuration", "package_url": "https://pypi.org/project/python-configuration/", "platform": "", "project_url": "https://pypi.org/project/python-configuration/", "project_urls": { "Homepage": "https://github.com/tr11/python-configuration", "Repository": "https://github.com/tr11/python-configuration" }, "release_url": "https://pypi.org/project/python-configuration/0.4.0/", "requires_dist": [ "pyyaml (>=5.1,<6.0); extra == \"yaml\"", "toml (>=0.10.0,<0.11.0); extra == \"toml\"" ], "requires_python": ">=3.6,<4.0", "summary": "A library to load configuration parameters from multiple sources and formats", "version": "0.4.0" }, "last_serial": 5962624, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "310fb165aff66ade99ddca28c2a2e955", "sha256": "27a764fbb2409a941e4a827c6c93c2e741409c1cb11e719358a26d7f12abf478" }, "downloads": -1, "filename": "python_configuration-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "310fb165aff66ade99ddca28c2a2e955", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.4,<4.0", "size": 18834, "upload_time": "2019-01-16T09:20:45", "url": "https://files.pythonhosted.org/packages/dd/3f/10f0365054f20e97b2a6c999b3a3ba6dd13b0e51780b3c87dcdc88eb96f9/python_configuration-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f97f54098c4ca93fd6b7191770a5ca0b", "sha256": "a28fefe67c0319c703e0fc9fef249d613fd9a46797af8867de50def267ea85b7" }, "downloads": -1, "filename": "python-configuration-0.1.0.tar.gz", "has_sig": false, "md5_digest": "f97f54098c4ca93fd6b7191770a5ca0b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4,<4.0", "size": 8623, "upload_time": "2019-01-16T09:20:43", "url": "https://files.pythonhosted.org/packages/2a/55/aed9a9f680138d7196afce4b1a8bb8d7fd0309d3614f66babda6df69067e/python-configuration-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "3710debfff8e4d55990af2584862f66a", "sha256": "68c537c028668382b2fafde9efee6423695a797d953f2d14971de2735aa41306" }, "downloads": -1, "filename": "python_configuration-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "3710debfff8e4d55990af2584862f66a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 24432, "upload_time": "2019-07-16T16:54:46", "url": "https://files.pythonhosted.org/packages/48/91/0ae1882d030f12f0d7b94b28541fe1c8d36f12a11d87a127503564fbfdba/python_configuration-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "995e4ca32334e444ebd55f470dcfbf6b", "sha256": "c0fa006436623d0a0d1dfd082707f2ed69ef0aa6479ea6cfe58922ae166bdcf5" }, "downloads": -1, "filename": "python-configuration-0.2.0.tar.gz", "has_sig": false, "md5_digest": "995e4ca32334e444ebd55f470dcfbf6b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 9663, "upload_time": "2019-07-16T16:54:45", "url": "https://files.pythonhosted.org/packages/43/d7/5dd9234841a2ce71baa6f8deb29eeefe9052431d501526632b78f62a6329/python-configuration-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "7648a9a55afe80d3641080f5c09cc4bb", "sha256": "8c2e112943be64dd12b54216991f048b58f65105e2cd6c42a718397628d77cd3" }, "downloads": -1, "filename": "python_configuration-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "7648a9a55afe80d3641080f5c09cc4bb", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 26636, "upload_time": "2019-08-16T15:36:19", "url": "https://files.pythonhosted.org/packages/2b/b7/b554158d7b33c82a7b5996cafd9857a2526648163a3fbabc4fe8ad44df2f/python_configuration-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "da2ff2c64d5017439a86f8a6e763bb2d", "sha256": "ce8b2b9a957134ec0b049638360be086ea4d6e98e627832fb5accfade250de0f" }, "downloads": -1, "filename": "python-configuration-0.3.0.tar.gz", "has_sig": false, "md5_digest": "da2ff2c64d5017439a86f8a6e763bb2d", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 11357, "upload_time": "2019-08-16T15:36:17", "url": "https://files.pythonhosted.org/packages/ad/4c/2293717188f6b0438591f02bea8ffdb441356b2e4243b6d31f6b144a3f45/python-configuration-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "fd0b07d55859fb6bd27f2b71c0eb1a66", "sha256": "93f3683e2756cd4a0122dc49289e2a85925aae1b9b242ebd6a5fa0bc8dcc3bfe" }, "downloads": -1, "filename": "python_configuration-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "fd0b07d55859fb6bd27f2b71c0eb1a66", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 28626, "upload_time": "2019-10-12T02:31:53", "url": "https://files.pythonhosted.org/packages/f9/c1/ee3c46729fa3196316ceab209fd9dd152397997bd594b5d2b6facb426d9a/python_configuration-0.4.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5b1a7011302e78d5934f0bcffa3a3221", "sha256": "40010aecddc84b028836c976452f1802f71af00f0cca4b9986cb9e8fe0b0002b" }, "downloads": -1, "filename": "python-configuration-0.4.0.tar.gz", "has_sig": false, "md5_digest": "5b1a7011302e78d5934f0bcffa3a3221", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 12221, "upload_time": "2019-10-12T02:31:51", "url": "https://files.pythonhosted.org/packages/76/a1/4e51cd60a919f524f43e15313a9d42b79c56af934a7d1f963850475587bf/python-configuration-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fd0b07d55859fb6bd27f2b71c0eb1a66", "sha256": "93f3683e2756cd4a0122dc49289e2a85925aae1b9b242ebd6a5fa0bc8dcc3bfe" }, "downloads": -1, "filename": "python_configuration-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "fd0b07d55859fb6bd27f2b71c0eb1a66", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 28626, "upload_time": "2019-10-12T02:31:53", "url": "https://files.pythonhosted.org/packages/f9/c1/ee3c46729fa3196316ceab209fd9dd152397997bd594b5d2b6facb426d9a/python_configuration-0.4.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5b1a7011302e78d5934f0bcffa3a3221", "sha256": "40010aecddc84b028836c976452f1802f71af00f0cca4b9986cb9e8fe0b0002b" }, "downloads": -1, "filename": "python-configuration-0.4.0.tar.gz", "has_sig": false, "md5_digest": "5b1a7011302e78d5934f0bcffa3a3221", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 12221, "upload_time": "2019-10-12T02:31:51", "url": "https://files.pythonhosted.org/packages/76/a1/4e51cd60a919f524f43e15313a9d42b79c56af934a7d1f963850475587bf/python-configuration-0.4.0.tar.gz" } ] }