Awesome Open Source
Awesome Open Source


.. image:: :target:

.. image:: :target:

.. image:: :target: :alt: Updates

.. image:: :target: :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 process as simple as::

$ pip install aiohttp-sse

Mailing List

aio-libs google group:!forum/aio-libs


.. code:: python

import asyncio
from aiohttp import web
from aiohttp.web import Response
from aiohttp_sse import sse_response
from datetime import datetime

async def hello(request):
    loop =
    async with sse_response(request) as resp:
        while True:
            data = 'Server Time : {}'.format(
            await resp.send(data)
            await asyncio.sleep(1, loop=loop)
    return resp

async def index(request):
    d = """
                var evtSource = new EventSource("/hello");
                evtSource.onmessage = function(e) {
                    document.getElementById('response').innerText =
            <h1>Response from server:</h1>
            <div id="response"></div>
    return Response(text=d, 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='', port=8080)

EventSource Protocol


  • Python_ 3.5+
  • aiohttp_ 3+


The aiohttp-sse is offered under Apache 2.0 license.

.. _Python: .. _asyncio: .. _aiohttp:

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
python (50,967
asyncio (261
aiohttp (68
server-sent-events (31
eventsource (15

Find Open Source By Browsing 7,000 Topics Across 59 Categories