Skip to main content

aiohttp-sse

https://github.com/aio-libs/aiohttp-sse/workflows/CI/badge.svg?event=push https://codecov.io/gh/aio-libs/aiohttp-sse/branch/master/graph/badge.svg Updates 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

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

Requirements

License

The aiohttp-sse is offered under Apache 2.0 license.

Metadata

Release files for aiohttp-sse 3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiohttp-sse 3.0
File Size Uploaded
aiohttp_sse-3.0.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aiohttp-sse 3.0
File Interpreter ABI Platform
aiohttp_sse-3.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.7 kB

Release files / aiohttp_sse-3.0.tar.gz

Download URL aiohttp_sse-3.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4c2158dc7221fbcad225699c2b7c368c15ae45ef195447ddd0ba3dea5af24c70
BLAKE2b-256 checksum
How to use checksums
af6d01d7f71e38ac91a912dd8c4ed1a1481316dc83cb6c42043bbfa1b647c0e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / aiohttp_sse-3.0-py3-none-any.whl

Download URL aiohttp_sse-3.0-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bd3bdb35a4beebe25a35e8240242636d45e952c80376166f7bc062511e299e5
BLAKE2b-256 checksum
How to use checksums
eb3f06f9f0a6c587d0a1106ea408b308ce09f2935d7365d1bada80c54b4bcc9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

3.0 This release

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page