{ "info": { "author": "Yuan Shi", "author_email": "shiyuan404@hotmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "thrift_converter\n============\n\nA python implemented tool for converting between json and thrift.\n\n\nInstall\n------------\n\n```bash\npip install thrift-converter\n```\n\n\nWhy build this tool:\n------------\n\n1. Class in thrift gen-py use `thrift_spec()` to deserialize, but the `Enum` object is simply treated as `I32`, while in json, it's stored as string of name. \n2. `set` is not json serializable in standard json, we can treat `{'a', 'b', ..}` as `{None: ['a', 'b', ...]}` for distinction.\n\n\nHow to:\n-----------\n1. Parsing thrift ast by [ptsd](https://github.com/wickman/ptsd)\n2. Deserializing thrift object by walking through ast recursively.\n\n\nTodo:\n-----------\n- [ ] learn `ply` from [ptsd](https://github.com/wickman/ptsd)\n\n\nOthers\n-----------\n\n* [introspection-of-thrift-enums-in-python](https://grokbase.com/t/thrift/user/13614a6xd1/introspection-of-thrift-enums-in-python) discussed end with waiting for thrift upgrade(support for python enums)\n* [thrift_json_decoder in twitter.common](https://github.com/twitter/commons/blob/master/src/python/twitter/thrift/text/thrift_json_decoder.py) can't handle with Enum\n* [thrift_json_convertor based on thriftpy](https://github.com/xuanyuanking/thrift_json_convertor) too heavy\n\n\nUsage\n------------\nexample: [demo](https://github.com/shiyuan/thrift_converter/blob/master/test/')\n\n```py\nimport json\nfrom thrift_converter import JsonThriftConverter, ThriftJsonConverter\n\nthrift_file = 'demo.thrift'\nobject_name = 'Group'\n\njson2thrift = JsonThriftConverter(thrift_file).convert\nthrift2json = ThriftJsonConverter(thrift_file).convert\n\nobj = gen_fake_obj()\n# Group(id=-1, worker_map={999: Worker(id=999, tasks=[Task(id=727, status=0, action=888, valid=True, msgs={'msg'})])})\n\njs = thrift2json(obj, object_name)\njs_str = json.dumps(js)\n# {\"id\": -1, \"worker_map\": {\"999\": {\"id\": 999, \"tasks\": [{\"id\": 727, \"status\": 0, \"action\": \"UP\", \"valid\": true, \"msgs\": {\"null\": [\"msg\"]}}]}}}\n\nobj = json2thrift(json.loads(js_str), object_name)\n# Group(id=-1, worker_map={999: Worker(id=999, tasks=[Task(id=727, status=0, action=888, valid=True, msgs={'msg'})])})\n\n```\n\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/shiyuan/thrift_converter", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "thrift-converter", "package_url": "https://pypi.org/project/thrift-converter/", "platform": "", "project_url": "https://pypi.org/project/thrift-converter/", "project_urls": { "Homepage": "https://github.com/shiyuan/thrift_converter" }, "release_url": "https://pypi.org/project/thrift-converter/0.0.1/", "requires_dist": [ "ptsd (>=0.1.0)" ], "requires_python": "", "summary": "Thrift converting tools: json2thrift, thrift2json", "version": "0.0.1" }, "last_serial": 4753512, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "50790323b063f5a8e3ed240c63af4521", "sha256": "c846d16cb4d29cf46020a8719d62346dd40ad9525e6c70b2027dd84c6f07046a" }, "downloads": -1, "filename": "thrift_converter-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "50790323b063f5a8e3ed240c63af4521", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5569, "upload_time": "2019-01-29T07:16:52", "url": "https://files.pythonhosted.org/packages/23/99/395eddb0e8c57dd778b924325f11e193b4f6bd5f0cf953593474f36c0b25/thrift_converter-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f04dbe6e2722ad33b6f6db6d6f323e68", "sha256": "7beb4a680cfa1544a5c904a0bbfd353700d35317bef72b2f8a186992f20a07ad" }, "downloads": -1, "filename": "thrift_converter-0.0.1.tar.gz", "has_sig": false, "md5_digest": "f04dbe6e2722ad33b6f6db6d6f323e68", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3373, "upload_time": "2019-01-29T07:16:57", "url": "https://files.pythonhosted.org/packages/5f/22/1709755faccf79ca22643927471c67b63e68a836d28eeaed169c83b9b56b/thrift_converter-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "50790323b063f5a8e3ed240c63af4521", "sha256": "c846d16cb4d29cf46020a8719d62346dd40ad9525e6c70b2027dd84c6f07046a" }, "downloads": -1, "filename": "thrift_converter-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "50790323b063f5a8e3ed240c63af4521", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5569, "upload_time": "2019-01-29T07:16:52", "url": "https://files.pythonhosted.org/packages/23/99/395eddb0e8c57dd778b924325f11e193b4f6bd5f0cf953593474f36c0b25/thrift_converter-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f04dbe6e2722ad33b6f6db6d6f323e68", "sha256": "7beb4a680cfa1544a5c904a0bbfd353700d35317bef72b2f8a186992f20a07ad" }, "downloads": -1, "filename": "thrift_converter-0.0.1.tar.gz", "has_sig": false, "md5_digest": "f04dbe6e2722ad33b6f6db6d6f323e68", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3373, "upload_time": "2019-01-29T07:16:57", "url": "https://files.pythonhosted.org/packages/5f/22/1709755faccf79ca22643927471c67b63e68a836d28eeaed169c83b9b56b/thrift_converter-0.0.1.tar.gz" } ] }