{ "info": { "author": "Stefano Terna", "author_email": "stefano.terna@tomorrowdata.io", "bugtrack_url": null, "classifiers": [], "description": "# License\n\nCopyright 2015 Stefano Terna\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n# prettysettings\nprettysettings is a minimal library which allows to save and retrieve configuraton settings from a json file and from env variables.\n\n## Override:\nOverride order is:\n- first read from defaults\n- then override from file\n- last override from env variables\n\n## Keys:\n- defaults dict is used as a reference to load keys from file and from env variables\n- if a key is found in the file (or env vars) which is not present in the defaults it is discarded\n\n## Types:\n- defaults dict is used to enforce type when loading from file or env variables\n- this ensures that env variables, which must be strings, are parsed to the type used in the default dict\n- parsed types are: `bool`, `int`, `float`, `str`\n- any type `T` for which a string representation exists, so that `T(string)` is the expected object is supported\n- hence if `defaults = {'a': 1}` while the file contains `{'a': '2'}`, the result will be `settings.a == 2` (`int`)\n- whereas if `defaults = {'a': 1}` while the file contains `{'a': 'string'}`, the Settings' constructor will raise an exception\n\n## Computed settings Hooks\nAfter reading items from defaults, file, env, the consrtuctor can call hoooks to add custom computed items to the settings object.\n- This can be handy to produce new items which are mere functions of the stored ones.\n- Or it can be useful to add to the settings object complex configuration items (i.e. not serializable to strings).\n- Computed settings are not persisted when updating the settings object.\n\n# Usage\n## basic usage, just defaults: \n```python\nfrom prettysettings import Settings\nsettings = Settings(defaults = {'option1': 1, 'option2': 'myoption'})\nprint(settings.option1) # output 1\nprint(settings.option2) # output 'myoption'\n```\n## load and update from and to file\n\nSay you have `settings.json` containing:\n```json\n{\n \"option1\": 2,\n \"option2\": \"my_new_option\"\n}\n```\nthen:\n```python\nfrom prettysettings import Settings\nsettings = Settings(defaults = {'option1': 1, 'option2': 'myoption'}, filename='./settings.json')\nprint(settings.option1) # output 2\nprint(settings.option2) # output 'my_new_option'\n\n# whereas\nsettings = Settings(defaults = {'option1': 1, 'option2': 3}, filename='./settings.json')\n# raises an exception for type incompatibility among option2 in defaults and in file.\n\n```\n\nAbout filename:\n- if filename does not exists it is skipped and Settings object is created with defaults\n- this allows to create settings from defaults > updating them > persisting them to file even if it didn't exist at creation time\n\nSay `settings.json` does not exists:\n```python\nfrom prettysettings import Settings\nsettings = Settings(defaults = {'option1': 1, 'option2': 'myoption'}, filename='./settings.json')\n\nsettings.update( {'option2': 'my_new_option'}, persist=True)\n\n```\nwill produce `settings.json` containing:\n```json\n{\n \"option1\": 1,\n \"option2\": \"my_new_option\"\n}\n```\n\n## Computed settings Hooks\n\n```python\nfrom prettysettings import Settings\n\ncshooks = {\n 'computedoption': lambda settings: 'hey this is computed with {}!!'.format(settings.option2)\n}\n\nsettings = Settings(defaults= {'option1': 1, 'option2': 'myoption'}, computed_settings_hooks=cshooks)\nprint(settings.option1) # output 1\nprint(settings.option2) # output 'myoption'\nprint(settings.computedoption) # output 'hey this is computed with myoption!!'\n```\n\n**Hint**: if you have more hooks with dependencies with one another, just wrap whem within an OrderedDict to be sure they will be executed in the correct order:\n\n```python\nfrom collections import OrderedDict\nfrom prettysettings import Settings\n\ncshooks = OrderedDict([\n ('computedoption', lambda settings: 'hey this is computed with {}!! '.format(settings.option2)),\n ('computedoption2', lambda settings: settings.option1 * settings.computedoption)\n])\n\nsettings = Settings(defaults= {'option1': 2, 'option2': 'myoption'}, computed_settings_hooks=cshooks)\nprint(settings.option1) # output 2\nprint(settings.option2) # output 'myoption'\nprint(settings.computedoption) # output 'hey this is computed with myoption!!'\nprint(settings.computedoption2) # output 'hey this is computed with myoption!! hey this is computed with myoption!!'\n```", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/iottly/prettysettings", "keywords": "prettysettings settings json environment variables", "license": "Apache License, Version 2.0", "maintainer": null, "maintainer_email": null, "name": "prettysettings", "package_url": "https://pypi.org/project/prettysettings/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/prettysettings/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/iottly/prettysettings" }, "release_url": "https://pypi.org/project/prettysettings/1.3.3/", "requires_dist": null, "requires_python": null, "summary": "This package provides a minimal class for pretty settings management.", "version": "1.3.3" }, "last_serial": 2860098, "releases": { "1.1": [ { "comment_text": "", "digests": { "md5": "d7c86466cb09543b1c0c1249ddb4a69b", "sha256": "141a0c719810782c487f5d3f4671e7d5ab4a0d61985cc9ae3608e3f15f446bb5" }, "downloads": -1, "filename": "prettysettings-1.1-py2.7.egg", "has_sig": false, "md5_digest": "d7c86466cb09543b1c0c1249ddb4a69b", "packagetype": "bdist_egg", "python_version": "2.7", "requires_python": null, "size": 4136, "upload_time": "2016-02-19T15:12:49", "url": "https://files.pythonhosted.org/packages/8e/50/efd8c679a6b95e19b01aa317d0f7b6e8718ba43b29e1773ee2f483d4d624/prettysettings-1.1-py2.7.egg" }, { "comment_text": "", "digests": { "md5": "4e4aed410fb0bcce8437ce71a481f200", "sha256": "ee5b2a22e0f34d668abe706afd73d59e4bd433f0bee4733011231e1f4c601a95" }, "downloads": -1, "filename": "prettysettings-1.1-py3.4.egg", "has_sig": false, "md5_digest": "4e4aed410fb0bcce8437ce71a481f200", "packagetype": "bdist_egg", "python_version": "3.4", "requires_python": null, "size": 4297, "upload_time": "2016-02-19T15:12:59", "url": "https://files.pythonhosted.org/packages/f1/77/79c687aa7d13183dd3e728fd622f7cbc185d66879663739a6164e575698a/prettysettings-1.1-py3.4.egg" }, { "comment_text": "", "digests": { "md5": "879fbcfb521b797913644b16d031b634", "sha256": "474f65d90dfdb00f632dccbfd3d62be91f03c58ac710831531e1612b20368fe8" }, "downloads": -1, "filename": "prettysettings-1.1.tar.gz", "has_sig": false, "md5_digest": "879fbcfb521b797913644b16d031b634", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2098, "upload_time": "2016-02-19T15:13:09", "url": "https://files.pythonhosted.org/packages/0f/a7/2bfa358ed942b648a51a7aee268c725c98e22eda5889e24085e7b804217c/prettysettings-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "368819b72ac2a06db0fea469b7c0539b", "sha256": "40ca7f42eace8c248c6894945cc303e9e06d39483e5696e01e6381b9e7932405" }, "downloads": -1, "filename": "prettysettings-1.2-py2.7.egg", "has_sig": false, "md5_digest": "368819b72ac2a06db0fea469b7c0539b", "packagetype": "bdist_egg", "python_version": "2.7", "requires_python": null, "size": 12713, "upload_time": "2016-02-25T14:45:00", "url": "https://files.pythonhosted.org/packages/57/e5/a4acd316ace80c2209b5fd3d41aef52f2be80497dee9c1504786be6eb926/prettysettings-1.2-py2.7.egg" }, { "comment_text": "", "digests": { "md5": "9543146e29bc4b3c04abc79169eb40b2", "sha256": "c62f2ef4ce58dcff8e1ddac375e593feb8b579ffcde62d6eee01b48e25d48b36" }, "downloads": -1, "filename": "prettysettings-1.2-py3.4.egg", "has_sig": false, "md5_digest": "9543146e29bc4b3c04abc79169eb40b2", "packagetype": "bdist_egg", "python_version": "3.4", "requires_python": null, "size": 13117, "upload_time": "2016-02-25T14:45:08", "url": "https://files.pythonhosted.org/packages/50/eb/5c862fe111b18ea5c842b6f62b67ef26ccc56cd3066b1df9ff4e1e2ec649/prettysettings-1.2-py3.4.egg" }, { "comment_text": "", "digests": { "md5": "dd437bc5d6dd54cc35fa43aed0278ced", "sha256": "1821471accd876a4b52bf362a4fd603cbe1efe085ff982c1d0bc5837dafa446d" }, "downloads": -1, "filename": "prettysettings-1.2.tar.gz", "has_sig": false, "md5_digest": "dd437bc5d6dd54cc35fa43aed0278ced", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4367, "upload_time": "2016-02-25T14:45:14", "url": "https://files.pythonhosted.org/packages/f9/ec/8a83ee7e6d67fa367e33cb5ae36f1b5ccd884c65c30f0305318abb3893f1/prettysettings-1.2.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "e66d70be50be6f551ad8f614bf373975", "sha256": "ea689cc86da2684e7f4d0e52f2770fb4b4803204e41e3835877d4fb0b7b960ad" }, "downloads": -1, "filename": "prettysettings-1.3.tar.gz", "has_sig": false, "md5_digest": "e66d70be50be6f551ad8f614bf373975", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4622, "upload_time": "2017-03-04T12:42:11", "url": "https://files.pythonhosted.org/packages/b0/46/96be984204830f94009ead19d74e56d8ec3c46dfe15efafb874de9c2254b/prettysettings-1.3.tar.gz" } ], "1.3.1": [ { "comment_text": "", "digests": { "md5": "a58ad15c95344766f7f68d96687fcb6b", "sha256": "301b72479903be880c41b401f3816c4ed596e9f77f3032b2838563665f8ab390" }, "downloads": -1, "filename": "prettysettings-1.3.1.tar.gz", "has_sig": false, "md5_digest": "a58ad15c95344766f7f68d96687fcb6b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4632, "upload_time": "2017-03-04T13:31:24", "url": "https://files.pythonhosted.org/packages/49/4a/6b8a3fce93409dc934d9226ec78ec8b15559ed91f2d6d726bb2dc8a659b5/prettysettings-1.3.1.tar.gz" } ], "1.3.2": [], "1.3.3": [ { "comment_text": "", "digests": { "md5": "de0dbad660689b38d641ea375bdcde60", "sha256": "583c3e99205ccc55dcae5bc3718d7bc31b92dfcce7c74b4b6b492bec7259f905" }, "downloads": -1, "filename": "prettysettings-1.3.3.tar.gz", "has_sig": false, "md5_digest": "de0dbad660689b38d641ea375bdcde60", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4680, "upload_time": "2017-05-08T21:02:32", "url": "https://files.pythonhosted.org/packages/25/95/7950d033e023802fbe862c0110742217c6b5344c253c1c2a3dffabcb063d/prettysettings-1.3.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "de0dbad660689b38d641ea375bdcde60", "sha256": "583c3e99205ccc55dcae5bc3718d7bc31b92dfcce7c74b4b6b492bec7259f905" }, "downloads": -1, "filename": "prettysettings-1.3.3.tar.gz", "has_sig": false, "md5_digest": "de0dbad660689b38d641ea375bdcde60", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4680, "upload_time": "2017-05-08T21:02:32", "url": "https://files.pythonhosted.org/packages/25/95/7950d033e023802fbe862c0110742217c6b5344c253c1c2a3dffabcb063d/prettysettings-1.3.3.tar.gz" } ] }