httpx-sse
Consume Server-Sent Event (SSE) streams with HTTPX
Repository Health
Technical Analysis
httpx-sse adds Server-Sent Events (SSE) support on top of the HTTPX client, since HTTPX itself has no built-in SSE parsing. It provides connect_sse/aconnect_sse context managers that open a streaming request against an SSE endpoint and return an EventSource object, whose .iter_sse()/.aiter_sse() methods yield parsed events (with event, data, id, and retry fields) as they arrive over the wire.
Both synchronous and async usage are first-class, matching HTTPX’s own sync/async client split, so the same parsing logic works whether you’re using httpx.Client or httpx.AsyncClient. It is explicitly positioned as beta software (pin your version), and is commonly used as a building block by higher-level libraries that need to consume SSE-based streaming APIs — including LLM streaming responses that use the SSE wire format.
What You Get
connect_sse/aconnect_ssecontext managers for opening a streaming SSE connection withhttpx.Client/httpx.AsyncClient- An
EventSourceobject exposing.iter_sse()/.aiter_sse()to iterate over parsed events synchronously or asynchronously ServerSentEventmodel objects carryingevent,data,id, andretryfields per the SSE spec- Low-level SSE decoders that handle multi-line data fields and comment lines per the WHATWG SSE specification
- Explicit exception types for malformed SSE responses or non-SSE content types
Common Use Cases
- Consuming streaming LLM API responses (OpenAI-style chat completions, etc.) that use SSE as their wire format
- Building a Python client for any backend that pushes live updates via Server-Sent Events (progress bars, notifications, live feeds)
- Testing an SSE-emitting backend (e.g. built with Starlette/FastAPI + sse-starlette) end-to-end from Python
- Adding SSE support to an existing codebase already standardized on HTTPX as its HTTP client
Under The Hood
Architecture - Four small modules make up the whole package: _api.py defines connect_sse/aconnect_sse context managers that open an HTTPX streaming request and wrap the response in an EventSource; _models.py defines the EventSource/ServerSentEvent data classes and the .iter_sse()/.aiter_sse() iteration methods; _decoders.py implements the line-by-line SSE decoding state machine (buffering data:/event:/id:/retry: fields across multi-line events); _exceptions.py defines typed errors for non-SSE responses. Tech Stack - Pure Python with httpx as its only runtime dependency, setuptools-scm for version derivation from git tags, requires Python 3.9+, and CI runs on Azure Pipelines. Code Quality - tests/ has one file per module (test_decoders.py, test_models.py, test_api.py, test_event_source.py, test_exceptions.py) plus an ASGI integration test, giving focused unit coverage; however development activity has slowed considerably (recent-activity health sub-score of 1/25), consistent with a small, feature-complete beta library. API Design - The connect_sse(client, method, url) signature mirrors httpx.Client.stream() closely, and the sync/async method-naming convention (iter_sse/aiter_sse) matches HTTPX’s own iter_bytes/aiter_bytes pattern, so existing HTTPX users can adopt it with almost no new concepts.
Used by 4 apps in this directory
Agno
Devops · AI Development · Automation
Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.
Dify
No Code Platforms · AI Development · Developer Tools
Visual LLM workflow platform with RAG pipelines, agent capabilities, and model management for building production AI applications.
GPT Researcher
Productivity · AI Assistants
The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.
SurfSense
Search · AI Assistants
The open-source, unlimited NotebookLM alternative with real-time collaboration, a desktop app, and no vendor lock-in.