---
title: "aiohttp-sse | pypx"
description: "Server-sent events  support for aiohttp."
canonical_url: "https://pypx.app/packages/aiohttp-sse"
meta:
  "og:description": "Server-sent events  support for aiohttp."
  "og:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_aiohttp-sse%2Cversion_3.0%2Csummary_Server-sent%2Bevents%2B%2Bsupport%2Bfor%2Baiohttp.%2Clicense_Apache%2BSoftware%2BLicense%2Cp_Ii9wYWNrYWdlcy9haW9odHRwLXNzZSI%2Cs_mO8nqhAkPZQPuuxY.png"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "aiohttp-sse 3.0"
  "twitter:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_aiohttp-sse%2Cversion_3.0%2Csummary_Server-sent%2Bevents%2B%2Bsupport%2Bfor%2Baiohttp.%2Clicense_Apache%2BSoftware%2BLicense%2Cp_Ii9wYWNrYWdlcy9haW9odHRwLXNzZSI%2Cs_mO8nqhAkPZQPuuxY.png"
---

> Index of every page on this site: [llms.txt](https://pypx.app/llms.txt)

# **aiohttp-sse**

v3.0

Server-sent events support for aiohttp.

10 KB Python 3.11+ py3-none-anyApache Software License1 deps

[** Diff **](https://pypx.app/packages/aiohttp-sse/diff)

`$ uv add aiohttp-sse`

# aiohttp-sse

![Updates](https://pyup.io/repos/github/aio-libs/aiohttp-sse/shield.svg) ![Chat on Gitter](https://badges.gitter.im/Join%20Chat.svg)

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

```python
import asyncio
import json
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.

## **Details **

<dl>

<dt>Version</dt>
<dd>3.0</dd>

<dt>License</dt>
<dd>Apache Software License</dd>

<dt>Python</dt>
<dd>&gt;=3.11</dd>

<dt>Maintainer</dt>
<dd>Nikolay Novik</dd></dl>

## **Links**

- [Homepage](https://github.com/aio-libs/aiohttp_sse/)
- [View on PyPI](https://pypi.org/project/aiohttp-sse/)

## **Release Cadence **

**1**

releases in the past year

avg 395 days between releases

## **Maintainers **

- Nikolay Novik · [nickolainovik@gmail.com](mailto:nickolainovik@gmail.com)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://pypx.app/#website","@type":"WebSite","description":"The Python Package Index, reimagined. Fast search, dependency insights, download trends, and changelogs — all in one place.","name":"pypx","url":"https://pypx.app/"},{"@id":"https://pypx.app/packages/aiohttp-sse#webpage","@type":"WebPage","description":"Server-sent events  support for aiohttp.","name":"aiohttp-sse","url":"https://pypx.app/packages/aiohttp-sse","isPartOf":{"@id":"https://pypx.app/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://pypx.app/packages/aiohttp-sse"]}]},{"@id":"https://pypx.app/packages/aiohttp-sse#/schema/software-application/1","@type":"SoftwareApplication","applicationCategory":"DeveloperApplication","description":"Server-sent events  support for aiohttp.","license":"Apache Software License","name":"aiohttp-sse","softwareVersion":"3.0"}]}
```

## Sitemap

See the full [sitemap](https://pypx.app/sitemap.md) for all pages.
