SSE plugin for Starlette
Project description
Server Sent Events for Starlette
Installation:
pip install sse-starlette
Usage:
import asyncio
import uvicorn
from starlette.applications import Starlette
from starlette.routing import Route
from sse_starlette.sse import EventSourceResponse
async def numbers(minimum, maximum):
for i in range(minimum, maximum + 1):
await asyncio.sleep(0.9)
yield dict(data=i)
async def sse(request):
generator = numbers(1, 5)
return EventSourceResponse(generator)
routes = [
Route("/", endpoint=sse)
]
app = Starlette(debug=True, routes=routes)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000, log_level='info')
Output:
Caveat: SSE streaming does not work in combination with GZipMiddleware.
Run the tests:
make test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sse-starlette-0.2.1.tar.gz
(4.5 kB
view details)
File details
Details for the file sse-starlette-0.2.1.tar.gz.
File metadata
- Download URL: sse-starlette-0.2.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6456050e9f4e1daba7351e97376ed0fc1e9e2a30eb357fc711c5b63b8eaef3c4
|
|
| MD5 |
544f08c5e298dfc7a2ee982c1bd941eb
|
|
| BLAKE2b-256 |
cfc5dfab7a2795880c4b9962221ee3783096cba0f5df75b16389e068bc8370d9
|