stream_response Module

This module defines <xref:StreamResponse>, the return type used to make a User Data Function return a fully streamed HTTP response instead of a single buffered body.

Import it from fabric.functions and return it from a function decorated with streaming_function::

import fabric.functions as fn


udf = fn.UserDataFunctions()


@udf.streaming_function()
def stream_numbers(count: int) -> fn.StreamResponse:
    def gen():
        for i in range(count):
            yield f"chunk {i}\n".encode()
    return fn.StreamResponse(gen(), media_type="text/plain")

Unlike the classic return types (dict, str, a pandas DataFrame ...) which the worker materializes in full before replying, a StreamResponse wraps an iterator (or async iterator) of chunks that are flushed to the client as they are produced. This is what enables true HTTP streaming end to end (e.g. relaying an Apache Arrow stream from Power BI executeDaxQueries).

.. important:: Streaming relies on the Azure Functions HTTP streams feature (azurefunctions-extensions-http-fastapi). When any streaming function is present the function app runs in ASGI mode app-wide, so a streaming app cannot also host classic buffered User Data Functions. See streaming_function.

Classes

StreamResponse

Wraps a streaming body for a User Data Function.