httpx-sse
Consume Server-Sent Event (SSE) messages with HTTPX.
Table of contents
Installation
Quickstart
How-To
API Reference
Installation
NOTE: This is beta software. Please be sure to pin your dependencies.
pip install httpx-sse=="0.4.*"
Quickstart
httpx-sse provides the connect_sse and aconnect_sse helpers for connecting to an SSE endpoint. The resulting EventSource object exposes the .iter_sse() and .aiter_sse() methods to iterate over the server-sent events.
Example usage:
import httpx
from httpx_sse import connect_sse
with httpx.Client() as client:
with connect_sse(client, "GET", "http:/localhost:8000/sse") as event_source:
for sse in event_source.iter_sse():
print(sse.event, sse.data, sse.id, sse.retry)
You can try this against this example Starlette server (credit):
import asyncio
import uvicorn
from starlette.applications import Starlette
from starlette.routing import Route
from sse_sta
|