{ "info": { "author": "Tim-Christian Mundt", "author_email": "dev@tim-erwin.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "# python-jsonapi-datastore\n\nClient-side [JSON API](http://jsonapi.org) data handling made easy. This is a re-write of Lucas Hosseini's [JavaScript jsonapi-datastore](https://github.com/beauby/jsonapi-datastore/) for Python. The serialization is not included yet. If you need it feel free to open a PR or ask for it.\n\n## Description\n\nThe [JSONAPI](http://jsonapi.org) standard is great for exchanging data (which is its purpose), but the format is not ideal to work directly within an application.\npython-jsonapi-datastore is a framework-agnostic library that takes away the burden of handling [JSONAPI](http://jsonapi.org) data on the client side.\n\nWhat it does:\n- read JSONAPI payloads,\n- rebuild the underlying data graph,\n- allows you to query models and access their relationships directly,\n- create new models.\n\nWhat it does not do:\n- make requests to your API. You design your endpoints URLs, the way you handle authentication, caching, etc. is totally up to you.\n\n## Installing\n\nInstall python-jsonapi-datastore with `pip` as usual:\n\n pip install jsonapi-datastore\n\nThis library has no 3rd-party dependencies.\n\n## Parsing data\n\nJust call the `.sync()` method of your store.\n```python\nstore = JsonApiDataStore()\nstore.sync(data)\n```\nThis parses the data and incorporates it in the store, taking care of already existing records (by updating them) and relationships.\n\n## Parsing with meta data\n\nIf you have meta data in your payload use the `.syncWithMeta` method of your store.\n```python\nstore = JsonApiDataStore()\nstore.syncWithMeta(data)\n```\nThis does everything that `.sync()` does, but returns an object with data and meta split.\n\n## Retrieving models\n\nJust call the `.find(type, id)` method of your store.\n```python\narticle = store.find('article', 123)\n```\nor call the `.findAll(type)` method of your store to get all the models of that type.\n```python\narticles = store.findAll('article')\n```\nAll the attributes *and* relationships are accessible through the model as object properties.\n```python\nprint(article.author.name)\n```\nIn case a related resource has not been fetched yet (either as a primary resource or as an included resource), the corresponding property on the model will contain only the `type` and `id` (and the `._placeHolder` property will be set to `true`). However, the models are *updated in place*, so you can fetch a related resource later, and your data will remain consistent.\n\n## Examples\n\n```python\n# Create a store:\nstore = JsonApiDataStore()\n\n# Then, given the following payload, containing two `articles`, with a related `user` who is the author of both:\npayload = {\n 'data': [{\n 'type': 'article',\n 'id': 1337,\n 'attributes': {\n 'title': 'Cool article'\n },\n 'relationships': {\n 'author': {\n 'data': {\n 'type': 'user',\n 'id': 1\n }\n }\n }\n },\n {\n 'type': 'article',\n 'id': 300,\n 'attributes': {\n 'title': 'Even cooler article'\n },\n 'relationships': {\n 'author': {\n 'data': {\n 'type': 'user',\n 'id': 1\n }\n }\n }\n }]\n}\n\n# we can sync it:\narticles = store.sync(payload)\n\n# which will return the list of synced articles.\n\n# Later, we can retrieve one of those:\narticle = store.find('article', 1337)\n\n# If the author resource has not been synced yet, we can only access its id and its type:\nprint(article.author)\n# { id: 1, _type: 'article' }\n\n# If we do sync the author resource later:\nauthorPayload = {\n 'data': {\n 'type': 'user',\n 'id': 1,\n 'attributes': {\n 'name': 'Lucas'\n }\n }\n}\n\nstore.sync(authorPayload)\n\n# we can then access the author's name through our old `article` reference:\nprint(article.author.name)\n# 'Lucas'\n\n```\n\n## What's missing\n\nCurrently, the store does not handle `links` attributes or resource-level or relationship-level meta.\n\n## Contributing\n\nPull-requests welcome!", "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/Tim-Erwin/python-jsonapi-datastore", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "jsonapi-datastore", "package_url": "https://pypi.org/project/jsonapi-datastore/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/jsonapi-datastore/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/Tim-Erwin/python-jsonapi-datastore" }, "release_url": "https://pypi.org/project/jsonapi-datastore/0.1.2/", "requires_dist": null, "requires_python": null, "summary": "A lightweight library handling structured JSONAPI responses.", "version": "0.1.2" }, "last_serial": 2329716, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "876938ed69f1ad40f5afc354e307a13f", "sha256": "dfba54f39d6a4912bd91c86ea18d0bad8940a5e728b52ad4ac37d4aa564ac4f9" }, "downloads": -1, "filename": "jsonapi-datastore-0.1.0.tar.gz", "has_sig": false, "md5_digest": "876938ed69f1ad40f5afc354e307a13f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4700, "upload_time": "2016-09-07T15:02:11", "url": "https://files.pythonhosted.org/packages/0b/e3/e05bb2a0b961e98d712da599362bf6367148a51fcf08949a3c5cef525188/jsonapi-datastore-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "66a40a8f0f6806b785c6c10f46d638cf", "sha256": "5462930ec9a05d76f50ab8289d465dd827c407788f802e4e47bc4ff8de247543" }, "downloads": -1, "filename": "jsonapi-datastore-0.1.1.tar.gz", "has_sig": false, "md5_digest": "66a40a8f0f6806b785c6c10f46d638cf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4060, "upload_time": "2016-09-07T15:27:45", "url": "https://files.pythonhosted.org/packages/86/a4/16cf982599053819564b9e521585a099fbfc52fd5b7dbd1a6e768afaa589/jsonapi-datastore-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "84ecee88648ad1b9fae059058155c18c", "sha256": "d4d91a345796ff464049dddc084803e8d2304b5e7501dc010a2d1fed6e28540b" }, "downloads": -1, "filename": "jsonapi-datastore-0.1.2.tar.gz", "has_sig": false, "md5_digest": "84ecee88648ad1b9fae059058155c18c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5145, "upload_time": "2016-09-07T15:41:29", "url": "https://files.pythonhosted.org/packages/ab/b5/2511a8fce368e834b652dcb626c11414552418b62f19dd07b66dfb978315/jsonapi-datastore-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "84ecee88648ad1b9fae059058155c18c", "sha256": "d4d91a345796ff464049dddc084803e8d2304b5e7501dc010a2d1fed6e28540b" }, "downloads": -1, "filename": "jsonapi-datastore-0.1.2.tar.gz", "has_sig": false, "md5_digest": "84ecee88648ad1b9fae059058155c18c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5145, "upload_time": "2016-09-07T15:41:29", "url": "https://files.pythonhosted.org/packages/ab/b5/2511a8fce368e834b652dcb626c11414552418b62f19dd07b66dfb978315/jsonapi-datastore-0.1.2.tar.gz" } ] }