Skip to content

Commit 4f0152c

Browse files
📝 Add API reference page for fastapi.sse (#15930)
Co-authored-by: Cursor <[email protected]>
1 parent 5f25505 commit 4f0152c

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

docs/en/docs/reference/sse.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Server-Sent Events - `EventSourceResponse` and `ServerSentEvent`
2+
3+
To stream Server-Sent Events (SSE), use `yield` in your *path operation function* and set `response_class=EventSourceResponse`.
4+
5+
If you need to set SSE fields like `event`, `id`, `retry`, or `comment`, you can `yield` `ServerSentEvent` objects instead of plain data.
6+
7+
Read more about it in the [FastAPI docs for Server-Sent Events (SSE)](https://fastapi.tiangolo.com/tutorial/server-sent-events/).
8+
9+
You can import them directly from `fastapi.sse`:
10+
11+
```python
12+
from fastapi.sse import EventSourceResponse, ServerSentEvent
13+
```
14+
15+
::: fastapi.sse.EventSourceResponse
16+
17+
::: fastapi.sse.ServerSentEvent

docs/en/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ nav:
211211
- reference/httpconnection.md
212212
- reference/response.md
213213
- reference/responses.md
214+
- reference/sse.md
214215
- reference/middleware.md
215216
- "":
216217
- reference/openapi/index.md

0 commit comments

Comments
 (0)