aiohttp-sse


Nameaiohttp-sse JSON
Version 2.2.0 PyPI version JSON
download
home_pagehttps://github.com/aio-libs/aiohttp_sse/
SummaryServer-sent events support for aiohttp.
upload_time2024-02-29 18:43:48
maintainer
docs_urlNone
authorNikolay Novik
requires_python>=3.8
licenseApache 2
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            aiohttp-sse
===========
.. image:: https://github.com/aio-libs/aiohttp-sse/workflows/CI/badge.svg?event=push
    :target: https://github.com/aio-libs/aiohttp-sse/actions?query=event%3Apush+branch%3Amaster

.. image:: https://codecov.io/gh/aio-libs/aiohttp-sse/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/aio-libs/aiohttp-sse

.. image:: https://pyup.io/repos/github/aio-libs/aiohttp-sse/shield.svg
     :target: https://pyup.io/repos/github/aio-libs/aiohttp-sse/
     :alt: Updates

.. image:: https://badges.gitter.im/Join%20Chat.svg
     :target: https://gitter.im/aio-libs/Lobby
     :alt: Chat on Gitter


The **EventSource** interface is used to receive server-sent events. It connects
to a server over HTTP and receives events in text/event-stream format without
closing the connection. *aiohttp-sse* provides support for server-sent
events for aiohttp_.


Installation
------------
Installation process as simple as::

    $ pip install aiohttp-sse


Example
-------
.. code:: python

    import asyncio
    from datetime import datetime

    from aiohttp import web

    from aiohttp_sse import sse_response


    async def hello(request: web.Request) -> web.StreamResponse:
        async with sse_response(request) as resp:
            while resp.is_connected():
                time_dict = {"time": f"Server Time : {datetime.now()}"}
                data = json.dumps(time_dict, indent=2)
                print(data)
                await resp.send(data)
                await asyncio.sleep(1)
        return resp


    async def index(_request: web.Request) -> web.StreamResponse:
        html = """
            <html>
                <body>
                    <script>
                        var eventSource = new EventSource("/hello");
                        eventSource.addEventListener("message", event => {
                            document.getElementById("response").innerText = event.data;
                        });
                    </script>
                    <h1>Response from server:</h1>
                    <div id="response"></div>
                </body>
            </html>
        """
        return web.Response(text=html, content_type="text/html")


    app = web.Application()
    app.router.add_route("GET", "/hello", hello)
    app.router.add_route("GET", "/", index)
    web.run_app(app, host="127.0.0.1", port=8080)


EventSource Protocol
--------------------

* http://www.w3.org/TR/2011/WD-eventsource-20110310/
* https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events


Requirements
------------

* aiohttp_ 3+


License
-------

The *aiohttp-sse* is offered under Apache 2.0 license.

