httpx-sse

Consume Server-Sent Event (SSE) streams with HTTPX

Library
PyPI
v0.4.3
213stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
35/100Needs Attention
Development Activity0
Maintenance20
Community48
Maturity52
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture72
Code Quality78
Innovation60
Learning Curve85

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_sse context managers for opening a streaming SSE connection with httpx.Client/httpx.AsyncClient
  • An EventSource object exposing .iter_sse()/.aiter_sse() to iterate over parsed events synchronously or asynchronously
  • ServerSentEvent model objects carrying event, data, id, and retry fields 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search