{ "info": { "author": "Vladimir Chub", "author_email": "vartagg@users.noreply.github.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": "|Build Status|\n\nKonf\n====\n\nTiny tool that designed to solve problems of Python configuration files located outside of VCS.\n\n\nInstallation:\n\n.. code:: bash\n\n pip install konf\n\nRunning tests:\n\n.. code:: bash\n\n nosetests\n\n\nWhy Konf?\n=========\n\nSometimes there is a need to get some settings outside of Python code and then to use them in an application. This can be secret keys, authentication tokens, URLs of third-party services, or other settings which depends on the server. Developers (or IT engineers) are faced with several challenges:\n\n\n- Validation of data importing from config. It may be simple typing, matching with range of possible values or with regexes.\n- Respect of all settings. Check that config contains all required data. Also, it can be useful to check that there are no extra (redundant) things inside a config (because it can be the data, forgotten to consider in an application).\n- Understanding what happens when something goes wrong. Correct representational exceptions allows immediately understand (just having looked at logs) what the problem is. Useful when deploying servers.\n\n\nFeatures:\n=========\n\n- Allows to DRY import variables\n- Readability for humans\n- JSON and YAML support out of the box (In fact, additional libraries will be automatically installed for support it)\n- Typing or validation of all importing data. And this is **required** because human factor prevention\n- Python 2.7, 3+ compatible\n- 100% code coverage\n- Custom format of configuration files can be used. If I missed and at now anyone uses something else except of supported formats, you can create an `issue `__ about it, and probably the new format will be supported in next versions.\n\nFor Python data structures validation is used excellent library\n`kolypto/py-good `__\n\nFor YAML parsing is used a great lib of Kirill Simonov\n`PyYAML `__\n\n\nQuick start\n===========\n\nJust look at the code.\n\n.. code:: python\n\n from konf import Konf\n\n # Filling of variables from config file tokens.yaml in k_ object\n k_ = Konf('tokens.yaml')\n\n # Getting variables from k_: first argument is a name of variable (specified in the config),\n # second can be a type or validator\n SECRET_KEY = k_('secret_key', basestring)\n AUTH_TOKEN = k_('auth_token', basestring)\n\n # In the next example is used a validator: list, that must contain\n # only objects with basestring type (str or unicode)\n CLIENTS = k_('clients', [basestring])\n\n # And dict with two required keys with appropriate types\n DELAYS = k_('delays', {'case1': int, 'case2': int})\n\n\n\nYou can find more details and advanced examples about natural validation on\n`good `__\npage\n\n\nOk, what happened next? Imagine that tokens.yaml is missing. In case of this, after the script execution, we can see next exception message:\n\n.. code:: pytb\n\n konf.main.ReadError: Can`t access to the configuration file \"tokens.yaml\"\n\n\nLet's create a file tokens.yaml and input next:\n\n.. code:: yaml\n\n ---\n secret_key: FOO\n auth_token: BAR\n clients: Q,\n delays:\n case1: 15\n case2: 17\n\n\nException is raised:\n\n.. code:: pytb\n\n Traceback (most recent call last):\n File \"/Users/me/python/examples/example.py\", line 19, in \n CLIENTS = k_('clients', [basestring])\n File \"/Users/me/python/examples/konf/konf/main.py\", line 126, in __call__\n raise self.ValidationError(e)\n konf.main.ValidationError: expected a list\n\n\nThen fix this mistake:\n\n.. code:: yaml\n\n ---\n secret_key: FOO\n auth_token: BAR\n clients: [Q]\n delays:\n case1: 15\n case2: 17\n\n\nNow all be OK, because ``[Q]`` represents a list of values, not a string. **Note**: you can see the list of all supported exceptions in the end of this documentation page. \n\n\nDefault values\n==============\n\nDo you need to use a value if any variable is not contained in a config file? You can use default value.\n\n.. code:: python\n\n from konf import Konf\n\n k_ = Konf('extra.yml')\n\n # 3rd arg is a default. If variable STRICT is not contained in config file,\n # USE_STRICT will be False\n USE_STRICT = k_('STRICT', bool, False)\n\n # You can also use None as default value\n WINNER = k_('WINNER', int, None)\n\n # Default values will never be validated, because you forcibly declaring it.\n # So, the next example is legit.\n SHIFT_TIME = k_('SHIFT', int, complex(42, 42))\n\n\nChecking redundant variables\n============================\n\nSometimes you want to be sure that all of the variables in a config file are used and you haven't forgotten anything.\nIn this situation the ``check_redundant()`` method can be helpful.\n\n.. code:: python\n\n from konf import Konf\n\n k_ = Konf('bar.yaml')\n\n FOO1 = k_('foo1', int)\n\n FOO2 = k_('foo2', int)\n\n # If config file contains anything except foo1 and foo2,\n # RedundantConfigError will be raised after call of this method!\n k_.check_redundant() # Fail\n\n\nDefault values and ``check_redundant()`` also working fine together.\n\n.. code:: python\n\n from konf import Konf\n\n k_ = Konf('foo.yaml')\n\n X = k_('X', int, 0)\n\n Y = k_('Y', int, 0)\n\n # If X and Y doesn't contained in the config file, RedundantConfigError will not be raised\n # after next line of code, because they have default values. \n # So, it's just like X == 0 and Y == 0\n k_.check_redundant() # Success\n\n\nMore complex example\n====================\n\nWrite the content to a social_auth.yml in a readable form:\n\n.. code:: yaml\n\n ---\n SN:\n vk:\n key: '123'\n secret: qwerty\n google:\n key: '456'\n secret: uiop\n twitter:\n key: '789'\n secret: zxc\n ok:\n key: '000'\n secret: vbn\n public_name: m\n\nStep-by-step process it in settings.py\n\n.. code:: python\n\n # 0. Select configuration file\n k_ = Konf('social_auth.yml')\n\n # 1. Declare validators\n # You can cache validators inside a Konf object as if it's a standard python dict\n k_['v1'] = {\n 'key': basestring,\n 'secret': basestring,\n }\n k_['v2'] = {\n 'key': basestring,\n 'secret': basestring,\n 'public_name': basestring\n }\n\n # 2. Get variables from config\n # For avoid copy-paste and massive chunks of code, just declare a new variable\n # and pass data from config to it\n sn = k_('SN', {\n 'vk': k_['v1'], # You can choose validator you want, for example v1...\n 'google': k_['v1'],\n 'twitter': k_['v1'],\n 'ok': k_['v2'] # ...or v2\n })\n\n # 3. Fill everything to a python variables which are required for 3rd-party library\n SOCIAL_AUTH_VK_OAUTH2_KEY = sn['vk']['key']\n SOCIAL_AUTH_VK_OAUTH2_SECRET = sn['vk']['secret']\n SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = sn['google']['key']\n SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = sn['google']['secret']\n SOCIAL_AUTH_TWITTER_KEY = sn['twitter']['key']\n SOCIAL_AUTH_TWITTER_SECRET = sn['twitter']['secret']\n SOCIAL_AUTH_ODNOKLASSNIKI_KEY = sn['ok']['key']\n SOCIAL_AUTH_ODNOKLASSNIKI_SECRET = sn['ok']['secret']\n SOCIAL_AUTH_ODNOKLASSNIKI_OAUTH2_PUBLIC_NAME = sn['ok']['public_name']\n\n # 4. Check that config doesn't contain some garbage\n # (this might mean you forgot to get these variables, or this config is wrong, some draft for example)\n k_.check_redundant()\n\n # 5. If server is running without errors, and you will meet issue with this 3rd-party library later,\n # you can be sure that problem isn't in your configuration file.\n # Otherwise, you'll just catch a error on a start server stage.\n\nList of supported Exceptions\n============================\n\n\n======================== ===================================================================================\n Exception Raises when...\n======================== ===================================================================================\nValidationError Data from config file doesn't match to the ``type_or_validator`` arg\n\nIncompleteConfigError Trying to get variable that not contained in a config file\n\nReadError Config file can't be read\n\nParseError Third-party parser can't parse configuration file\n\nReassignmentError Variable is loaded not for the first time\n\nFileExtensionError Extension of the config isn't supported, and ``parse_callback`` arg isn't specified\n\nRedundantConfigError Call of ``check_redundant()`` if any of variables in a config isn't used in app\n\nValidatorManagementError Incorrect usage of validators\n======================== ===================================================================================\n\n.. |Build Status| image:: https://travis-ci.org/vartagg/konf.svg?branch=master\n :target: https://travis-ci.org/vartagg/konf", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/vartagg/konf/", "keywords": "konf,json,yaml,config", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "konf", "package_url": "https://pypi.org/project/konf/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/konf/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/vartagg/konf/" }, "release_url": "https://pypi.org/project/konf/1.2/", "requires_dist": null, "requires_python": null, "summary": "Konf is a Python package which designed to simplify the use of variables in configuration files. json and yaml supported out of the box.", "version": "1.2" }, "last_serial": 1896802, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "18c5ded11ba26a484a5406161cbc27a9", "sha256": "0d639c0425a37bd9f91a17d85546358a3acfb5e273009917a7e1dc8a9e8e343d" }, "downloads": -1, "filename": "konf-1.0.tar.gz", "has_sig": false, "md5_digest": "18c5ded11ba26a484a5406161cbc27a9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3429, "upload_time": "2015-02-07T14:46:46", "url": "https://files.pythonhosted.org/packages/1d/fb/4a002b5c6e13f7ecca716c086d6c756066d64a26964c5774474968b74ec3/konf-1.0.tar.gz" } ], "1.1": [], "1.1.1": [ { "comment_text": "", "digests": { "md5": "72351ba3f5724419f6d9f924881565da", "sha256": "05a8557c98f4d5bd931cc003a949b5b1a6f7eed58e25186bbdc66fcfddb4426a" }, "downloads": -1, "filename": "konf-1.1.1.tar.gz", "has_sig": false, "md5_digest": "72351ba3f5724419f6d9f924881565da", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4603, "upload_time": "2015-02-08T10:35:45", "url": "https://files.pythonhosted.org/packages/35/c0/b1aebf13256b75b06adb2ad9518a2ed88d1726ec99a1bf78dc57c97e8b3f/konf-1.1.1.tar.gz" } ], "1.1.2": [ { "comment_text": "", "digests": { "md5": "13808eba74f37d2ce5d3d0f3664e191f", "sha256": "8c79ce1ccdf7bcfc230006f0829e94f0aad016452db0958eb1a20549e61a8884" }, "downloads": -1, "filename": "konf-1.1.2.tar.gz", "has_sig": false, "md5_digest": "13808eba74f37d2ce5d3d0f3664e191f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5929, "upload_time": "2015-02-08T19:27:48", "url": "https://files.pythonhosted.org/packages/c9/29/51fbefd11972b66918405a61234529df540a097b949c93ff3e1b3b2dec00/konf-1.1.2.tar.gz" } ], "1.1.2a0": [ { "comment_text": "", "digests": { "md5": "23741ae233445b6a9bd1e6588dd23366", "sha256": "b6c46c5fd4d9cdcdf3f29fa369f48ba7a4258d3edad3a8225955d87d54e7fce2" }, "downloads": -1, "filename": "konf-1.1.2a0.tar.gz", "has_sig": false, "md5_digest": "23741ae233445b6a9bd1e6588dd23366", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6088, "upload_time": "2015-05-14T14:33:51", "url": "https://files.pythonhosted.org/packages/67/24/0267022de02c5a4e770e2b2be4e950a37df3e5bee26779d9ec0491d98716/konf-1.1.2a0.tar.gz" } ], "1.1.3": [ { "comment_text": "", "digests": { "md5": "adf4ded8fc28352b21450143d4d96f6b", "sha256": "fb8422e2c5953b7ba97d17bd2e65d906f5b38d74d81089382a85b26906a32c18" }, "downloads": -1, "filename": "konf-1.1.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "adf4ded8fc28352b21450143d4d96f6b", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 9738, "upload_time": "2015-05-14T14:45:19", "url": "https://files.pythonhosted.org/packages/cf/d8/3a16d9befd2e99b817553a4f06496a995d338714827e173059fc32aecf7e/konf-1.1.3-py2.py3-none-any.whl" } ], "1.1.4": [ { "comment_text": "", "digests": { "md5": "58bbf2e02efbb6486492fed795fd2b6b", "sha256": "4eef9851ea06485d563b8149ab2c6020e6ebac8466cc6dbed06be2aed4080145" }, "downloads": -1, "filename": "konf-1.1.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "58bbf2e02efbb6486492fed795fd2b6b", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 12637, "upload_time": "2015-05-23T07:10:45", "url": "https://files.pythonhosted.org/packages/99/0d/181fb1b4b0e4655b02cf492c7ed8abb804ef024e2718879282b754de61df/konf-1.1.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ddb74df092effd27e5b43ce24b14f599", "sha256": "b542a03223a00920d9f4dc0824e8843e88016f5c8c76e9d263fc6a040d5c88f8" }, "downloads": -1, "filename": "konf-1.1.4.tar.gz", "has_sig": false, "md5_digest": "ddb74df092effd27e5b43ce24b14f599", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7541, "upload_time": "2015-05-23T07:10:41", "url": "https://files.pythonhosted.org/packages/37/9b/94acbd30498c5ec0e94964f8ede31f4287d2a7608e0ab4ff4618c9a241e8/konf-1.1.4.tar.gz" } ], "1.1.5": [ { "comment_text": "", "digests": { "md5": "1ae479eede189263ff1ac559ff20dedc", "sha256": "da9fd9ce4c565eedab9fabd307635ec9685ef5b318df803b61545a4166dc2eaa" }, "downloads": -1, "filename": "konf-1.1.5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "1ae479eede189263ff1ac559ff20dedc", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 12402, "upload_time": "2015-06-21T10:04:26", "url": "https://files.pythonhosted.org/packages/81/a0/19c394170a9e8f3030a08a2e673158ad44706cbfc69595dc938440c35c76/konf-1.1.5-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "dc100db6fa6af76400ba7e6d9e4c2668", "sha256": "3f10be667fb5b5358213ef0eac534e8771c8fc9e41b6dee96c77c4b5b5860339" }, "downloads": -1, "filename": "konf-1.1.5.tar.gz", "has_sig": false, "md5_digest": "dc100db6fa6af76400ba7e6d9e4c2668", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7292, "upload_time": "2015-06-21T10:04:23", "url": "https://files.pythonhosted.org/packages/9f/08/748261e4282bb7ed9f3bd15492173d01396ad682671b8479c8a9c5a3aa1a/konf-1.1.5.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "7ca1dc77e9fb384de947fe0aad73aac7", "sha256": "f0c8aafec8909a13c0a63ee15ae3e32fcd81e082b24853fe7b571a2be6c0dfb6" }, "downloads": -1, "filename": "konf-1.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7ca1dc77e9fb384de947fe0aad73aac7", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 15765, "upload_time": "2016-01-09T19:36:03", "url": "https://files.pythonhosted.org/packages/59/c8/39021e70b7a4327598321960bce3351b8c7bc5e450175063238c8ccdb5d8/konf-1.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "703c1656b5cd327019ea353242e132ce", "sha256": "7c89721bebd233e4b57cdf6b638b07fa5c3de8aa054e29dc001c2e1958bfe5cd" }, "downloads": -1, "filename": "konf-1.2.tar.gz", "has_sig": false, "md5_digest": "703c1656b5cd327019ea353242e132ce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9030, "upload_time": "2016-01-09T19:35:56", "url": "https://files.pythonhosted.org/packages/9f/37/602e46bdfe79f7513076e11479c32ee94b264962770bd4ba1a3419aa68ba/konf-1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7ca1dc77e9fb384de947fe0aad73aac7", "sha256": "f0c8aafec8909a13c0a63ee15ae3e32fcd81e082b24853fe7b571a2be6c0dfb6" }, "downloads": -1, "filename": "konf-1.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7ca1dc77e9fb384de947fe0aad73aac7", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 15765, "upload_time": "2016-01-09T19:36:03", "url": "https://files.pythonhosted.org/packages/59/c8/39021e70b7a4327598321960bce3351b8c7bc5e450175063238c8ccdb5d8/konf-1.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "703c1656b5cd327019ea353242e132ce", "sha256": "7c89721bebd233e4b57cdf6b638b07fa5c3de8aa054e29dc001c2e1958bfe5cd" }, "downloads": -1, "filename": "konf-1.2.tar.gz", "has_sig": false, "md5_digest": "703c1656b5cd327019ea353242e132ce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9030, "upload_time": "2016-01-09T19:35:56", "url": "https://files.pythonhosted.org/packages/9f/37/602e46bdfe79f7513076e11479c32ee94b264962770bd4ba1a3419aa68ba/konf-1.2.tar.gz" } ] }