.. _Python: https://www.python.org
.. _asyncio: http://docs.python.org/3/library/asyncio.html
.. _aiohttp: https://github.com/aio-libs/aiohttp

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aio-libs/aiohttp_sse/",
    "name": "aiohttp-sse",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Nikolay Novik",
    "author_email": "nickolainovik@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/80/df/4ddb30e689695fd91cf41c072e154061120ed166e8baf6c9a0020f27dffc/aiohttp-sse-2.2.0.tar.gz",
    "platform": null,
    "description": "aiohttp-sse\n===========\n.. image:: https://github.com/aio-libs/aiohttp-sse/workflows/CI/badge.svg?event=push\n    :target: https://github.com/aio-libs/aiohttp-sse/actions?query=event%3Apush+branch%3Amaster\n\n.. image:: https://codecov.io/gh/aio-libs/aiohttp-sse/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/aio-libs/aiohttp-sse\n\n.. image:: https://pyup.io/repos/github/aio-libs/aiohttp-sse/shield.svg\n     :target: https://pyup.io/repos/github/aio-libs/aiohttp-sse/\n     :alt: Updates\n\n.. image:: https://badges.gitter.im/Join%20Chat.svg\n     :target: https://gitter.im/aio-libs/Lobby\n     :alt: Chat on Gitter\n\n\nThe **EventSource** interface is used to receive server-sent events. It connects\nto a server over HTTP and receives events in text/event-stream format without\nclosing the connection. *aiohttp-sse* provides support for server-sent\nevents for aiohttp_.\n\n\nInstallation\n------------\nInstallation process as simple as::\n\n    $ pip install aiohttp-sse\n\n\nExample\n-------\n.. code:: python\n\n    import asyncio\n    from datetime import datetime\n\n    from aiohttp import web\n\n    from aiohttp_sse import sse_response\n\n\n    async def hello(request: web.Request) -> web.StreamResponse:\n        async with sse_response(request) as resp:\n            while resp.is_connected():\n                time_dict = {\"time\": f\"Server Time : {datetime.now()}\"}\n                data = json.dumps(time_dict, indent=2)\n                print(data)\n                await resp.send(data)\n                await asyncio.sleep(1)\n        return resp\n\n\n    async def index(_request: web.Request) -> web.StreamResponse:\n        html = \"\"\"\n            <html>\n                <body>\n                    <script>\n                        var eventSource = new EventSource(\"/hello\");\n                        eventSource.addEventListener(\"message\", event => {\n                            document.getElementById(\"response\").innerText = event.data;\n                        });\n                    </script>\n                    <h1>Response from server:</h1>\n                    <div id=\"response\"></div>\n                </body>\n            </html>\n        \"\"\"\n        return web.Response(text=html, content_type=\"text/html\")\n\n\n    app = web.Application()\n    app.router.add_route(\"GET\", \"/hello\", hello)\n    app.router.add_route(\"GET\", \"/\", index)\n    web.run_app(app, host=\"127.0.0.1\", port=8080)\n\n\nEventSource Protocol\n--------------------\n\n* http://www.w3.org/TR/2011/WD-eventsource-20110310/\n* https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events\n\n\nRequirements\n------------\n\n* aiohttp_ 3+\n\n\nLicense\n-------\n\nThe *aiohttp-sse* is offered under Apache 2.0 license.\n\n.. _Python: https://www.python.org\n.. _asyncio: http://docs.python.org/3/library/asyncio.html\n.. _aiohttp: https://github.com/aio-libs/aiohttp\n",
    "bugtrack_url": null,
    "license": "Apache 2",
    "summary": "Server-sent events  support for aiohttp.",
    "version": "2.2.0",
    "project_urls": {
        "Homepage": "https://github.com/aio-libs/aiohttp_sse/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5ab8bf448b1d2dbe6cf16c3be0b92230a8f032f2f0ed159a2299284c709819c8",
                "md5": "a68b27baacf7606fc5abbb266c956f6d",
                "sha256": "339f9803bcf4682a2060e75548760d86abe4424a0d92ba66ff4985de3bd743dc"
            },
            "downloads": -1,
            "filename": "aiohttp_sse-2.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a68b27baacf7606fc5abbb266c956f6d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6740,
            "upload_time": "2024-02-29T18:43:46",
            "upload_time_iso_8601": "2024-02-29T18:43:46.423986Z",
            "url": "https://files.pythonhosted.org/packages/5a/b8/bf448b1d2dbe6cf16c3be0b92230a8f032f2f0ed159a2299284c709819c8/aiohttp_sse-2.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "80df4ddb30e689695fd91cf41c072e154061120ed166e8baf6c9a0020f27dffc",
                "md5": "8c86e737a2f3642941c1d383f42ce6ae",
                "sha256": "a48dd5774031d3f41a29e159ebdbb93e89c8f37c1e9e83e196296be51885a5c2"
            },
            "downloads": -1,
            "filename": "aiohttp-sse-2.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8c86e737a2f3642941c1d383f42ce6ae",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9432,
            "upload_time": "2024-02-29T18:43:48",
            "upload_time_iso_8601": "2024-02-29T18:43:48.118475Z",
            "url": "https://files.pythonhosted.org/packages/80/df/4ddb30e689695fd91cf41c072e154061120ed166e8baf6c9a0020f27dffc/aiohttp-sse-2.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-29 18:43:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aio-libs",
    "github_project": "aiohttp_sse",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "aiohttp-sse"
}
        
Elapsed time: 0.43319s