Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 10 for StreamingResponse (0.2 sec)

  1. tests/test_dependency_yield_scope.py

        def iter_data():
            yield json.dumps({"is_open": session.open})
    
        return StreamingResponse(iter_data())
    
    
    @app.get("/request-scope")
    def request_scope(session: SessionRequestDep) -> Any:
        def iter_data():
            yield json.dumps({"is_open": session.open})
    
        return StreamingResponse(iter_data())
    
    
    @app.get("/two-scopes")
    def get_stream_session(
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 21:25:59 UTC 2025
    - 6.7K bytes
    - Viewed (0)
  2. fastapi/responses.py

    from starlette.responses import RedirectResponse as RedirectResponse  # noqa
    from starlette.responses import Response as Response  # noqa
    from starlette.responses import StreamingResponse as StreamingResponse  # noqa
    
    try:
        import ujson
    except ImportError:  # pragma: nocover
        ujson = None  # type: ignore
    
    
    try:
        import orjson
    except ImportError:  # pragma: nocover
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Oct 18 12:36:40 UTC 2023
    - 1.7K bytes
    - Viewed (0)
  3. docs/en/docs/reference/responses.md

    ```python
    from fastapi.responses import (
        FileResponse,
        HTMLResponse,
        JSONResponse,
        ORJSONResponse,
        PlainTextResponse,
        RedirectResponse,
        Response,
        StreamingResponse,
        UJSONResponse,
    )
    ```
    
    ## FastAPI Responses
    
    There are a couple of custom FastAPI response classes, you can use them to optimize JSON performance.
    
    ::: fastapi.responses.UJSONResponse
        options:
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Thu Apr 18 19:53:19 UTC 2024
    - 3.7K bytes
    - Viewed (0)
  4. docs_src/custom_response/tutorial008_py39.py

    from fastapi import FastAPI
    from fastapi.responses import StreamingResponse
    
    some_file_path = "large-video-file.mp4"
    app = FastAPI()
    
    
    @app.get("/")
    def main():
        def iterfile():  # (1)
            with open(some_file_path, mode="rb") as file_like:  # (2)
                yield from file_like  # (3)
    
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 360 bytes
    - Viewed (0)
  5. tests/test_dependency_after_yield_streaming.py

    def get_stream_simple(session: SessionDep) -> Any:
        def iter_data():
            yield from ["x", "y", "z"]
    
        return StreamingResponse(iter_data())
    
    
    @app.get("/stream-session")
    def get_stream_session(session: SessionDep) -> Any:
        def iter_data():
            yield from session
    
        return StreamingResponse(iter_data())
    
    
    @app.get("/broken-session-data")
    def get_broken_session_data(session: BrokenSessionDep) -> Any:
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 21:25:59 UTC 2025
    - 3.2K bytes
    - Viewed (0)
  6. docs_src/custom_response/tutorial007_py39.py

    from fastapi import FastAPI
    from fastapi.responses import StreamingResponse
    
    app = FastAPI()
    
    
    async def fake_video_streamer():
        for i in range(10):
            yield b"some fake video bytes"
    
    
    @app.get("/")
    async def main():
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 277 bytes
    - Viewed (0)
  7. docs_src/dependencies/tutorial013_an_py310.py

    import time
    from typing import Annotated
    
    from fastapi import Depends, FastAPI, HTTPException
    from fastapi.responses import StreamingResponse
    from sqlmodel import Field, Session, SQLModel, create_engine
    
    engine = create_engine("postgresql+psycopg://postgres:postgres@localhost/db")
    
    
    class User(SQLModel, table=True):
        id: int | None = Field(default=None, primary_key=True)
        name: str
    
    
    app = FastAPI()
    
    
    def get_session():
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Mon Sep 29 03:29:38 UTC 2025
    - 937 bytes
    - Viewed (0)
  8. docs_src/dependencies/tutorial014_an_py310.py

    import time
    from typing import Annotated
    
    from fastapi import Depends, FastAPI, HTTPException
    from fastapi.responses import StreamingResponse
    from sqlmodel import Field, Session, SQLModel, create_engine
    
    engine = create_engine("postgresql+psycopg://postgres:postgres@localhost/db")
    
    
    class User(SQLModel, table=True):
        id: int | None = Field(default=None, primary_key=True)
        name: str
    
    
    app = FastAPI()
    
    
    def get_session():
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Mon Sep 29 03:29:38 UTC 2025
    - 957 bytes
    - Viewed (0)
  9. docs/en/docs/advanced/advanced-dependencies.md

    ### Dependencies with `yield` and `StreamingResponse`, Technical Details { #dependencies-with-yield-and-streamingresponse-technical-details }
    
    Before FastAPI 0.118.0, if you used a dependency with `yield`, it would run the exit code after the *path operation function* returned but right before sending the response.
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Thu Nov 13 07:37:15 UTC 2025
    - 9.1K bytes
    - Viewed (0)
  10. docs/zh/docs/advanced/custom-response.md

    返回 HTTP 重定向。默认情况下使用 307 状态代码(临时重定向)。
    
    {* ../../docs_src/custom_response/tutorial006.py hl[2,9] *}
    
    ### `StreamingResponse`
    
    采用异步生成器或普通生成器/迭代器,然后流式传输响应主体。
    
    {* ../../docs_src/custom_response/tutorial007.py hl[2,14] *}
    
    #### 对类似文件的对象使用 `StreamingResponse`
    
    如果您有类似文件的对象(例如,由 `open()` 返回的对象),则可以在 `StreamingResponse` 中将其返回。
    
    包括许多与云存储,视频处理等交互的库。
    
    {* ../../docs_src/custom_response/tutorial008.py hl[2,10:12,14] *}
    
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Mon Nov 18 02:25:44 UTC 2024
    - 7.5K bytes
    - Viewed (0)
Back to top