{ "info": { "author": "Joakim Ekberg", "author_email": "jocke.ekberg@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "Hyp\n===\nJSON-API responses in Python.\n\nAbout\n-----\nHyp is a library implementing the _must_ parts of the [JSON-API](http://jsonapi.org) response specification. This means that you can use Hyp to serialize your models into responses that contain links and linked compound documents. It works really good in combination with your micro web framework of choice, preferably [Flask](http://flask.pocoo.org).\n\nIt has built in support for both [Schematics](https://schematics.readthedocs.org/) and [Marshmallow](http://marshmallow.readthedocs.org) in the sense that you can use any of them for serializing your models (or primitives) into JSON that Hyp creates responses from. To add support for more data serialization libraries such as [Colander](http://docs.pylonsproject.org/projects/colander/en/latest/) should be trivial though.\n\nTutorial\n--------\nFirst let's define some serializers for your models:\n\n```python\nfrom marshmallow import Serializer, fields\n\n\nclass CommentSerializer(Serializer):\n id = fields.Integer()\n content = fields.String()\n\n\nclass PersonSerializer(Serializer):\n id = fields.Integer()\n name = fields.String()\n\n\nclass PostSerializer(Serializer):\n id = fields.Integer()\n title = fields.String()\n```\n\nWe can then create our own responders using the `hyp.Responders` class:\n\n```python\nfrom hyp.responder import Responder\n\n\nclass CommentResponder(Responder):\n TYPE = 'comment'\n SERIALIZER = CommentSerializer\n\n\nclass PersonResponder(Responder):\n TYPE = 'person'\n SERIALIZER = PersonSerializer\n\n\nclass PostResponder(Responder):\n TYPE = 'post'\n SERIALIZER = PostSerializer\n LINKS = {\n 'comments': {\n 'responder': CommentResponder(),\n 'href': 'http://example.com/comments/{posts.comments}',\n },\n 'author': {\n 'responder': PersonResponder(),\n 'href': 'http://example.com/people/{posts.author}',\n },\n }\n```\n\nFinally we can use our responders for creating responses. These responses goes perfectly into any Flask application out there:\n\n```python\npost = {\n 'id': 1,\n 'title': 'My post',\n 'comments': [\n {'id': 1, 'content': 'A comment'},\n {'id': 2, 'content': 'Another comment'},\n ]\n}\n\njson = PostResponder.respond(post, linked={'comments': post['comments']})\n\n```\n\nThe `json` variable will now contain some freshly squeezed JSON ready for sending back to the client:\n\n```json\n{\n \"posts\": [\n {\n \"id\": 1,\n \"title\": \"My title\",\n \"links\": {\n \"comments\": [1, 2]\n }\n }\n ],\n \"linked\": {\n \"comments\": [\n {\n \"id\": 1,\n \"content\": \"My comment\"\n },\n {\n \"id\": 2,\n \"content\": \"Another comment\"\n }\n ]\n },\n \"links\": {\n \"posts.comments\": {\n \"type\": \"comments\",\n \"href\": \"http://example.com/comments/{posts.comments}\"\n }\n }\n}\n```\n\nIf you'd like to get have dict returned instead of json, for example if you want to use flask's [jsonify](http://flask.pocoo.org/docs/api/#flask.json.jsonify), then you can use the `build` method instead like so:\n\n```python\npost = {\n 'id': 1,\n 'title': 'My post',\n 'comments': [\n {'id': 1, 'content': 'A comment'},\n {'id': 2, 'content': 'Another comment'},\n ]\n}\n\nresponse = PostResponder.build(post, linked={'comments': post['comments']})\njson = flask.jsonify(response)\n```", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/kalasjocke/hyp", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "hyp", "package_url": "https://pypi.org/project/hyp/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/hyp/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/kalasjocke/hyp" }, "release_url": "https://pypi.org/project/hyp/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "Partial JSON API implementation in Python on top of Schematics", "version": "1.0.0" }, "last_serial": 1283965, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "0e1b9b60f3b4812006a050ac3a1ef083", "sha256": "3a1ed0b37176526ea964eb6f9088ba01ac829c1c971f8aad8e7894af444dd54e" }, "downloads": -1, "filename": "hyp-0.1.0.tar.gz", "has_sig": false, "md5_digest": "0e1b9b60f3b4812006a050ac3a1ef083", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3240, "upload_time": "2014-02-12T13:40:48", "url": "https://files.pythonhosted.org/packages/fd/ba/90c61138a2c5344e4cbccc493f39812b9495f15315f98b07ad29c4f909a3/hyp-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "a2e3708b3d411ce0871b8478643ea811", "sha256": "863d9f61d652761d33044670b119192f92b09c56a5af25dbc238936975e98995" }, "downloads": -1, "filename": "hyp-0.1.1.tar.gz", "has_sig": false, "md5_digest": "a2e3708b3d411ce0871b8478643ea811", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3271, "upload_time": "2014-02-12T13:45:29", "url": "https://files.pythonhosted.org/packages/d5/cf/54e9cfdde36588e32678d53f3caa4caf95c1996acef6f730c63728833dd4/hyp-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "bb7c67881f2dd92c518bfac9ee986bf3", "sha256": "d2029b99d763bde05bd00237fe063a9b2061af5a75804ccf7bb9401436a0d644" }, "downloads": -1, "filename": "hyp-0.1.2.tar.gz", "has_sig": false, "md5_digest": "bb7c67881f2dd92c518bfac9ee986bf3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3267, "upload_time": "2014-02-12T15:09:18", "url": "https://files.pythonhosted.org/packages/3a/e1/7cf927ee311273046d9ac24de7c17f5bf2c9e63347084de1b48d67f1886f/hyp-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "2abe5b94db31eb7386a3464ca42a728c", "sha256": "9ba99aa5b7b01a84134b1d713d095a701b8451c70e7f4c712d6a94769c5575f9" }, "downloads": -1, "filename": "hyp-0.1.3.tar.gz", "has_sig": false, "md5_digest": "2abe5b94db31eb7386a3464ca42a728c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3245, "upload_time": "2014-02-14T08:40:35", "url": "https://files.pythonhosted.org/packages/be/99/25cda22303d88439493907f8ca43f2d6eefad092c237f2e7d347b82ad577/hyp-0.1.3.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "b5d82423c5c3d160621ab3a206bc934f", "sha256": "0998cd73270ce1bac027383632700edb6ed9060b85fe3861eaadfbc52fe57448" }, "downloads": -1, "filename": "hyp-0.2.0.tar.gz", "has_sig": false, "md5_digest": "b5d82423c5c3d160621ab3a206bc934f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3305, "upload_time": "2014-02-16T20:31:09", "url": "https://files.pythonhosted.org/packages/29/a6/9a15f09e7faaf10b1c4a4bb02ad66aac86c1803d85b90ca949810c31d0a5/hyp-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "d85a7afdbbacb51f328e6103d8140779", "sha256": "d91b0f4986065deedd238c4103288d73ec4a581b5d320fe3c15b6ead21633434" }, "downloads": -1, "filename": "hyp-0.2.1.tar.gz", "has_sig": false, "md5_digest": "d85a7afdbbacb51f328e6103d8140779", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3395, "upload_time": "2014-02-16T21:34:33", "url": "https://files.pythonhosted.org/packages/6d/85/ae4783898932518a5d1b5e7c4d5634f1c59927f79a82268ef8567247f291/hyp-0.2.1.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "db9f8a58c7233ac46ef8ce443a395bf2", "sha256": "71b6b4745087650662a4f54969fd5e31bf01461c50e9efa4e999aa39115df00b" }, "downloads": -1, "filename": "hyp-0.3.0.tar.gz", "has_sig": false, "md5_digest": "db9f8a58c7233ac46ef8ce443a395bf2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3416, "upload_time": "2014-04-10T08:46:05", "url": "https://files.pythonhosted.org/packages/d8/a3/0877c603cbb30cbba9d7250afe203ea9a1bdb58239d47e189724f4d681e3/hyp-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "c042ffa57d3d8a30d887b14619a927d7", "sha256": "50b31c7bc7721be3a5734d512ecff88950243744d58884a9011aec13db44e435" }, "downloads": -1, "filename": "hyp-0.3.1.tar.gz", "has_sig": false, "md5_digest": "c042ffa57d3d8a30d887b14619a927d7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3486, "upload_time": "2014-04-24T12:25:03", "url": "https://files.pythonhosted.org/packages/cc/9a/5686b91a4769313767598010631581a4e88147e96fcb92affda3dc74fcf8/hyp-0.3.1.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "61c375264cfa35913d37cc9ddb31bdbb", "sha256": "e342f4c4650732516f5f2d82da221e373fb26445f9a87e5fdcf4078012f84d20" }, "downloads": -1, "filename": "hyp-0.4.0.tar.gz", "has_sig": false, "md5_digest": "61c375264cfa35913d37cc9ddb31bdbb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3679, "upload_time": "2014-08-01T08:10:48", "url": "https://files.pythonhosted.org/packages/36/ba/3076b3c90afbeb39c48312c38eeb0ef4f5bb79bce73f8aa78a1bbde821d7/hyp-0.4.0.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "85a28c74e69af0006f8328a6311fcf16", "sha256": "8d49809bb715251b41b4840531e6b773ebb5197396250c8b392e2ecf9554d090" }, "downloads": -1, "filename": "hyp-0.5.0.tar.gz", "has_sig": false, "md5_digest": "85a28c74e69af0006f8328a6311fcf16", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3669, "upload_time": "2014-09-05T14:09:11", "url": "https://files.pythonhosted.org/packages/15/95/5b0ae93844e07353a83abc3e2f7966da4eec1430fc2d4e1e41300f269105/hyp-0.5.0.tar.gz" } ], "0.6.0": [ { "comment_text": "", "digests": { "md5": "94d1b9d0fd44addf4e980ddb3963a9e1", "sha256": "c442b86013bd1ebdbc79c2c2aa3fe1621a84b54cac2b50f52f5f2ed34ea6e451" }, "downloads": -1, "filename": "hyp-0.6.0.tar.gz", "has_sig": false, "md5_digest": "94d1b9d0fd44addf4e980ddb3963a9e1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4233, "upload_time": "2014-10-27T07:59:44", "url": "https://files.pythonhosted.org/packages/83/25/fc594667a30d5f689cdb42e79f2b4fe602cc751946e08c9ef15c40fc97db/hyp-0.6.0.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "a86281d94c76fbf08f65e3ebee24183e", "sha256": "4bdf1f3af1bb20ca621cc5fa21b79c048f5aad39280c14c81d2402efebad54aa" }, "downloads": -1, "filename": "hyp-1.0.0.tar.gz", "has_sig": false, "md5_digest": "a86281d94c76fbf08f65e3ebee24183e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3612, "upload_time": "2014-09-02T11:21:22", "url": "https://files.pythonhosted.org/packages/e6/a4/c279db9d2c1ba8fa04e7dd612d3cdb16bfa6161976549856e819a71dd33d/hyp-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a86281d94c76fbf08f65e3ebee24183e", "sha256": "4bdf1f3af1bb20ca621cc5fa21b79c048f5aad39280c14c81d2402efebad54aa" }, "downloads": -1, "filename": "hyp-1.0.0.tar.gz", "has_sig": false, "md5_digest": "a86281d94c76fbf08f65e3ebee24183e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3612, "upload_time": "2014-09-02T11:21:22", "url": "https://files.pythonhosted.org/packages/e6/a4/c279db9d2c1ba8fa04e7dd612d3cdb16bfa6161976549856e819a71dd33d/hyp-1.0.0.tar.gz" } ] }