{ "info": { "author": "Amphinicy Technologies ltd", "author_email": "info@amphinicy.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Build Tools" ], "description": "# Config Handler\n\nHandle config files in your projects the easy way.\n\n[![PyPI version](https://badge.fury.io/py/config-handler.svg)](https://badge.fury.io/py/config-handler)\n[![Build Status](https://travis-ci.com/amphinicy/config-handler.svg?branch=master)](https://travis-ci.com/amphinicy/config-handler)\n\n![GitHub issues](https://img.shields.io/github/issues/amphinicy/config-handler.svg)\n![GitHub closed issues](https://img.shields.io/github/issues-closed/amphinicy/config-handler.svg)\n![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed/amphinicy/config-handler.svg)\n\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/Marine-Traffic-API.svg)\n![GitHub](https://img.shields.io/github/license/amphinicy/config-handler.svg?color=blue)\n![GitHub last commit](https://img.shields.io/github/last-commit/amphinicy/config-handler.svg?color=blue)\n\n## Installation\n\n```bash\n> pip install config-handler\n```\n\n## Rules\n\n#### Rule #1 \nUse INI files for config. \nRegarding that please follow INI file language: [https://en.wikipedia.org/wiki/INI_file](https://en.wikipedia.org/wiki/INI_file)\n\n#### Rule #2 \nUse only strings, integers and booleans. \nIf you need to use anything else, the design isn't right.\n\n#### Rule #3 \nDon't put your config file (config.ini) in git repository. \nInstead you have a config template file (config.ini.template).\n\n#### Rule #4 \nConfig file should contain ONLY the stuff that could be changed by user. \nIf you have the data that will never change, use constants.\n\n## Config template file\n\nThis is how config.ini.template file should look like: \n\n![Config template file](docs/images/config_template_file_1.png)\n\nconfig.ini.template file supports template variables (`${project_root_path}`).\n\n## Usage\n\n#### Scenario #1 \n\nYou are running your app for the first time and config.ini doesn't exist yet. \nSo you need to create it from config.ini.template file (use template variables if needed):\n\n```python\nimport os\nfrom config_handler import ConfigHandler\n\ntemplate_config_variables = {\n 'project_root_path': os.path.join('path', 'to', 'project', 'root')\n}\nConfigHandler('./config.ini').sync(template_config_variables)\n``` \n\nAfter this call, config.ini file was created in the same directory where config.ini.template is located and should look like this:\n\n![Config file](docs/images/config_file_1.png)\n\n#### Scenario #2 \n\nNow read your newly created config.ini: \n\n```python\nfrom config_handler import ConfigHandler\n\nconfig = ConfigHandler('./config.ini').read()\n\nprint(config.sections())\n# >>> ['app1', 'app2']\n\nprint(dict(config['DEFAULT']))\n# >>> {'send_email': 'true', 'authenticate_user': 'true'}\n\nprint(dict(config['app1']))\n# >>> {'send_email': 'false', 'line_height': '12', 'input_path': 'path/to/project/root/input/app1', 'authenticate_user': 'true'}\n\nprint(config['DEFAULT']['send_email'])\n# >>> 'true'\n\nprint(config['app1']['front_page_title'])\n# >>> 'Hello World!'\n\nprint(config.getboolean('DEFAULT', 'send_email'))\n# >>> True\n\nprint(config.getboolean('app2', 'send_email'))\n# >>> False\n``` \n\n`.read()` returns `ConfigParser` objects from python's native [Configuration file parser lib](https://docs.python.org/3/library/configparser.html) \n\n#### Scenario #3 \n\nUser made some changes in config.ini file: \n\n![Config file](docs/images/config_file_2.png)\n\nAnd some changes are made in config.ini.template file by the developers:\n\n![Config template file](docs/images/config_template_file_2.png) \n\nThen you need to run sync again: \n\n```python\nimport os\nfrom config_handler import ConfigHandler\n\ntemplate_config_variables = {\n 'project_root_path': os.path.join('path', 'to', 'project', 'root')\n}\nConfigHandler('./config.ini').sync(template_config_variables)\n``` \n\nAfter the sync, config.ini file should look like this: \n\n![Config file](docs/images/config_file_3.png) \n\nSo, what user changes or adds stays in config.ini. \nEverything new that was added in config.ini.template was added in config.ini as well.\n\n#### Scenario #4 \n\nYou can sync and read at the same time: \n\n```python\nfrom config_handler import ConfigHandler\n\nconfig = ConfigHandler('./config.ini').sync({...}).read()\n\n...\n``` \n\n## Exception handling\n\n```python\nfrom config_handler import (ConfigHandler, \n ConfigHandlerException,\n ConfigHandlerFileReadException)\n\ntry:\n config = ConfigHandler('./config.ini').sync({...}).read()\n\nexcept ConfigHandlerFileReadException:\n \"\"\"Read exceptions\"\"\"\n\nexcept ConfigHandlerException:\n \"\"\"All Config Handler exceptions\"\"\"\n``` \n\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/amphinicy/config-handler.git", "keywords": "config,config-handler,python,json", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "Config-Handler", "package_url": "https://pypi.org/project/Config-Handler/", "platform": "", "project_url": "https://pypi.org/project/Config-Handler/", "project_urls": { "Homepage": "https://github.com/amphinicy/config-handler.git", "Source": "https://github.com/amphinicy/config-handler.git" }, "release_url": "https://pypi.org/project/Config-Handler/0.1.0/", "requires_dist": [ "click (~=7.0)" ], "requires_python": "", "summary": "Handle config files in your projects the easy way", "version": "0.1.0" }, "last_serial": 5128420, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "7a2d6b5ae788ba798adead8cdb076c0c", "sha256": "6dd3ad8c27180a3267fd597bd7324b9b85bd9e2b76e390483ed348b346a403ec" }, "downloads": -1, "filename": "Config_Handler-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "7a2d6b5ae788ba798adead8cdb076c0c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6908, "upload_time": "2019-04-11T11:07:20", "url": "https://files.pythonhosted.org/packages/7a/49/58812841be303a8006cdacd8306ef3bbf0af9c56bcd7e2a648baec339ac0/Config_Handler-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fbe28bfd92263be2ddbd2302e5416afa", "sha256": "e3e355b6e3f1ee9a5fe0eb9e7f7e1aa8e5dc96511c24c828054c95d8a507d8b6" }, "downloads": -1, "filename": "Config Handler-0.1.0.tar.gz", "has_sig": false, "md5_digest": "fbe28bfd92263be2ddbd2302e5416afa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4765, "upload_time": "2019-04-11T11:07:21", "url": "https://files.pythonhosted.org/packages/a0/74/8d077b81e2afc57cc51097fcdbe3550353e6d94814fc15910641997df78e/Config%20Handler-0.1.0.tar.gz" } ], "0.1.0.dev0": [ { "comment_text": "", "digests": { "md5": "ba4021890b5a9b32ddc06599c9bfe869", "sha256": "366c2803c5d0ae93a4f520c201d850d1820e2d7bc3d46bf0d7f5000948399720" }, "downloads": -1, "filename": "Config_Handler-0.1.0.dev0-py3-none-any.whl", "has_sig": false, "md5_digest": "ba4021890b5a9b32ddc06599c9bfe869", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6791, "upload_time": "2019-04-10T14:55:31", "url": "https://files.pythonhosted.org/packages/81/f7/a029113a5aa3bc557a897dcf1a1f2a427843f4ebd9406946e4933f3102a4/Config_Handler-0.1.0.dev0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5fd4a45c70bd5891054571d8646809f9", "sha256": "f9c9832989d0bfe8ca5ed4a8c3841df4f6630eea86f43e7cdbe8cf438e3f2f1e" }, "downloads": -1, "filename": "Config Handler-0.1.0.dev0.tar.gz", "has_sig": false, "md5_digest": "5fd4a45c70bd5891054571d8646809f9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4506, "upload_time": "2019-04-10T14:55:33", "url": "https://files.pythonhosted.org/packages/e2/8f/7db0c66377cf92731427f474e49bdcf19874803b1b7914a942eb3c7e04e6/Config%20Handler-0.1.0.dev0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7a2d6b5ae788ba798adead8cdb076c0c", "sha256": "6dd3ad8c27180a3267fd597bd7324b9b85bd9e2b76e390483ed348b346a403ec" }, "downloads": -1, "filename": "Config_Handler-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "7a2d6b5ae788ba798adead8cdb076c0c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6908, "upload_time": "2019-04-11T11:07:20", "url": "https://files.pythonhosted.org/packages/7a/49/58812841be303a8006cdacd8306ef3bbf0af9c56bcd7e2a648baec339ac0/Config_Handler-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fbe28bfd92263be2ddbd2302e5416afa", "sha256": "e3e355b6e3f1ee9a5fe0eb9e7f7e1aa8e5dc96511c24c828054c95d8a507d8b6" }, "downloads": -1, "filename": "Config Handler-0.1.0.tar.gz", "has_sig": false, "md5_digest": "fbe28bfd92263be2ddbd2302e5416afa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4765, "upload_time": "2019-04-11T11:07:21", "url": "https://files.pythonhosted.org/packages/a0/74/8d077b81e2afc57cc51097fcdbe3550353e6d94814fc15910641997df78e/Config%20Handler-0.1.0.tar.gz" } ] }