{ "info": { "author": "Bruno Reni\u00e9", "author_email": "bruno@renie.fr", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4" ], "description": "Induction\n=========\n\n.. image:: https://travis-ci.org/brutasse/induction.svg?branch=master\n :alt: Build Status\n :target: https://travis-ci.org/brutasse/induction\n\nA simple web framework based on asyncio.\n\n.. image:: https://raw.githubusercontent.com/brutasse/induction/master/tesla.jpg\n :alt: Tesla's induction motor\n\nInduction is the phenomenon that drives asynchronous motors. Pictured above is\n`Tesla's induction motor`_.\n\n.. _Tesla's induction motor: http://en.wikipedia.org/wiki/Induction_motor\n\nInstallation\n------------\n\n::\n\n pip install induction\n\nUsage examples\n--------------\n\nIf you know `express`_ and/or `Flask`_, you'll feel right at home.\n\n.. _express: http://expressjs.com/\n.. _Flask: http://flask.pocoo.org/\n\nSynchronous route\n`````````````````\n\n.. code-block:: python\n\n from induction import Induction\n app = Induction(__name__)\n\n @app.route('/')\n def index(request):\n return app.render_template('index.html')\n\nAsync route\n```````````\n\n.. code-block:: python\n\n from asyncio import coroutine\n from induction import Induction\n app = Induction(__name__)\n\n @app.route('/slow'):\n @coroutine\n def slow(request, response):\n yield from asyncio.sleep(10)\n response.write('Hello, world!')\n\nHandlers\n--------\n\nHandlers are decorated with ``@app.route(url_pattern)``. Routes are managed by\nthe `Routes`_ library.\n\n.. _Routes: https://routes.readthedocs.org/en/latest/\n\nHandlers have several way to send data back to the client:\n\n* *returning*: synchronous routes can return data directly. The return values\n are passed to the response object. Supported return values are:\n\n - A string or bytes object, which becomes the body of the response. A\n default status of ``200 OK`` and mimetype of ``text/html`` are added.\n\n - A tuple of ``(response, headers, status)``, in any order and with at least\n one item provided. ``headers`` can be a list or a dictionnary.\n\n* *writing*: handlers can be defined to accept two arguments, ``request`` and\n ``response``. They can then directly write data to the response.\n\n``Induction`` objects\n---------------------\n\nThe ``Induction`` constructor accepts the following arguments:\n\n* ``name``: the name for your app.\n\nAnd the following keyword arguments:\n\n* ``template_folder``: path to the folder from which to load templates.\n Defaults to ``'templates'`` relatively to the current working directory.\n\nThe following methods are available on ``Induction`` instances:\n\n* ``route(path, **conditions)``: registers a route. Meant to be used as a\n decorator::\n\n @app.route('/')\n def foo(request):\n return jsonify({})\n\n* ``before_request(func)``: registers a function to be called before all\n request handlers. E.g.::\n\n @app.before_request\n def set_some_header(request, response):\n request.uuid = str(uuid.uuid4())\n response.add_header('X-Request-ID', request.uuid)\n\n ``before_request`` functions are called in the order they've been declared.\n\n When a ``before_request`` function returns something else than ``None``, all\n request processing is stopped and the returned data is passed to the\n response.\n\n* ``after_request(func)`` registers a function to be called after all request\n handlers. Works like ``before_request``.\n\n* ``handle_404(request, [response])``: error handler for HTTP 404 errors.\n\n* ``error_handler(exc_type)``: registers a function to be called when a\n request handler raises an exception of type ``exc_type``. Exception handlers\n take the request, the response and the exception object as argument::\n\n @app.error_handler(ValueError):\n def handle_value_error(request, response, exception):\n response.add_header(\"X-Exception\", str(exception))\n\n Note that the response may have been partially sent to the client already.\n Depending on what your application does, it might not be safe to set headers\n or even send data to the response.\n\n Setting ``exc_type`` to ``None`` lets you register a catch-all error handler\n that will process all unhandled exceptions::\n\n @app.error_handler(None):\n def handle_exception(request, response, exception):\n # Send exception to Sentry\n client = raven.Client()\n client.captureException()\n\n* ``render_template(template_name_or_list, **context)``: loads the first\n matching template from ``template_name_or_list`` and renders it using the\n given context.\n\nResponse objects\n----------------\n\nThe following attributes and methods are available on ``Response`` objects:\n\n* ``status``, ``status_line``: the HTTP status code and line for this\n response.\n\n* ``write(chunk, close=False, unchunked=False)``: writes a chunk of data to\n the reponse.\n\n If ``chunk`` is a string, it'll be encoded to bytes.\n\n If ``close`` is ``True``, ``write_eof()`` is called on the response.\n\n If ``unchunked`` is ``True`` a ``Content-Length`` header is added and the\n response will be closed once the chunk is written.\n\n* ``redirect(location, status=302)``: redirects to ``location`` using the\n given status code.\n\nReleases\n--------\n\n* **0.2** (2014-09-25)\n\n * 404 error returns HTML by default.\n\n * Ability to set a catch-all error handler, e.g. for Sentry handling.\n\n* **0.1** (2014-09-19)\n\n * Initial release.\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "induction", "package_url": "https://pypi.org/project/induction/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/induction/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/induction/0.2/", "requires_dist": null, "requires_python": null, "summary": "A simple web framework based on asyncio.", "version": "0.2" }, "last_serial": 1237546, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "ed1a0f319d7854840701abe080034f73", "sha256": "472a447f7864968464332ce2e51ed7a7402d76c9acb0cfd45f500539c5be252a" }, "downloads": -1, "filename": "induction-0.1.tar.gz", "has_sig": false, "md5_digest": "ed1a0f319d7854840701abe080034f73", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6087, "upload_time": "2014-09-19T09:01:52", "url": "https://files.pythonhosted.org/packages/62/b0/ace52215cf5f4137f9574b63ef897cccf274991db9dc0151950ab1ad6a69/induction-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "e1f32260388c47c04bccd885582c91a7", "sha256": "c2fff686cba8eb7cda79e63072e8c414263039b04e9f3188740cbba0e3b03ba9" }, "downloads": -1, "filename": "induction-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "e1f32260388c47c04bccd885582c91a7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6870, "upload_time": "2014-09-25T09:56:36", "url": "https://files.pythonhosted.org/packages/8a/55/24c47efdab067b613e6aa17a6e3a5c813896bc9c61b4e8ed80af0804f28e/induction-0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0ab62b9c2138de0b676d46b8fbb1767e", "sha256": "046c1180c630fce917634cb7d92ee5a7ffb28bd452825f677e971a48c3d80a10" }, "downloads": -1, "filename": "induction-0.2.tar.gz", "has_sig": false, "md5_digest": "0ab62b9c2138de0b676d46b8fbb1767e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6452, "upload_time": "2014-09-25T09:56:39", "url": "https://files.pythonhosted.org/packages/32/5b/9e1987fc39913e871619f1048af4f5b30464c815e5aa420b4aa0fc802879/induction-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e1f32260388c47c04bccd885582c91a7", "sha256": "c2fff686cba8eb7cda79e63072e8c414263039b04e9f3188740cbba0e3b03ba9" }, "downloads": -1, "filename": "induction-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "e1f32260388c47c04bccd885582c91a7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6870, "upload_time": "2014-09-25T09:56:36", "url": "https://files.pythonhosted.org/packages/8a/55/24c47efdab067b613e6aa17a6e3a5c813896bc9c61b4e8ed80af0804f28e/induction-0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0ab62b9c2138de0b676d46b8fbb1767e", "sha256": "046c1180c630fce917634cb7d92ee5a7ffb28bd452825f677e971a48c3d80a10" }, "downloads": -1, "filename": "induction-0.2.tar.gz", "has_sig": false, "md5_digest": "0ab62b9c2138de0b676d46b8fbb1767e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6452, "upload_time": "2014-09-25T09:56:39", "url": "https://files.pythonhosted.org/packages/32/5b/9e1987fc39913e871619f1048af4f5b30464c815e5aa420b4aa0fc802879/induction-0.2.tar.gz" } ] }