Skip to content

Stream class

esmerald.datastructures.stream.Stream

Bases: ResponseContainer[StreamingResponse]

iterator instance-attribute

iterator

Any iterable function.

to_response

to_response(headers, media_type, status_code, app)
PARAMETER DESCRIPTION
headers

TYPE: Dict[str, Any]

media_type

TYPE: Union[MediaType, str]

status_code

TYPE: int

app

TYPE: Type[Esmerald]

Source code in esmerald/datastructures/stream.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def to_response(
    self,
    headers: Dict[str, Any],
    media_type: Union["MediaType", str],
    status_code: int,
    app: Type["Esmerald"],
) -> StreamingResponse:  # pragma: no cover
    return StreamingResponse(
        background=self.background,
        content=(
            self.iterator
            if isinstance(self.iterator, (Iterable, AsyncIterable))
            else self.iterator()
        ),
        headers=headers,
        media_type=media_type,
        status_code=status_code,
    )