]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Add API reference page for fastapi.sse (#15930)
authorSaurabh Vijay Salve <90780335+SAURABHSALVE@users.noreply.github.com>
Tue, 28 Jul 2026 15:08:21 +0000 (20:38 +0530)
committerGitHub <noreply@github.com>
Tue, 28 Jul 2026 15:08:21 +0000 (17:08 +0200)
Co-authored-by: Cursor <cursoragent@cursor.com>
docs/en/docs/reference/sse.md [new file with mode: 0644]
docs/en/mkdocs.yml

diff --git a/docs/en/docs/reference/sse.md b/docs/en/docs/reference/sse.md
new file mode 100644 (file)
index 0000000..5b447af
--- /dev/null
@@ -0,0 +1,17 @@
+# Server-Sent Events - `EventSourceResponse` and `ServerSentEvent`
+
+To stream Server-Sent Events (SSE), use `yield` in your *path operation function* and set `response_class=EventSourceResponse`.
+
+If you need to set SSE fields like `event`, `id`, `retry`, or `comment`, you can `yield` `ServerSentEvent` objects instead of plain data.
+
+Read more about it in the [FastAPI docs for Server-Sent Events (SSE)](https://fastapi.tiangolo.com/tutorial/server-sent-events/).
+
+You can import them directly from `fastapi.sse`:
+
+```python
+from fastapi.sse import EventSourceResponse, ServerSentEvent
+```
+
+::: fastapi.sse.EventSourceResponse
+
+::: fastapi.sse.ServerSentEvent
index 0a762a40d4d39298c7ee7d72805b0940bd01dba6..9bcdbd652d71fc8b8a994019e6fddd7b3d125441 100644 (file)
@@ -211,6 +211,7 @@ nav:
   - reference/httpconnection.md
   - reference/response.md
   - reference/responses.md
+  - reference/sse.md
   - reference/middleware.md
   - "":
     - reference/openapi/index.md