Coverage for docs_src / stream_json_lines / tutorial001_py310.py: 100%
24 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1from collections.abc import AsyncIterable, Iterable 1afgbcde
3from fastapi import FastAPI 1afgbcde
4from pydantic import BaseModel 1afgbcde
6app = FastAPI() 1afgbcde
9class Item(BaseModel): 1afgbcde
10 name: str 1abcde
11 description: str | None 1abcde
14items = [ 1afgbcde
15 Item(name="Plumbus", description="A multi-purpose household device."),
16 Item(name="Portal Gun", description="A portal opening device."),
17 Item(name="Meeseeks Box", description="A box that summons a Meeseeks."),
18]
21@app.get("/items/stream") 1afgbcde
22async def stream_items() -> AsyncIterable[Item]: 1afgbcde
23 for item in items: 1hijk
24 yield item 1hijk
27@app.get("/items/stream-no-async") 1afgbcde
28def stream_items_no_async() -> Iterable[Item]: 1afgbcde
29 for item in items: 1lmno
30 yield item 1lmno
33@app.get("/items/stream-no-annotation") 1afgbcde
34async def stream_items_no_annotation(): 1afgbcde
35 for item in items: 1pqrs
36 yield item 1pqrs
39@app.get("/items/stream-no-async-no-annotation") 1afgbcde
40def stream_items_no_async_no_annotation(): 1afgbcde
41 for item in items: 1tuvw
42 yield item 1tuvw