{ "info": { "author": "Wampeter Foma", "author_email": "foma@wampeter.org", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "kon\n===\n\n.. contents:: Table of contents\n\n\nOverview\n--------\n\n`kon`_ is a very simple configuration file(s) management system that parses one or more configuration files in a path and provides an object tree that can be accessed directly. It also attempts to parse the data as concrete types so that you don't have to explicitly get specific types, only for `INI`_ files. This does introduce some constraints and deviations from default implementations in python, but the convenience is generally worth it. Moreover this behavior can be overridden. kon currently handles only `INI`_ and `JSON`_ files.\n\n\nInstallation\n------------\n\nInstall the extension using ``pip``:\n\n.. code:: bash\n\n $ pip install kon\n\nor ``easy_install``:\n\n.. code:: bash\n\n $ easy_install kon\n\n\nUsage\n-----\n\nBasic Usage\n+++++++++++\n\nYou can instantiate a ``Konfig`` object by calling its constructor:\n\n.. code:: python\n\n from kon import Konfig\n\n cfg = Konfig('/path/to/folder/or/ini-file')\n # this can also accept options for loading by handlers\n cfg.load()\n\nThe load method will try to get an appropriate file handler based on the filename extension. If none exists, it will skip that file. The file handlers are instantiated with any default values you may want to provide the configuration. For each file handler it then calls the instance's ``load`` method. This method can accept handler specific loading options. Currently supported handlers and their behaviors are documented below.\n\nIf you want to specify default arguments, you can pass them in as keywords arguments to the constructor and they are passed through to the file handlers used to load the files.\n\n.. code:: python\n\n from kon import Konfig\n\n cfg = Konfig('/path/to/folder/or/ini-file', a=1, b=2.2, c=False)\n cfg.load()\n\nLoad Behavior\n~~~~~~~~~~~~~\n\nThe ``load`` method does a couple of things.\n\n- It will walk the directory tree starting from the root directory you provide in the constructor call and create objects per directory as it goes along.\n- Once it encounters a file, it will try to get a file handler for that type of file.\n- If it cannot get a file handler, the file will be skipped.\n- If it can get the file handler, it will instantiate it, pass it in the defaults it got and then call *it's* ``load`` method passing in any parameters it got.\n\nFor e.g. if you have a directory tree like the following:\n\n::\n\n kon\n \u251c\u2500\u2500 a.ini\n \u251c\u2500\u2500 b\n \u2502\u00a0\u00a0 \u251c\u2500\u2500 c.ini\n \u2502\u00a0\u00a0 \u251c\u2500\u2500 d.json\n \u2502\u00a0\u00a0 \u251c\u2500\u2500 e\n \u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 e.ini\n \u2502\u00a0\u00a0 \u251c\u2500\u2500 g.json\n \u2502\u00a0\u00a0 \u2514\u2500\u2500 h.ini\n \u251c\u2500\u2500 i.ini\n \u251c\u2500\u2500 j.ini\n \u2514\u2500\u2500 k.ini\n\nThe corresponding object tree created by ``load`` before calling the handlers load will be exactly like the tree above sans the filename extension.\n\nIn the event that you have a folder and a file by the same prefix, for e.g.:\n\n::\n\n kon\n \u251c\u2500\u2500 a.ini\n \u2514\u2500\u2500 a.ini\n \u00a0\u00a0 \u2514\u2500\u2500 c.ini\n\nit will result in a single object kon.a with merged sub-children.\n\n\nJSONFileHandler\n+++++++++++++++\n\nThis handler parses `JSON`_ files that it finds in the path specified or an individual file if it is so specified. Internally it delegates to the default python ``json`` library.\n\nOptions\n~~~~~~~\n\n``preserve_case``\n If set to ``false`` normalizes the key names to be lower case. By default the json loads function preserves case. This is the opposite of what happens with `INIFileHandler`_.\n``encoding``\n Passthrough option for `json.loads`_\n\n\nINIFileHandler\n++++++++++++++\n\nThis handler parses `INI`_ files that it finds in the path specified or an individual file if it is so specified. Internally it uses `SafeConfigParser`_ to load and parse the files. The individual sections, options and values are processed again.\n\nOptions\n~~~~~~~\n\n``preserve_case``\n If set to ``true`` preserves the case of the option names. Sections are still *case-insensitive*. By default ``SafeConfigParser`` normalizes all option names to lower case. This will prevent that.\n``dict_type``\n Passthrough option for ``SafeConfigParser``, see below\n``allow_no_value``\n Passthrough option for ``SafeConfigParser``, see below\n\nCustomizing SafeConfigParser\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIf you want to customize the way the internal `SafeConfigParser`_ works you can use the arguments as specified in the `RawConfigParser`_ constructor documentation and pass them to the ``load`` method call on a ``Konfig`` instance.\n\n.. warning::\n Do not pass in the defaults argument as that will be *ignored*. The defaults that are sent to the parser should be provided as keyword arguments to the constructor.\n\nFor example:\n\n.. code:: python\n\n cfg = Konfig('/path/to/folder/or/ini-file')\n cfg.load(dict_type=OrderedDict, allow_no_value=True)\n\n\nImplementation Details\n~~~~~~~~~~~~~~~~~~~~~~\n\n``Konfig`` uses `SafeConfigParser`_ to load the INI file. Consequently you get the built-in parsing and interpolation capabilities of the parser.\n\nBecause ``SafeConfigParser`` does not automatically coerce the values to an appropriate type, `kon`_ will try to do it's best to do some for you. The following cast attempts are made in order of precedence:\n\n * `int`_\n * `float`_\n * `boolean`_\n * list, dict or tuple (using `ast.literal_eval `_)\n\n.. note::\n * The behavior deviates from ``SafeConfigParser``'s treatment of boolean because a type-coercion to `int`_ happens before a type-coercion to `boolean`_. So if you want a boolean set it to one of ``yes, no, on, off, true or false`` only.\n\n\n\n.. _Kon: https://bitbucket.org/wampeter/kon\n.. _INI: https://en.wikipedia.org/wiki/INI_file\n.. _JSON: http://json.org\n.. _ConfigParser: https://docs.python.org/2/library/configparser.html\n.. _SafeConfigParser: https://docs.python.org/2/library/configparser.html#safeconfigparser-objects\n.. _int: https://docs.python.org/2/library/configparser.html#ConfigParser.RawConfigParser.getint>\n.. _float: https://docs.python.org/2/library/configparser.html#ConfigParser.RawConfigParser.getfloat>\n.. _boolean: https://docs.python.org/2/library/configparser.html#ConfigParser.RawConfigParser.getboolean\n.. _RawConfigParser: https://docs.python.org/2/library/configparser.html#ConfigParser.RawConfigParser\n.. _json.loads: https://docs.python.org/2.7/library/json.html#json.loads", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/wampeter/kon", "keywords": null, "license": "GNU GPL v3", "maintainer": null, "maintainer_email": null, "name": "kon", "package_url": "https://pypi.org/project/kon/", "platform": "any", "project_url": "https://pypi.org/project/kon/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://bitbucket.org/wampeter/kon" }, "release_url": "https://pypi.org/project/kon/0.0.1/", "requires_dist": null, "requires_python": null, "summary": "A configuration file(s) management library", "version": "0.0.1" }, "last_serial": 2937328, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "666a68edb313ebc88e0f6632a73bfc1d", "sha256": "f676660c07c1a89d6715e5de41c2c17d584f954a055e2a24a1f6102a10223a32" }, "downloads": -1, "filename": "kon-0.0.1.tar.gz", "has_sig": false, "md5_digest": "666a68edb313ebc88e0f6632a73bfc1d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14688, "upload_time": "2017-06-09T06:27:00", "url": "https://files.pythonhosted.org/packages/89/9e/c540dd1016fdc66cbb8e6cce36d664dc61e623ecefad631af768199e3556/kon-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "666a68edb313ebc88e0f6632a73bfc1d", "sha256": "f676660c07c1a89d6715e5de41c2c17d584f954a055e2a24a1f6102a10223a32" }, "downloads": -1, "filename": "kon-0.0.1.tar.gz", "has_sig": false, "md5_digest": "666a68edb313ebc88e0f6632a73bfc1d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14688, "upload_time": "2017-06-09T06:27:00", "url": "https://files.pythonhosted.org/packages/89/9e/c540dd1016fdc66cbb8e6cce36d664dc61e623ecefad631af768199e3556/kon-0.0.1.tar.gz" } ] }