Browse Source

📝 Update docs source example for streaming data

pull/15023/head
Sebastián Ramírez 5 months ago
parent
commit
f10968be60
  1. 26
      docs_src/stream_data/tutorial002_py310.py

26
docs_src/stream_data/tutorial002_py310.py

@ -22,23 +22,33 @@ class PNGStreamingResponse(StreamingResponse):
@app.get("/image/stream", response_class=PNGStreamingResponse) @app.get("/image/stream", response_class=PNGStreamingResponse)
async def stream_image() -> AsyncIterable[bytes]: async def stream_image() -> AsyncIterable[bytes]:
for chunk in read_image(): with read_image() as image_file:
yield chunk for chunk in image_file:
yield chunk
@app.get("/image/stream-no-async", response_class=PNGStreamingResponse) @app.get("/image/stream-no-async", response_class=PNGStreamingResponse)
def stream_image_no_async() -> Iterable[bytes]: def stream_image_no_async() -> Iterable[bytes]:
for chunk in read_image(): with read_image() as image_file:
yield chunk for chunk in image_file:
yield chunk
@app.get("/image/stream-no-async-yield-from", response_class=PNGStreamingResponse)
def stream_image_no_async_yield_from() -> Iterable[bytes]:
with read_image() as image_file:
yield from image_file
@app.get("/image/stream-no-annotation", response_class=PNGStreamingResponse) @app.get("/image/stream-no-annotation", response_class=PNGStreamingResponse)
async def stream_image_no_annotation(): async def stream_image_no_annotation():
for chunk in read_image(): with read_image() as image_file:
yield chunk for chunk in image_file:
yield chunk
@app.get("/image/stream-no-async-no-annotation", response_class=PNGStreamingResponse) @app.get("/image/stream-no-async-no-annotation", response_class=PNGStreamingResponse)
def stream_image_no_async_no_annotation(): def stream_image_no_async_no_annotation():
for chunk in read_image(): with read_image() as image_file:
yield chunk for chunk in image_file:
yield chunk

Loading…
Cancel
Save