{ "info": { "author": "Ilya Semenov", "author_email": "ilya@semenov.co", "bugtrack_url": null, "classifiers": [], "description": "aiohttp_route_decorator\n=======================\n\nThe library provides ``@route`` decorator for `aiohttp.web`_, resembling the contract of Flask_ ``@app.route``.\n\n.. _aiohttp.web: https://aiohttp.readthedocs.io/en/latest/web.html\n.. _Flask: http://flask.pocoo.org/docs/0.11/quickstart/#routing\n\nThe imaginary ``aiohttp`` ``@app.route`` decorator is discouraged_ for multiple_ reasons_; this one tries to solve part of those problems (the ``app`` doesn't need to be global at the very least).\n\n.. _discouraged: http://aiohttp.readthedocs.io/en/stable/faq.html\n.. _multiple: https://github.com/KeepSafe/aiohttp/issues/428\n.. _reasons: https://github.com/KeepSafe/aiohttp/pull/195\n\n\nInstallation\n============\n\n::\n\n pip install aiohttp_route_decorator\n\n\nUsage\n=====\n\nCreate a ``route`` object in each of your handler modules, and decorate the handlers:\n\n.. code:: python\n\n\t# myapp/handlers.py\n\n\tfrom aiohttp_route_decorator import RouteCollector\n\n\troute = RouteCollector()\n\n\t@route('/')\n\tasync def index(request):\n\t\treturn web.Response(body=b'OK')\n\n\t@route('/publish', method='POST')\n\tasync def publish(request):\n\t\treturn web.Response(body=b'OK')\n\n\t@route('/login', methods=['GET', 'POST'], name='login')\n\tasync def login(request):\n\t\tif request.method == 'POST':\n\t\t\treturn web.Response(body=b'OK')\n\t\treturn web.Response(body=b'Login')\n\t\t\n\nWhen you init the application, push the collected ``routes`` into ``app.router``:\n\n.. code:: python\n\n\tfrom aiohttp import web\n\tfrom myapp import handlers\n\n\tdef run():\n\t\tapp = web.Application()\n\t\thandlers.route.add_to_router(app.router)\n\t\tweb.run_app(app)\n\n\nNon-decorator use\n-----------------\n\nIf you prefer to keep your routes together, you can construct the list manually after your handers:\n\n.. code:: python\n\n\tfrom aiohttp_route_decorator import RouteCollector, Route\n\n\tasync def index(request):\n\t\treturn web.Response(body=b'OK')\n\n\tasync def publish(request):\n\t\treturn web.Response(body=b'OK')\n\n\tasync def login(request):\n\t\tif request.method == 'POST':\n\t\t\treturn web.Response(body=b'OK')\n\t\treturn web.Response(body=b'Login')\n\n\troutes = RouteCollector([\n\t\tRoute('/', index),\n\t\tRoute('/publish', publish, method='POST'),\n\t\tRoute('/login', login, methods=['GET', 'POST'], name='login'),\n\t])\n\n\nPrefixed routes\n---------------\n\nYou can provide common route prefix that will be prepended to all routes:\n\n.. code:: python\n\n\tfrom aiohttp_route_decorator import RouteCollector\n\n\troutes = RouteCollector(prefix='/app')\n\n\t@route('/')\n\tasync def index(request):\n\t\treturn web.Response(body=b'OK')\n\n\t@route('/publish', method='POST')\n\tasync def publish(request):\n\t\treturn web.Response(body=b'OK')\n\n\t...\n\n\thandlers.route.add_to_router(app.router)\n\t# /app/ -> index\n\t# /app/publish -> publish\n\n\nYou can also provide the prefix within ``add_to_router()`` call instead:\n\n.. code:: python\n\n\tfrom aiohttp_route_decorator import RouteCollector\n\n\troutes = RouteCollector()\n\n\t@route('/')\n\tasync def index(request):\n\t\treturn web.Response(body=b'OK')\n\n\t@route('/publish', method='POST')\n\tasync def publish(request):\n\t\treturn web.Response(body=b'OK')\n\n\t...\n\n\thandlers.route.add_to_router(app.router, prefix='/app')\n\t# /app/ -> index\n\t# /app/publish -> publish\n\n\n...or use both:\n\n.. code:: python\n\n\tfrom aiohttp_route_decorator import RouteCollector\n\n\troutes = RouteCollector(prefix='/app')\n\n\t@route('/')\n\tasync def index(request):\n\t\treturn web.Response(body=b'OK')\n\n\t@route('/publish', method='POST')\n\tasync def publish(request):\n\t\treturn web.Response(body=b'OK')\n\n\t...\n\n\thandlers.route.add_to_router(app.router, prefix='/project')\n\t# /project/app/ -> index\n\t# /project/app/publish -> publish\n\n\nThe non-decorator version of ``RouteCollector`` can also accept prefix:\n\n.. code:: python\n\n\tfrom aiohttp_route_decorator import RouteCollector, Route\n\n\tasync def index(request):\n\t\treturn web.Response(body=b'OK')\n\n\tasync def publish(request):\n\t\treturn web.Response(body=b'OK')\n\n\troutes = RouteCollector(prefix='/app', routes=[\n\t\tRoute('/', index),\n\t\tRoute('/publish', publish, method='POST'),\n\t])\n\n\nParameters reference\n--------------------\n\n``route(path, *, method='GET', methods=None, name=None, **kwargs)``\n\n- **path** (*str*) \u2014 route path. Should be started with slash (``'/'``).\n- **method** (*str*) \u2014 HTTP method for route. Should be one of ``'GET'``, ``'POST'``, ``'PUT'``, ``'DELETE'``, ``'PATCH'``, ``'HEAD'``, ``'OPTIONS'`` or ``'*'`` for any method.\n- **methods** (*List[str]*) \u2014 optional shortcut for creating several routes with different HTTP methods at once. If used, should be a list of acceptable values for ``method`` argument.\n- **name** (*str*) \u2014 optional route name.\n- **kwargs** \u2014 other parameters to be passed to ``aiohttp.web.Resource.add_route()``.\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/IlyaSemenov/aiohttp_route_decorator", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "aiohttp_route_decorator", "package_url": "https://pypi.org/project/aiohttp_route_decorator/", "platform": "", "project_url": "https://pypi.org/project/aiohttp_route_decorator/", "project_urls": { "Homepage": "https://github.com/IlyaSemenov/aiohttp_route_decorator" }, "release_url": "https://pypi.org/project/aiohttp_route_decorator/0.1.4/", "requires_dist": null, "requires_python": "", "summary": "aiohttp @route decorator that doesn't need the app singleton", "version": "0.1.4" }, "last_serial": 3016716, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "0cc5e29c7019be1b0a962341d2f62ea2", "sha256": "17c4180e6be9303f917e088367602f1b66dd2e9454e3b8b5f0eefe7decd9e4da" }, "downloads": -1, "filename": "aiohttp_route_decorator-0.0.1.tar.gz", "has_sig": false, "md5_digest": "0cc5e29c7019be1b0a962341d2f62ea2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1770, "upload_time": "2016-06-21T13:11:22", "url": "https://files.pythonhosted.org/packages/4c/bd/037723fb6cd62c6b37abc940c2e2d4b88d67dbb5349cb750b7d734f3d5fc/aiohttp_route_decorator-0.0.1.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "e8cfd68e148c5d3de48e70c35de8d66c", "sha256": "46519f2638d05be9649084a00096274b2563c66c7ea90ebdcf487ac636131dbc" }, "downloads": -1, "filename": "aiohttp_route_decorator-0.1.0.tar.gz", "has_sig": false, "md5_digest": "e8cfd68e148c5d3de48e70c35de8d66c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2491, "upload_time": "2016-06-22T04:00:16", "url": "https://files.pythonhosted.org/packages/15/33/470f66a468b2baaeec1c7cb802402c15845d3b3bfba7aed9da95d3fa3d8c/aiohttp_route_decorator-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "3624de54d3dfed07703f19eaa891ef04", "sha256": "c7668bdca380c1aa430bf355368167ced464e25f90b2451c1b68cb2cdcb5c9c0" }, "downloads": -1, "filename": "aiohttp_route_decorator-0.1.1.tar.gz", "has_sig": false, "md5_digest": "3624de54d3dfed07703f19eaa891ef04", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2651, "upload_time": "2016-06-22T04:18:58", "url": "https://files.pythonhosted.org/packages/83/8f/40b43f4b33627868536d386a57042dcf4c4cea4dfa545d98a15725bf3a91/aiohttp_route_decorator-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "ea324de1d9800d1827c15d977acbd424", "sha256": "63505a96e12c52b7f3689aac8d1c65bcdc61327f6618eacb3122b1927e15348c" }, "downloads": -1, "filename": "aiohttp_route_decorator-0.1.2.tar.gz", "has_sig": false, "md5_digest": "ea324de1d9800d1827c15d977acbd424", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2642, "upload_time": "2016-06-22T04:23:06", "url": "https://files.pythonhosted.org/packages/d5/57/fd42852ac0419b278e473a3e79147412cfb596ff9c799104c8ca49b51ccc/aiohttp_route_decorator-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "5272ea8f6879ae7bb17ab7721bc7fb6d", "sha256": "3941811faf0674935f5625afa42d7c5b2dfe6975bb5c1f71bc599a1a56b52b83" }, "downloads": -1, "filename": "aiohttp_route_decorator-0.1.3.tar.gz", "has_sig": false, "md5_digest": "5272ea8f6879ae7bb17ab7721bc7fb6d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3132, "upload_time": "2016-06-25T09:25:13", "url": "https://files.pythonhosted.org/packages/80/89/9bb8bd519a2679ee5ceedddf07b06230dd3548b39ff10cfecffb2edcd0f4/aiohttp_route_decorator-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "a02ac34d701c579c11f39d4c9c02adab", "sha256": "d03fa077255852c26609c6134f342bfd5028b7b4ce19bf7927f55a04684c653c" }, "downloads": -1, "filename": "aiohttp_route_decorator-0.1.4.tar.gz", "has_sig": false, "md5_digest": "a02ac34d701c579c11f39d4c9c02adab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3796, "upload_time": "2017-07-12T07:33:31", "url": "https://files.pythonhosted.org/packages/4f/b6/3af0444d36812b68367c3bb8ff65d0ccf5ba855ce28cda5ce10ff465021a/aiohttp_route_decorator-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a02ac34d701c579c11f39d4c9c02adab", "sha256": "d03fa077255852c26609c6134f342bfd5028b7b4ce19bf7927f55a04684c653c" }, "downloads": -1, "filename": "aiohttp_route_decorator-0.1.4.tar.gz", "has_sig": false, "md5_digest": "a02ac34d701c579c11f39d4c9c02adab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3796, "upload_time": "2017-07-12T07:33:31", "url": "https://files.pythonhosted.org/packages/4f/b6/3af0444d36812b68367c3bb8ff65d0ccf5ba855ce28cda5ce10ff465021a/aiohttp_route_decorator-0.1.4.tar.gz" } ] }