{ "info": { "author": "slorg1", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Topic :: Software Development :: Build Tools" ], "description": "# glyphs\n\n## Examples\nSample response JSON from an API call looks as follows. Let's assume for the example that we keep a reference to that dictionary.\n```python\nmy_json_dict = {\n 'expand': 'schema,names',\n 'issues':[\n {\n 'expand': 'operations,versionedRepresentations,editmeta,changelog,renderedFields',\n 'fields': {\n 'status': {\n 'description': '',\n 'id': '10001',\n 'name': 'Done',\n 'statusCategory': \n {\n 'colorName': 'green',\n 'id': 3,\n 'key': 'done',\n 'name': 'Done',\n }\n }\n },\n 'id': '10022',\n 'key': 'XXX-23'},\n {\n 'expand': 'operations,versionedRepresentations,editmeta,changelog,renderedFields',\n 'fields': {\n 'status': {\n 'description': '',\n 'id': '10001',\n 'name': 'Done',\n 'statusCategory': \n {\n 'colorName': 'green',\n 'id': 3,\n 'key': 'done',\n 'name': 'Done',\n }\n }\n },\n 'id': '10021',\n 'key': 'XXX-22'},\n ],\n 'maxResults': 50,\n 'startAt': 0,\n 'total': 17\n}\n```\n\nHow would you get the `status` & `statusCategory`'s `id` for each item of the \"issue\"?\n```python\n issues = my_json_dict['issues']\n\n if issues:\n # add a lot of code to check if the type returns worked for you\n # add a lot of code to handle exceptions\n\n for issue in issues:\n status_name = issue['fields']['status']['name']\n # add a lot of code to check if the type returned works for you\n # add a lot of code to handle exceptions\n # add a code convert the data or have the rest of your code handle unpredictable returns\n\n status_id = issue['fields']['status']['statusCategory']['id']\n # add a lot of code to check if the type returned works for you\n # add a lot of code to handle exceptions\n # add a code convert the data or have the rest of your code handle unpredictable returns\n\n```\nThis is the shortest you could possibly write it. Now you have to hope for the best from there, write a lot of\ncode to handle exception, data conversion etc.\n\nWith Glyphs:\n```python\n from glyphs.ro.ROGlyph import ROGlyph\n from glyphs.utils.DictUtils import DictUtils\n\n issues_glyph = ROGlyph('issues', r_translation_function=list, r_default_value=tuple())\n name_glyph = ROGlyph('fields>status>name', r_translation_function=unicode,)\n cat_id_glyph = ROGlyph('fields>statusCategory>id', r_translation_function=int, r_default_value=-1)\n\n issues = DictUtils.get(my_json_dict, issues_glyph)\n\n for issue in issues:\n status_name = DictUtils.get(my_json_dict, name_glyph)\n status_id = DictUtils.get(my_json_dict, cat_id_glyph)\n```\nSimilar code with a twist:\n1. we know that what we got is precisely what we wanted.\n2. simpler errors and missing data are automatically handled for us (with tasteful defaults)\n3. it also supports `functools.partial` if we want to make our code shorter\n4. the glyphs are infinitely shareable!! reuse and abuse!\n5. we can swap `DictUtils` with a different util (any that you want) if the type of `my_json_dict` changes\n(in later versions of the code) and everything will still work as we intended.\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/slorg1/glyphs", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "glyphs", "package_url": "https://pypi.org/project/glyphs/", "platform": "", "project_url": "https://pypi.org/project/glyphs/", "project_urls": { "Homepage": "https://github.com/slorg1/glyphs" }, "release_url": "https://pypi.org/project/glyphs/0.1.2/", "requires_dist": [ "six (>=1.10.0)" ], "requires_python": "", "summary": "Swiss army knife of data extraction", "version": "0.1.2" }, "last_serial": 5264007, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "bbae11c64fbfa72e16646675fd233d2a", "sha256": "421fed4b758402fbc62ae4e71c2f167b25471980a40d78213a2202263dd93226" }, "downloads": -1, "filename": "glyphs-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "bbae11c64fbfa72e16646675fd233d2a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12771, "upload_time": "2019-05-13T13:06:46", "url": "https://files.pythonhosted.org/packages/9e/a2/6be9ac072da086de4478dafda98656ead189ed055919d9629f21924a4443/glyphs-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "264a404e2c50b2da6792d017dbf37ffb", "sha256": "760eea3e28f1bc082009f55d0c92dbecf76485d9c2007de546cc681086a59cc0" }, "downloads": -1, "filename": "glyphs-0.1.tar.gz", "has_sig": false, "md5_digest": "264a404e2c50b2da6792d017dbf37ffb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7597, "upload_time": "2019-05-13T13:06:48", "url": "https://files.pythonhosted.org/packages/26/e5/32500b7e60ac64b65a07e96e42de77b6ae0b81721b8c6a3ad07bdd6aa8d3/glyphs-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "e055f62c2224b00d3b98d326654faaa5", "sha256": "eb757a80cead53718d30e5b7621aef4a574cf9c27eb90ac2ca8ced02e6557734" }, "downloads": -1, "filename": "glyphs-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "e055f62c2224b00d3b98d326654faaa5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14873, "upload_time": "2019-05-13T13:11:33", "url": "https://files.pythonhosted.org/packages/df/b5/c6fcfe5e466f82ec983193bf205313dd732e492466c0c26aeb9a59173bb4/glyphs-0.1.1-py3-none-any.whl" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "287c6c03414c2245372f3389897e4872", "sha256": "34face790a8e6683eb73690494ab261c30b0da6baf71a56c6694983fa4e16628" }, "downloads": -1, "filename": "glyphs-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "287c6c03414c2245372f3389897e4872", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17568, "upload_time": "2019-05-13T19:35:59", "url": "https://files.pythonhosted.org/packages/0c/94/222c9edc27b754e8aadfee29872b45a3f3b35d73cd1a16c968ff143ff8e7/glyphs-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "aeac5497534f2c6ffe463d82dea04ee6", "sha256": "9648dd8696888d8d618b34c3e5840e9d6a4fa6b843d96e520420c674f33a15d3" }, "downloads": -1, "filename": "glyphs-0.1.2.tar.gz", "has_sig": false, "md5_digest": "aeac5497534f2c6ffe463d82dea04ee6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12694, "upload_time": "2019-05-13T19:36:01", "url": "https://files.pythonhosted.org/packages/8a/8e/d73cf7360a7e55e8f8f7f362b1fdec7f767f0f4e3e457185dccb9b07ba91/glyphs-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "287c6c03414c2245372f3389897e4872", "sha256": "34face790a8e6683eb73690494ab261c30b0da6baf71a56c6694983fa4e16628" }, "downloads": -1, "filename": "glyphs-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "287c6c03414c2245372f3389897e4872", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 17568, "upload_time": "2019-05-13T19:35:59", "url": "https://files.pythonhosted.org/packages/0c/94/222c9edc27b754e8aadfee29872b45a3f3b35d73cd1a16c968ff143ff8e7/glyphs-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "aeac5497534f2c6ffe463d82dea04ee6", "sha256": "9648dd8696888d8d618b34c3e5840e9d6a4fa6b843d96e520420c674f33a15d3" }, "downloads": -1, "filename": "glyphs-0.1.2.tar.gz", "has_sig": false, "md5_digest": "aeac5497534f2c6ffe463d82dea04ee6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12694, "upload_time": "2019-05-13T19:36:01", "url": "https://files.pythonhosted.org/packages/8a/8e/d73cf7360a7e55e8f8f7f362b1fdec7f767f0f4e3e457185dccb9b07ba91/glyphs-0.1.2.tar.gz" } ] }