diff --git a/docs/en/docs/reference/sse.md b/docs/en/docs/reference/sse.md new file mode 100644 index 000000000..5b447af53 --- /dev/null +++ b/docs/en/docs/reference/sse.md @@ -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 diff --git a/docs/en/mkdocs.yml b/docs/en/mkdocs.yml index 884307dcf..5de3f65a3 100644 --- a/docs/en/mkdocs.yml +++ b/docs/en/mkdocs.yml @@ -213,6 +213,7 @@ nav: - reference/httpconnection.md - reference/response.md - reference/responses.md + - reference/sse.md - reference/middleware.md - "": - reference/openapi/index.md