Skip to content

feat(runtime): add stream_sse / stream_sse_sync for SSE endpoints - #28

Merged
calvin-archastro merged 1 commit into
mainfrom
feat/runtime-sse-streaming
Jun 29, 2026
Merged

feat(runtime): add stream_sse / stream_sse_sync for SSE endpoints#28
calvin-archastro merged 1 commit into
mainfrom
feat/runtime-sse-streaming

Conversation

@calvin-archastro

Copy link
Copy Markdown
Contributor

What changed

Adds the SSE primitives the generated stream() methods target for x-sdk-streaming endpoints:

  • HttpClient.stream_sse (async) — async def ... -> AsyncIterator[dict]
  • SyncHttpClient.stream_sse_sync (sync) — def ... -> Iterator[dict]

Each opens the request with any method + JSON body, sets Accept: text/event-stream, raises ApiError on a non-2xx response before the stream opens, and yields parsed {"event", "data"} records from the text/event-stream body via httpx streaming (aiter_lines / iter_lines).

classDiagram
    class HttpClient {
      request(path, ...) Any
      request_raw(path, ...) dict
      stream_sse(path, ...) AsyncIterator
    }
    class SyncHttpClient {
      request(path, ...) Any
      request_raw(path, ...) dict
      stream_sse_sync(path, ...) Iterator
    }
    note for HttpClient "stream_sse: method + body, SSE parse, yields {event, data}"
Loading

Scope

Runtime-only. No codegen changes — this is the hand-maintained runtime the generated SSE methods call. (Generator-side emission + contract tests live in archastro-openapi.)

Risk

Low. Purely additive — new methods on the existing clients; nothing else changes. One known limitation: token refresh is not retried mid-stream (a 401 raises ApiError); noted for a follow-up if needed.

User impact

Generated SSE stream() methods (async + sync) now have a working runtime to call.

Testing

Added unit tests (tests/test_http_client.py, 42 pass) mirroring the TS suite: async + sync ordered events + JSON body send + Accept header, and non-2xx → ApiError. ruff check + ruff format clean.

Follow-ups

  • Mid-stream 401 refresh (deferred — minimal version raises instead).
  • Codegen that emits the stream() methods + contract tests is tracked separately (archastro-openapi).

Adds the SSE primitives the generated stream() methods target for
x-sdk-streaming endpoints: HttpClient.stream_sse (async) and
SyncHttpClient.stream_sse_sync (sync). Each opens the request (any method +
JSON body), sets Accept: text/event-stream, raises ApiError on a non-2xx
before the stream opens, and yields parsed {"event", "data"} records from the
event stream via httpx streaming. (Token refresh is not retried mid-stream.)

Runtime-only — no codegen changes. Tests cover async + sync ordered events +
body send and non-2xx -> ApiError. 42 pass; ruff clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@calvin-archastro
calvin-archastro merged commit 4309b21 into main Jun 29, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant