StreamResponse Class

Wraps a streaming body for a User Data Function.

Constructor

StreamResponse(content: Iterable[bytes] | Iterator[bytes] | AsyncIterable[bytes] | AsyncIterator[bytes] | Iterable[str] | AsyncIterable[str], *, media_type: str = 'application/octet-stream', status_code: int = 200, headers: Mapping[str, str] | None = None)

Parameters

Name Description
content
Required

An iterator/iterable (sync or async) yielding bytes or str chunks. Each chunk is flushed to the client as it is produced.

media_type
Required
str

The Content-Type of the streamed body. Defaults to application/octet-stream (suitable for an Apache Arrow IPC stream).

status_code
Required
int

The HTTP status code. Defaults to 200.

headers
Required

Optional extra response headers.

Keyword-Only Parameters

Name Description
media_type
Default value: application/octet-stream
status_code
Default value: 200
headers
Default value: None

Methods

from_arrow_batches

Build a StreamResponse that emits an Apache Arrow IPC stream incrementally, one record batch at a time, without buffering the whole table in memory.

from_arrow_batches

Build a StreamResponse that emits an Apache Arrow IPC stream incrementally, one record batch at a time, without buffering the whole table in memory.

static from_arrow_batches(batches: Any, *, schema: Any = None, media_type: str = 'application/octet-stream', status_code: int = 200, headers: Mapping[str, str] | None = None) -> StreamResponse

Parameters

Name Description
batches
Required

An iterable of pyarrow.RecordBatch (or a pyarrow.RecordBatchReader). When a reader is passed its schema is used automatically.

schema
Required

The pyarrow.Schema to write. Required when batches is a plain iterable of record batches and schema cannot be inferred from the first batch.

Keyword-Only Parameters

Name Description
schema
Default value: None
media_type
Default value: application/octet-stream
status_code
Default value: 200
headers
Default value: None