{ "info": { "author": "Cyril Panshine", "author_email": "kipanshi@gmail.com", "bugtrack_url": null, "classifiers": [ "Framework :: Pyramid", "Programming Language :: Python", "Programming Language :: Python :: 2", "Topic :: Internet :: WWW/HTTP" ], "description": "============\npyramid_skue\n============\n\n``pyramid_skue`` is a library for builidn REST API services on top of `Pyramid`_ framework.\n\n.. _`Pyramid`: http://www.pylonsproject.org/\n\n\nInstallation\n------------\nRequires Pyramid >= 1.5a2\n\nInstall with pip::\n\n pip install pyramid_skue\n\nor using ``easy_install``::\n\n easy_install pyramid_skue\n\n\nUsage\n-----\n\nCreate ``api`` python package inside your main project package.\n\nPopulate ``api/resourses.py`` with the defenition of resource::\n\n from pyramid_skue.rest.api import ResourceDescription\n from pyramid_skue.rest.api import HttpMethodDescription\n from pyramid_skue.rest.api import HttpParameterDescription\n from pyramid_skue.http import CommonResponse\n from pyramid_skue.rest.resources import DocumentResource\n from .response import MessageResourceJson\n\n class MessageResource(DocumentResource):\n \"\"\"Represents resource for readin/creating messages.\"\"\"\n\n # Resource definition\n def describe_resource(self):\n \"\"\"Self description.\n\n \"\"\"\n description = 'Author of the message'\n author_param = HttpParameterDescription(\n 'author', 'string', is_required=True,\n description=description)\n\n description = 'Title of the message'\n title_param = HttpParameterDescription(\n 'title', 'string', is_required=True,\n description=description)\n\n description = 'Title of the message (optional)'\n title_optional_param = HttpParameterDescription(\n 'title', 'string', is_required=False,\n description=description)\n\n description = 'Message body'\n body_param = HttpParameterDescription(\n 'body', 'string', is_required=True,\n description=description)\n\n description = \"Get existing messages\"\n get_method = HttpMethodDescription(\n 'GET', parameters=[title_optional_param],\n description=description)\n\n description = \"Post message\"\n post_method = HttpMethodDescription(\n 'POST', parameters=[author_param, title_param, body_param],\n description=description)\n\n description = \"Create/Get messages\"\n resource = ResourceDescription(\n 'MessageResource', url=\"/api/message\",\n methods=[get_method, post_method],\n description=description)\n return resource\n\n def read_resource(self):\n \"\"\"\n Return messages. Can be filtered by title.\n Assuming that ``storage`` is some database you're using.\n\n \"\"\"\n title = self.payload.get('title')\n if title:\n messages = storage.filter(title).all()\n else:\n messages = storage.all()\n\n body = MessageResourceJson(messages)\n return CommonResponse.success(body)\n\n def create_resource(self):\n \"\"\"Create message.\n\n ``storage`` is some hypothetical database.\n\n \"\"\"\n author = self.payload.get('author')\n title = self.payload.get('title')\n body = self.payload.get('body')\n\n message_id = storage.create_message(author=author, title=title, body=body)\n resource_uri = self.get_resoruce_uri(message_id)\n\n return CommonResponse.resource_created(resource_uri)\n\nThen add ``api/response.py``::\n \n from pyramid_skue.json.utils import ResourceJSONRepresentation\n\n class MessageResourceJson(ResourceJSONRepresentation):\n \"\"\"Represents a JSON response for MessageResource.\"\"\"\n def __init__(self, messages):\n ResourceJSONRepresentation.__init__(self, 'MessageResource')\n\n self.objects = []\n\n for message in messages:\n self.objects.append({\n 'author': message.author,\n 'title': message.title,\n 'body': message.body})\n\nNow register the views in your ``__init__.py``::\n\n config.add_route('api-message', '/api/message')\n config.add_view('your_app.api.resources.MessageResource',\n route_name='api-message',\n renderer='string',\n permission='view', # whatever permission you like\n check_csrf=True)\n\nIt's better to secure your views agains CSRF attacs, look at the `pyramid's documentation`_.\n\n.. _`pyramid's documentation`: http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/sessions.html#preventing-cross-site-request-forgery-attacks\n\nContacts\n--------\nThe project is maintained by Cyril Panshine (`@CyrilPanshine`_). Bug reports and pull requests are very much welcomed!\n\n.. _`@CyrilPanshine`: https://twitter.com/CyrilPanshine\n\n\n0.1.0\n-----\nInitial version", "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/kipanshi/pyramid_skue", "keywords": "web pyramid pylons rest api", "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "pyramid_skue", "package_url": "https://pypi.org/project/pyramid_skue/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pyramid_skue/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/kipanshi/pyramid_skue" }, "release_url": "https://pypi.org/project/pyramid_skue/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "pyramid_skue", "version": "0.1.0" }, "last_serial": 926404, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "27405098f0376f3d19c8cefa36ec6724", "sha256": "a6e80d05cef2f668e621ffa880b62f7d1aa8d2ac602dc9ce0c6b657ff5320e8a" }, "downloads": -1, "filename": "pyramid_skue-0.1.0.tar.gz", "has_sig": false, "md5_digest": "27405098f0376f3d19c8cefa36ec6724", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13415, "upload_time": "2013-11-22T12:12:15", "url": "https://files.pythonhosted.org/packages/db/30/056e08c2bf7bf416f959d1468e26db4bf6cc9d95bf94512e8de97ceb3c60/pyramid_skue-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "27405098f0376f3d19c8cefa36ec6724", "sha256": "a6e80d05cef2f668e621ffa880b62f7d1aa8d2ac602dc9ce0c6b657ff5320e8a" }, "downloads": -1, "filename": "pyramid_skue-0.1.0.tar.gz", "has_sig": false, "md5_digest": "27405098f0376f3d19c8cefa36ec6724", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13415, "upload_time": "2013-11-22T12:12:15", "url": "https://files.pythonhosted.org/packages/db/30/056e08c2bf7bf416f959d1468e26db4bf6cc9d95bf94512e8de97ceb3c60/pyramid_skue-0.1.0.tar.gz" } ] }