Skip to content

Feat/sse - #83

Merged
NEFORCEO merged 12 commits into
masterfrom
feat/sse
Jun 27, 2026
Merged

Feat/sse#83
NEFORCEO merged 12 commits into
masterfrom
feat/sse

Conversation

@NEFORCEO

Copy link
Copy Markdown
Member

🚀 Description

Add @app.sse() decorator for Server-Sent Events (SSE) — real-time event streaming over plain HTTP, alongside the existing HTTP and WebSocket routes.

Includes:

  • fasthttp/sse.pySSEEvent dataclass with event, data, id, retry fields
  • @app.sse() decorator on FastHTTP — supports headers, reconnect, max_retries, tags
  • _run_sse() — async SSE parser using httpx.AsyncClient streaming, parses the standard text/event-stream format (data:/event:/id:/: lines)
  • SSE streams run in parallel with HTTP requests and WebSocket connections in app.run()
  • Auto-reconnect with exponential backoff and Last-Event-ID resumption

Documentation and examples:

  • docs/en/tutorial/sse/index.md — English tutorial (quick start, API reference, SSE vs WebSocket comparison)
  • docs/ru/tutorial/sse/index.md — Russian tutorial
  • examples/sse/basic.py — Wikimedia EventStreams real-world example
  • examples/sse/reconnect.py — reconnection example with auth headers

🧩 Type of Change

  • feat: New feature
  • docs: Documentation update

✅ Checklist

  • Tests added or updated
  • Documentation updated
  • No breaking changes
  • Code follows project style

🔗 Related Issues

N/A


📸 Additional Context

SSE streams complete alongside HTTP requests — if the server closes the stream, the app exits normally. For infinite streams (e.g. Wikimedia), the app stays alive until Ctrl+C.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thanks for your contribution, @NEFORCEO!

Please make sure:

  • Code is clean and formatted
  • Tests are passing
  • PR description is clear

Maintainers will review it soon.

@codspeed-hq

codspeed-hq Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 42.09%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 6 improved benchmarks
✅ 6 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
test_response_req_text_from_json 213.2 µs 134.4 µs +58.66%
test_response_repr 196.4 µs 131.9 µs +48.91%
test_response_property_access 194.5 µs 131.6 µs +47.8%
test_response_json_parsing 205.6 µs 141.9 µs +44.83%
test_response_creation 201.3 µs 140.1 µs +43.64%
test_middleware_after_response 403.1 µs 355.9 µs +13.28%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing feat/sse (53ec719) with master (6f3d441)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (936008b) during the generation of this report, so 6f3d441 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@NEFORCEO
NEFORCEO merged commit e323c2e into master Jun 27, 2026
17 checks passed
@NEFORCEO
NEFORCEO deleted the feat/sse branch June 27, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants