Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 1 - 10 of 17 for EventSourceResponse (0.25 seconds)

The search processing time has exceeded the limit. The displayed results may be partial.

  1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. docs/ko/docs/tutorial/server-sent-events.md

    ///
    
    ## FastAPI로 SSE 스트리밍 { #stream-sse-with-fastapi }
    
    FastAPI에서 SSE를 스트리밍하려면, 경로 처리 함수에서 `yield`를 사용하고 `response_class=EventSourceResponse`를 설정하세요.
    
    `EventSourceResponse`는 `fastapi.sse`에서 임포트합니다:
    
    {* ../../docs_src/server_sent_events/tutorial001_py310.py ln[1:25] hl[4,22] *}
    
    각 `yield`된 항목은 JSON으로 인코딩되어 SSE 이벤트의 `data:` 필드로 전송됩니다.
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 19 18:56:39 GMT 2026
    - 5.3K bytes
    - Click Count (0)
  9. docs/zh-hant/docs/tutorial/server-sent-events.md

    ///
    
    ## 使用 FastAPI 串流 SSE { #stream-sse-with-fastapi }
    
    要在 FastAPI 中串流 SSE,請在你的路徑操作函式(path operation function)中使用 `yield`,並設定 `response_class=EventSourceResponse`。
    
    從 `fastapi.sse` 匯入 `EventSourceResponse`:
    
    {* ../../docs_src/server_sent_events/tutorial001_py310.py ln[1:25] hl[4,22] *}
    
    每個 `yield` 的項目都會以 JSON 編碼並放在 SSE 事件的 `data:` 欄位中送出。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:33:04 GMT 2026
    - 4.6K bytes
    - Click Count (0)
  10. docs/zh/docs/tutorial/server-sent-events.md

    如果你想流式传输二进制数据(例如视频或音频),请查看高级指南:[流式传输数据](../advanced/stream-data.md)。
    
    ///
    
    ## 使用 FastAPI 流式传输 SSE { #stream-sse-with-fastapi }
    
    要在 FastAPI 中流式传输 SSE,在你的*路径操作函数*中使用 `yield`,并设置 `response_class=EventSourceResponse`。
    
    从 `fastapi.sse` 导入 `EventSourceResponse`:
    
    {* ../../docs_src/server_sent_events/tutorial001_py310.py ln[1:25] hl[4,22] *}
    
    每个被 yield 的项会被编码为 JSON,并放入 SSE 事件的 `data:` 字段发送。
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 14:29:48 GMT 2026
    - 4.6K bytes
    - Click Count (0)
Back to Top