{ "info": { "author": "Tyler Nullmeier", "author_email": "Tylerzeromaster@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3 :: Only", "Topic :: Utilities" ], "description": "Tornado web services @ your fingertips\n===============================================================================\n\n**dizzydecor** is a python library that makes it easy to create web services \nin tornado. To accomplish this, the library adds two new classes and decorators \nthat help eliminate the need for boilerplate code. \n\nExample\n----------------------------------------------------------------------------\n\nHere is an example to show how **dizzydecor**, works:\n\n.. code:: python\n\n from tornado.ioloop import IOLoop\n\n from dizzydecor import (\n WSApplication,\n WebserviceHandler,\n webservice,\n servicemethod\n )\n\n @webservice\n class MyWebService(WebserviceHandler):\n\n @servicemethod()\n async def echo(self, message):\n return f\"You said: {message}\"\n\n @servicemethod(httpmethod=\"GET\")\n async def my_greeting(self):\n return dict(greeting=\"Hello, welcome to my web service demo!\")\n\n if __name__ == \"__main__\":\n app = WSApplication()\n app.listen(8080)\n IOLoop.current().start()\n\nThis will create a web service with two service methods: echo and my_greeting.\nBy default, service methods respond to POST requests; however, the ``httpmethod``\nargument to ``servicemethod`` can change this behaviour. For instance, \nmy_greeting is setup to respond to GET requests.\n\nPaths are generated based on class and method names. \n - A web service's path is the lower-case class name with each word joined by a hyphen. (MyWebService -> my-web-service)\n - A method's path is the method's name with underscores replaced with hyphens. (my_greeting -> my-greeting)\n\nIt's also worth noting that if a service method does not get all of its \narguments, the service handler sends a 400 HTTP status code.\n\nTo test, you can use curl::\n\n $ curl http://localhost:8080/my-web-service/echo -d '{\"message\": \"This is my message\"}'\n \"You said: This is my message\"\n $ curl http://localhost:8080/my-web-service/my-greeting\n {\"greeting\": \"Hello, welcome to my web service demo!\"}\n\nYou may have noticed that the example uses JSON.\n\nWhat if I do not want to use JSON?\n----------------------------------------------------------------------------\n\nIn this case, all you need to do is override the ``load`` and ``dump``\nmethods in a subclass of ``WebserviceHandler`` or ``SyncWebserviceHandler``\n\nHere is an example with `PyYAML `_:\n\n.. code:: python\n\n # -- snip --\n\n import yaml\n\n class YAMLServiceHandler(WebserviceHandler):\n\n def load(self, request):\n return yaml.safe_load(request)\n\n def dump(self, response):\n # You can also set content-type here with self.set_header\n return yaml.safe_dump(response)\n\n @webservice\n class YetAnotherService(YAMLServiceHandler):\n\n @servicemethod()\n async def join(self, arr, delim):\n return dict(message=delim.join(map(str, arr)))\n\n # -- snip --\n\nThe rest is exactly the same, except now your service will use YAML.\n\nHere's how to test it with curl::\n\n $ curl http://localhost:8080/yet-another-service/join --data-binary @\"/dev/stdin\"<<_eof_\n arr:\n - Hello\n - world\n delim: \" \"\n _eof_\n message: Hello world\n\nInstallation\n----------------------------------------------------------------------------\n\nInstall with pip or easy_install::\n\n $ pip install dizzydecor\n\n**dizzydecor** is only available for Python 3\n\nWhat about non-standard HTTP methods? (Experimental)\n----------------------------------------------------------------------------\n\nIn this case, all you need to do is extend the SUPPORTED_METHODS property \nof the service handler class.\n\n.. code:: python\n\n # -- snip --\n\n @webservice\n class NotificationService(WebserviceHandler):\n SUPPORTED_METHODS = WebserviceHandler.SUPPORTED_METHODS + (\"NOTIFY\",)\n\n @servicemethod(httpmethod=\"NOTIFY\")\n async def notification(self, message):\n # etc\n\n # -- snip --\n\nThe script for the new HTTP method is added to the service handler \nduring the creation of the web service. After that, all you need to \ndo is setup to service method to respond to that request type. Depending \non the situation, you might also need to customize the way arguments are \nparsed by overriding prepare.\n\nSynchronous services\n----------------------------------------------------------------------------\n\nThe ``WebserviceHandler`` is asynchronous; however, you can make synchronous \nservice handlers using the ``SyncWebserviceHandler`` class.\n\n.. code:: python\n\n # -- snip --\n\n @webservice\n class MySyncService(SyncWebserviceHandler):\n\n # This time the method is not async\n @servicemethod(httpmethod=\"GET\")\n def my_greeting(self):\n return dict(greeting=\"Hello...\")\n\n # -- snip --\n\n", "description_content_type": "text/x-rst", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/TylerZeroMaster/dizzydecor", "keywords": "tornado webservice web service oriented SOA decorator", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "dizzydecor", "package_url": "https://pypi.org/project/dizzydecor/", "platform": "", "project_url": "https://pypi.org/project/dizzydecor/", "project_urls": { "Homepage": "https://github.com/TylerZeroMaster/dizzydecor" }, "release_url": "https://pypi.org/project/dizzydecor/0.0.1/", "requires_dist": [ "tornado" ], "requires_python": ">=3", "summary": "Web service decorators for tornado", "version": "0.0.1" }, "last_serial": 5636424, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "107e8d934b544e86c64982cc89937dd5", "sha256": "8777be082482f9681077050210c6645f8b1410cb004ced16b5f55eaf974718fe" }, "downloads": -1, "filename": "dizzydecor-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "107e8d934b544e86c64982cc89937dd5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3", "size": 6170, "upload_time": "2019-08-05T21:12:37", "url": "https://files.pythonhosted.org/packages/89/6f/2563e3d143dc759c270d7e5df95a80cadd9c71160e0d1b435b1c513a659c/dizzydecor-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "322e3cb3981ecce9275815f0ce93baef", "sha256": "3641a1328ed569c2708388d22f5afda2a4367b3e633c04f21a8e4e8e00e05c20" }, "downloads": -1, "filename": "dizzydecor-0.0.1.tar.gz", "has_sig": false, "md5_digest": "322e3cb3981ecce9275815f0ce93baef", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 6318, "upload_time": "2019-08-05T21:12:39", "url": "https://files.pythonhosted.org/packages/3c/55/c3dff2503dc15d408c79250849a9ec19b7fed5fcd2a64baba562f47b9a6d/dizzydecor-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "107e8d934b544e86c64982cc89937dd5", "sha256": "8777be082482f9681077050210c6645f8b1410cb004ced16b5f55eaf974718fe" }, "downloads": -1, "filename": "dizzydecor-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "107e8d934b544e86c64982cc89937dd5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3", "size": 6170, "upload_time": "2019-08-05T21:12:37", "url": "https://files.pythonhosted.org/packages/89/6f/2563e3d143dc759c270d7e5df95a80cadd9c71160e0d1b435b1c513a659c/dizzydecor-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "322e3cb3981ecce9275815f0ce93baef", "sha256": "3641a1328ed569c2708388d22f5afda2a4367b3e633c04f21a8e4e8e00e05c20" }, "downloads": -1, "filename": "dizzydecor-0.0.1.tar.gz", "has_sig": false, "md5_digest": "322e3cb3981ecce9275815f0ce93baef", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 6318, "upload_time": "2019-08-05T21:12:39", "url": "https://files.pythonhosted.org/packages/3c/55/c3dff2503dc15d408c79250849a9ec19b7fed5fcd2a64baba562f47b9a6d/dizzydecor-0.0.1.tar.gz" } ] }