{ "info": { "author": "Michal Vlas\u00e1k", "author_email": "daeatel@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# puREST\n\n\npuREST is a dead simple Python REST consumer based on [`requests`](http://docs.python-requests.org/en/master/) aiming for the simplest possible use while keeping all of the [`requests`](http://docs.python-requests.org/en/master/) features.\n\n``` python\nfrom purest import jsonplaceholder_typicode_com as api\n\nposts = api.posts()\narticle = api.posts[1]()\ncomments = api.posts[1].comments()\n```\n\n# Installation\n\n``` python \npip install purest\n```\n\n# Basic usage\n\nThere are two main parts of puREST library. First one is concerned with the creation of puREST resources.\n\n## Creating a puREST resource\n\npuREST resource is a tiny wrapper above the [`requests`](http://docs.python-requests.org/en/master/) module. It provides magic methods for simpler and more straightforward use of REST endpoints.\n\nAs a first thing, you need to create the puREST resource. You can do it either directly or from an already existing puREST resource.\n\n### Direct method\n\nThe most basic way of defining a puREST resource is creating a new instance of `Purest` class. You have to pass the desired URL to its constructor.\n\n(I will demonstrate the library usage on the great [JSONPlaceholder website](https://jsonplaceholder.typicode.com/) where applicable)\n\n``` python\nfrom purest import Purest\n\napi = Purest(\"https://jsonplaceholder.typicode.com/\")\n```\n\nIn addition to this method, you can even create the `Purest` resource right during the import from `purest` module. To do this, you have to import the camelCase name of URL from `purest`.\n\n``` python\nfrom purest import jsonplaceholder_typicode_com as api\n```\n\nThe name you want to import is then transformed:\n\n1) dot (`.`) is placed before each capital letter\n2) string is converted to lowercase\n3) `https://` is prepended\n4) resulting string is used as an argument for `Purest` constructor\n\n### Creating puREST object from another puREST object\n\nIf you already have a `Purest` instance pointing to some REST endpoint, it would be unpleasant to create new `Purest` resource for each other sub-endpoint on that site.\n\nFor that reason, you can easily create a new `Purest` object from any existing `Purest` object. It can be achieved either by getting its attribute or by getting its item.\n\n``` python\nfrom purest import jsonplaceholder_typicode_com as api\n\nposts_url = api.posts\n# equivalent to\nposts_url = api['posts']\n```\n\nThis also works for individual items of REST collections\n\n``` python\nfrom purest import jsonplaceholder_typicode_com as api\n\narticle)url = api.posts[1]\n# equivalent to\narticle_url = api['posts'][1]\n```\n\n## Getting the puREST resource content\n\nOnce you have the `Purest` instance pointing to the desired endpoint, you can easily obtain its content by calling it.\n\nAs stated earlier, `Purest` is a [`requests`](http://docs.python-requests.org/en/master/) wrapper so you can also use the ordinary [`requests.get`](http://docs.python-requests.org/en/master/api/#requests.get) and the string you pass to that call will be appended to the URL the `Purest` object is pointing to.\n\n``` python\nfrom purest import jsonplaceholder_typicode_com as api\n\nposts = api.posts()\n# equivalent to\nposts = api['posts']()\n# equivalent to\nposts = api.get('posts')\n\narticle = api.posts[1]()\n# equivalent to\narticle = api.['posts'][1]()\n```\n\n# Advanced usage\n\nFor the simplest usage of REST possible, puREST makes some assumptions about the data obtained from the provided URLs.\n\nBy default, after GETting the response, it transforms it to JSON by [`requests.json()`](http://docs.python-requests.org/en/master/api/#requests.Response.json) method.\n\nBy default, all dictionaries in the response are enhanced with magic methods so that you can acces the dictionary items as if they would be attributes. This is done recursively (for embedded dictionaries as well). This behavior can be disabled by setting `transform_dict` to `False` in `Purest` constructor.\n\n``` python\nfrom purest import jsonplaceholder_typicode_com as api\n\narticle = api.posts[1]()\n\nprint article['id']\n# equivalent to\nprint article.id\n```\n\n# Tests\n\n```python setup.py test```", "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/vlasy/purest", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "puREST", "package_url": "https://pypi.org/project/puREST/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/puREST/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/vlasy/purest" }, "release_url": "https://pypi.org/project/puREST/0.0.2/", "requires_dist": null, "requires_python": null, "summary": "Simple dynamic REST consumer", "version": "0.0.2" }, "last_serial": 2479279, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "29742bbe799f79d72aca232dba959f79", "sha256": "0fca081bc6186e5ec6b381343e248a3a78846cc7d6fb99446063dcd0bb291ddb" }, "downloads": -1, "filename": "puREST-0.0.1.tar.gz", "has_sig": false, "md5_digest": "29742bbe799f79d72aca232dba959f79", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1513, "upload_time": "2016-11-22T20:49:01", "url": "https://files.pythonhosted.org/packages/7b/95/58e56b5bdac00770bfd5f7d8fa5d0b353a7a85b9d7ecc6616a1ca02783f5/puREST-0.0.1.tar.gz" } ], "0.0.1.post1": [ { "comment_text": "", "digests": { "md5": "815875b1f688b927df6869ae8839370c", "sha256": "cf30ac2f154b7081a0b3011e2320c84d40e77f48bbd3feee68318633803df67c" }, "downloads": -1, "filename": "puREST-0.0.1.post1.tar.gz", "has_sig": false, "md5_digest": "815875b1f688b927df6869ae8839370c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3215, "upload_time": "2016-11-22T21:01:37", "url": "https://files.pythonhosted.org/packages/4d/72/ec2c2d049e6f2d37652afa11c60842fcca6686ca02ca68ad8cdf5fb91665/puREST-0.0.1.post1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "bb390e202fe6760dbf7760ed0abb97e5", "sha256": "2f1f8ea401443439a8d2eca601adea08b4a865ab5f63b17b0fc249ad7854fe26" }, "downloads": -1, "filename": "puREST-0.0.2.tar.gz", "has_sig": false, "md5_digest": "bb390e202fe6760dbf7760ed0abb97e5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3183, "upload_time": "2016-11-23T17:34:19", "url": "https://files.pythonhosted.org/packages/71/f5/910231dc7524b4ccc0e719484028a324fd4f22eb8a95d3214bdc09751fc4/puREST-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bb390e202fe6760dbf7760ed0abb97e5", "sha256": "2f1f8ea401443439a8d2eca601adea08b4a865ab5f63b17b0fc249ad7854fe26" }, "downloads": -1, "filename": "puREST-0.0.2.tar.gz", "has_sig": false, "md5_digest": "bb390e202fe6760dbf7760ed0abb97e5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3183, "upload_time": "2016-11-23T17:34:19", "url": "https://files.pythonhosted.org/packages/71/f5/910231dc7524b4ccc0e719484028a324fd4f22eb8a95d3214bdc09751fc4/puREST-0.0.2.tar.gz" } ] }