{ "info": { "author": "Mohamed Daif", "author_email": "mohamed@daif.me", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.4" ], "description": "Introduction\n============\n\nPython Rest Client exists to solve the common problem of consuming\nRESTful services.\n\nThe Problem\n===========\n\nIn an OOP language as Python, developers tend to think of their data as\nobjects and associated attributes and behaviors. When it comes to\nconsuming a RESTful service, you typically wrap the actual communication\nusing functions, methods or classes and spend some time to design your\nhandler(s). That typically results in repetitive and not-so-readable\ncode. Also different developers usually have different approaches on how\nto handle this issue. If you want to make sure you are passing the right\ndata types that would be a totally different story !\n\nThe Solution\n============\n\nPython Rest Client solves these issues by treating the RESTful endpoints\nas they should be ... endpoints to resources ! It lets you define your\nown resources like you do in Django models, by extending a class and\ndefining some attributes, and that's it ! You can have objects that\nhandles data type validation on attributes, define the endpoints once at\na single location, and the operations can be chained.\n\nQuick Start\n===========\n\nAfter you install Python Rest Client you can use it as following.\n\n::\n\n from rest_client import models # import models\n \n class Student(models.RestModel): # extend models.RestModel\n name = models.StringField()\n age = models.PositiveIntegerField()\n gpa = models.PositiveFloatField()\n\n class Meta: # An inner meta class is required to define endpoints\n post = \"http://shangri-la/students/\" # each entry should map to an HTTP action\n put = \"http://shangri-la/students/{id}\"\n delete = \"http://shangri-la/students/{id}\"\n get = \"http://shangri-la/classes/{class_id}/{student_id}\"\n\nAfter you define your resource and the endpoints you need, you can use\nthem as following ...\n\n::\n\n student = Student()\n student.post(name='Bob', age=27, gpa=3.6)\n\nIf you try to assign an attribute a wrong data type a TypeError will be\nraised\n\n::\n\n >>> student.post(name=7, age=27, gpa=3.6)\n\n::\n\n Traceback (most recent call last):\n ...\n TypeError: expected \n\nYou can format the endpoints at each request using the format method,\nwhich makes it very easy to follow the DRY principle and at the same\ntime dealing with multiple resources of the same type based on a\ndifferent id. For example if you need to get students with ids in range\n13 to 20 at a class with id 15 you can do the following ...\n\n::\n\n for i in range(13, 21):\n student = student.format(class_id=15, student_id=i).get()\n response = student.response\n\neach returned object from get, post, ...etc methods is a requests\nresponse object: http://docs.python-requests.org/en/latest/\n\nThe attributes are sent as query string unless you set the json\\_body\nargument at format method to be True, they will be sent as JSON body\nwith the proper header.\n\n::\n\n student.format(json_body=True, id=18).put(name='Alice', age=27, gpa=3.6)\n\nthe post, put, ... etc methods used in the examples are dynamically\ngenerated based on what you define in the inner Meta class, if you try\nto call an undefined action an AttributeError will be raised. You can\nfind additional examples in the tests directory.\n\nCurrently supported data types\n==============================\n\n- StringField\n- IntegerField\n- FloatField\n- ListField\n- PositiveIntegerField\n- PositiveFloatField", "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/mdaif/python-rest-model", "keywords": null, "license": "OSI Approved", "maintainer": null, "maintainer_email": null, "name": "python-rest-model", "package_url": "https://pypi.org/project/python-rest-model/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/python-rest-model/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/mdaif/python-rest-model" }, "release_url": "https://pypi.org/project/python-rest-model/1.0.2/", "requires_dist": null, "requires_python": null, "summary": "A standard way to consume a RESTful service, inspired by Django models", "version": "1.0.2" }, "last_serial": 1798697, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "987e54d58919ea05e3cb5affe6bba95b", "sha256": "7af595525b25984fce4e696d25f044475af55de366452cff8c99737ac3b63b36" }, "downloads": -1, "filename": "python-rest-model-1.0.tar.gz", "has_sig": false, "md5_digest": "987e54d58919ea05e3cb5affe6bba95b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5843, "upload_time": "2015-10-15T19:12:57", "url": "https://files.pythonhosted.org/packages/b6/f3/87cebc3f39395a6b64feb0756269050d25b8e44d853f3d7ce6277d3bf106/python-rest-model-1.0.tar.gz" } ], "1.0.1": [], "1.0.2": [] }, "urls": [] }