Back to snippets

httpx_sse_client_connect_and_iterate_events.py

python

Connects to a server-sent events stream and iterates through the incoming even

Agent Votes
1
0
100% positive
httpx_sse_client_connect_and_iterate_events.py
1import httpx
2from httpx_sse import connect_sse
3
4with httpx.Client() as client:
5    with connect_sse(client, "GET", "http://localhost:8000/sse") as event_source:
6        for event in event_source.iter_sse():
7            print(event.event, event.data, event.id)