- Sort Score
- Num 10 results
- Language All
Results 1 - 10 of 23 for EventSourceResponse (0.19 seconds)
-
tests/test_sse.py
app = FastAPI() @app.get("/items/stream", response_class=EventSourceResponse) async def sse_items() -> AsyncIterable[Item]: for item in items: yield item @app.get("/items/stream-sync", response_class=EventSourceResponse) def sse_items_sync() -> Iterable[Item]: yield from items @app.get("/items/stream-no-annotation", response_class=EventSourceResponse) async def sse_items_no_annotation(): for item in items:
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Mar 01 09:21:52 GMT 2026 - 9.8K bytes - Click Count (0) -
fastapi/.agents/skills/fastapi/references/streaming.md
To stream Server-Sent Events, use `response_class=EventSourceResponse` and `yield` items from the endpoint. Plain objects are automatically JSON-serialized as `data:` fields, declare the return type so the serialization is done by Pydantic: ```python from collections.abc import AsyncIterable from fastapi import FastAPI from fastapi.sse import EventSourceResponse from pydantic import BaseModel app = FastAPI()
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Mar 01 10:05:57 GMT 2026 - 2.5K bytes - Click Count (0) -
docs_src/server_sent_events/tutorial001_py310.py
@app.get("/items/stream", response_class=EventSourceResponse) async def sse_items() -> AsyncIterable[Item]: for item in items: yield item @app.get("/items/stream-no-async", response_class=EventSourceResponse) def sse_items_no_async() -> Iterable[Item]: for item in items: yield item @app.get("/items/stream-no-annotation", response_class=EventSourceResponse) async def sse_items_no_annotation():
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Mar 01 09:21:52 GMT 2026 - 1.1K bytes - Click Count (0) -
docs_src/server_sent_events/tutorial002_py310.py
from collections.abc import AsyncIterable from fastapi import FastAPI from fastapi.sse import EventSourceResponse, ServerSentEvent from pydantic import BaseModel app = FastAPI() class Item(BaseModel): name: str price: float items = [ Item(name="Plumbus", price=32.99), Item(name="Portal Gun", price=999.99), Item(name="Meeseeks Box", price=49.99), ]
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Mar 01 09:21:52 GMT 2026 - 686 bytes - Click Count (0) -
docs_src/server_sent_events/tutorial004_py310.py
from collections.abc import AsyncIterable from typing import Annotated from fastapi import FastAPI, Header from fastapi.sse import EventSourceResponse, ServerSentEvent from pydantic import BaseModel app = FastAPI() class Item(BaseModel): name: str price: float items = [ Item(name="Plumbus", price=32.99), Item(name="Portal Gun", price=999.99), Item(name="Meeseeks Box", price=49.99), ]
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Mar 01 09:21:52 GMT 2026 - 795 bytes - Click Count (0) -
docs_src/server_sent_events/tutorial003_py310.py
from collections.abc import AsyncIterable from fastapi import FastAPI from fastapi.sse import EventSourceResponse, ServerSentEvent app = FastAPI() @app.get("/logs/stream", response_class=EventSourceResponse) async def stream_logs() -> AsyncIterable[ServerSentEvent]: logs = [ "2025-01-01 INFO Application started", "2025-01-01 DEBUG Connected to database", "2025-01-01 WARN High memory usage detected", ]
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Mar 01 09:21:52 GMT 2026 - 518 bytes - Click Count (0) -
docs_src/server_sent_events/tutorial005_py310.py
from collections.abc import AsyncIterable from fastapi import FastAPI from fastapi.sse import EventSourceResponse, ServerSentEvent from pydantic import BaseModel app = FastAPI() class Prompt(BaseModel): text: str @app.post("/chat/stream", response_class=EventSourceResponse) async def stream_chat(prompt: Prompt) -> AsyncIterable[ServerSentEvent]: words = prompt.text.split() for word in words:
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Mar 01 09:21:52 GMT 2026 - 528 bytes - Click Count (0) -
fastapi/sse.py
"event": {"type": "string"}, "id": {"type": "string"}, "retry": {"type": "integer", "minimum": 0}, }, } class EventSourceResponse(StreamingResponse): """Streaming response with `text/event-stream` media type. Use as `response_class=EventSourceResponse` on a *path operation* that uses `yield` to enable Server Sent Events (SSE) responses.
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Mar 01 09:21:52 GMT 2026 - 6.2K bytes - Click Count (0) -
fastapi/responses.py
from typing import Any from fastapi.exceptions import FastAPIDeprecationWarning from fastapi.sse import EventSourceResponse as EventSourceResponse # noqa from starlette.responses import FileResponse as FileResponse # noqa from starlette.responses import HTMLResponse as HTMLResponse # noqa from starlette.responses import JSONResponse as JSONResponse # noqa from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Mar 01 09:21:52 GMT 2026 - 3.6K bytes - Click Count (0) -
docs/en/docs/tutorial/server-sent-events.md
/// ## Stream SSE with FastAPI { #stream-sse-with-fastapi } To stream SSE with FastAPI, use `yield` in your *path operation function* and set `response_class=EventSourceResponse`. Import `EventSourceResponse` from `fastapi.sse`: {* ../../docs_src/server_sent_events/tutorial001_py310.py ln[1:25] hl[4,22] *} Each yielded item is encoded as JSON and sent in the `data:` field of an SSE event.Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Mar 05 18:13:19 GMT 2026 - 4.6K bytes - Click Count (0)