{ "info": { "author": "Jelle Smet", "author_email": "development@smetj.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "======\nUplook\n======\n\nWhat?\n-----\n\nAn opinionated Python module to handle configuration values with support for\nexternal data sources.\n\nHow?\n----\n\nThe **UpLook** class takes an arbitrary number of key/values. These variables\nare stored and accessible as regular object attributes. Values of type\n<> can be accessed in dotted format.\n\nA value can also be a *lookup function* by using a special syntax:\n\n.. code-block:: text\n\n +-> The name of the funtion. 1 tilde means the function is a static lookup.\n | 2 tildes means a lookup is done every time the attribute is accessed.\n |\n | +------------+------> An optional pair of values. The first value is the \n | | | to lookup. The second value is a default value to return\n | | | in case the key lookup fails.\n ~~function(\"key\", \"default value\")\n |\n |\n +-> The default value can also be JSON. In that case you should not use\n quotes around the value.\n\n\nAn actual example would look like:\n\n.. code-block:: python\n\n >>>> u = UpLook(servers='~~consul(\"first\", [])')\n\n\nFor this to work you first need to register the function responsible for\nretrieving the data. Depending what is required to lookup the desired value\nyou could feed a value to the function.\n\nAn (silly) example lookup function looks like:\n\n.. code-block:: python\n\n def show_members(cluster_name):\n if cluster_name == \"first\"\n return [\"one\", \"two\", \"three\"]\n else:\n raise Exception(\"Unknown cluster\")\n\n >>>> u.registerLookup(\"consul\", show_members)\n\n\nAccessing value *u.value.server* will then trigger the the registered *lookup*\nfunction and return its value:\n\n.. code-block:: python\n\n >>>> u.value.servers\n [\"one\", \"two\", \"three\"]\n\n\nWhen the registered function return an Exception, the default value is returned:\n\n.. code-block:: python\n\n >>>> u = UpLook(servers='~~consul(\"blahblahblah\", [])')\n >>>> u.value.servers\n []\n\n\nRemarks\n-------\n\n- When executing the lookup function fails and a default value has been\n defined, no error is raised and the default value is returned.\n\n- When executing the lookup function fails and **no** default value has been\n defined an error is raised.\n\n- When the default value is between single or double quotes, it is returned\n literally. When the *default value* is **not** between quotes, it is\n considered to be JSON. When The JSON is invalid, an error is returned.\n\n\nMore examples\n-------------\n\nProvided kwargs are accessible as attributes\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n >>>> from uplook import UpLook\n >>>> u = UpLook(one=1, two=2)\n >>>> u\n UpLook({'two': 2, 'one': 1})\n >>>> u.value.one\n 1\n\n\n\nDict argument values are recursively mapped to attributes\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n >>>> from uplook import UpLook\n >>>> u = UpLook(levels = {\"level1\":{\"level2\":{\"level3\": \"hello\"}}})\n >>>> u\n UpLook({'levels': {'level1': {'level2': {'level3': 'hello'}}}})\n >>>> u.value.levels.level1.level2.level3\n 'hello'\n\n\n\nGet the data portion without all helper methods\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n >>>> from uplook import UpLook\n >>>> u = UpLook(one=1, two=2)\n >>>> u\n UpLook({'two': 2, 'one': 1})\n >>>> data = u.get()\n >>>> data.one\n 1\n\n\n\nGet a simple dict representation of the data\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n >>>> from uplook import UpLook\n >>>> u = UpLook(one=1, two=2)\n >>>> u\n UpLook({'two': 2, 'one': 1})\n >>>> data = u.dump()\n {'two': 2, 'one': 1}\n\n\n\nIterate over key/value pairs of a data container\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n >>>> from uplook import UpLook\n >>>> u = UpLook(one=1, two=2)\n >>>> u\n UpLook({'two': 2, 'one': 1})\n >>>> for key, value in u.get():\n .... print \"key: %s, value: %s\" % (key, value)\n ....\n key: two, value: 2\n key: one, value: 1\n\n\n\nExternal lookup values\n----------------------\n\nSome value lookup function\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n from uplook import UpLook\n from uplook.errors import NoSuchValue\n\n\n def someLookupFunction(key):\n data = {\"value.number.one\": \"hi\",\n \"value.number.two\": \"this\",\n \"value.number.three\": \"is\",\n \"value.number.four\": \"a\",\n \"value.number.five\": \"silly\",\n \"value.number.six\": \"demo\"\n }\n\n try:\n return data[key]\n except KeyError:\n raise NoSuchValue(\"%s is an unknown value.\" % (key))\n\n\n def randomInt(max):\n return random.randint(0, max)\n\n\n\n\nInitialize an Uplook instance with a dynamic and static lookup\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n >>> instance = UpLook(static='~fubar(\"value.number.one\", \"unknown\")',\n >>> dynamic='~~random(100)',\n >>> normal='hello')\n\n\n\n\nList all user defined lookup functions\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n >>> for function in instance.listfunctions():\n print function\n fubar\n random\n >>>\n\n\n\nRegister lookup functions\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n >>> instance.registerLookup(\"fubar\", someLookupFunction)\n >>> instance.registerLookup(\"random\", randomInt)\n\n\n\n\nAccess a static lookup value\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n >>> print test.value.static\n hi\n >>> print test.value.static\n hi\n\n\n\nAccess a dynamic lookup value\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n >>> print test.value.dynamic\n >>> 81\n >>> print test.value.dynamic\n >>> 16\n", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/smetj/uplook/tarball/master", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/smetj/uplook", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "uplook", "package_url": "https://pypi.org/project/uplook/", "platform": "Linux", "project_url": "https://pypi.org/project/uplook/", "project_urls": { "Download": "https://github.com/smetj/uplook/tarball/master", "Homepage": "https://github.com/smetj/uplook" }, "release_url": "https://pypi.org/project/uplook/1.1.1/", "requires_dist": null, "requires_python": "", "summary": "An opinionated Python module to handle configuration values with support for external data sources.", "version": "1.1.1" }, "last_serial": 2806896, "releases": { "0.4.1": [ { "comment_text": "", "digests": { "md5": "a27440526eea4afec7a3af875578c9a3", "sha256": "61fee4a3e4ac1bdd09c7b395cf826b1752dc3d97a943d6ef66a2ee4c8854b8f0" }, "downloads": -1, "filename": "uplook-0.4.1.tar.gz", "has_sig": false, "md5_digest": "a27440526eea4afec7a3af875578c9a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5688, "upload_time": "2015-12-05T20:08:19", "url": "https://files.pythonhosted.org/packages/42/5f/df871b081970cb745e5d59ffcef4b1e6266eb27d0f3f9395df56459650d6/uplook-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "e8a44542202ed666df03b51b3d74227c", "sha256": "d370c26a25ba59c4e8e2ad06f2e3c453c63cd3e44230005ec29054a92bbb28f0" }, "downloads": -1, "filename": "uplook-0.4.2.tar.gz", "has_sig": false, "md5_digest": "e8a44542202ed666df03b51b3d74227c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5642, "upload_time": "2016-03-30T21:26:11", "url": "https://files.pythonhosted.org/packages/72/bd/60a31252876ca9648271ba8baa974e51bf680ac7e1875a1f6a9c1f9b479f/uplook-0.4.2.tar.gz" } ], "0.4.3": [ { "comment_text": "", "digests": { "md5": "01c2cd0d287d7120ab13d67e304d703e", "sha256": "65396a5f9f1b86878301cc3e6603cc98a67a9216fd997c5bde7b229004356fea" }, "downloads": -1, "filename": "uplook-0.4.3.tar.gz", "has_sig": false, "md5_digest": "01c2cd0d287d7120ab13d67e304d703e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5661, "upload_time": "2016-04-11T19:01:12", "url": "https://files.pythonhosted.org/packages/27/1c/9535f112f62c5dea7284f321b8687f4afda2c468c312989703aab7121cf3/uplook-0.4.3.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "ef92833ac21696ac16996bb166af08cd", "sha256": "0a00fada497f926748bbbd4ea1c861da30774d5e065c13b7257d0368447c34eb" }, "downloads": -1, "filename": "uplook-1.0.0.tar.gz", "has_sig": false, "md5_digest": "ef92833ac21696ac16996bb166af08cd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5624, "upload_time": "2016-06-05T09:12:09", "url": "https://files.pythonhosted.org/packages/47/06/915b1a77478be8cdf97421cb7c053f209d3342b20e5fd2168a4dc2983143/uplook-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "de81123c81349642ae416269f48e34c9", "sha256": "59c2fa2d4a577ff21ca8174077875588e18b26cec51741e1eb9ce5191a898792" }, "downloads": -1, "filename": "uplook-1.1.0.tar.gz", "has_sig": false, "md5_digest": "de81123c81349642ae416269f48e34c9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6756, "upload_time": "2016-06-30T19:12:43", "url": "https://files.pythonhosted.org/packages/46/61/4adca1d92324f08062b91428ed151bfccad3f88b6b23f94b8cca36fe613e/uplook-1.1.0.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "96eec2087cd4f6180941ec4849d73b78", "sha256": "278bed5cece6014701a0991a039e5d2734d3bb3d9a045bbf588b5a9209501c17" }, "downloads": -1, "filename": "uplook-1.1.1.tar.gz", "has_sig": false, "md5_digest": "96eec2087cd4f6180941ec4849d73b78", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6767, "upload_time": "2017-04-16T13:27:03", "url": "https://files.pythonhosted.org/packages/07/d7/de5862fe00b251b642a2e632d4ba7c932271df174c37c3447b9e6f7a90d1/uplook-1.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "96eec2087cd4f6180941ec4849d73b78", "sha256": "278bed5cece6014701a0991a039e5d2734d3bb3d9a045bbf588b5a9209501c17" }, "downloads": -1, "filename": "uplook-1.1.1.tar.gz", "has_sig": false, "md5_digest": "96eec2087cd4f6180941ec4849d73b78", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6767, "upload_time": "2017-04-16T13:27:03", "url": "https://files.pythonhosted.org/packages/07/d7/de5862fe00b251b642a2e632d4ba7c932271df174c37c3447b9e6f7a90d1/uplook-1.1.1.tar.gz" } ] }