nemo_microservices._streaming#

Module Contents#

Classes#

AsyncStream

Provides the core interface to iterate over an asynchronous stream response.

SSEBytesDecoder

SSEDecoder

ServerSentEvent

Stream

Provides the core interface to iterate over a synchronous stream response.

Functions#

extract_stream_chunk_type

Given a type like Stream[T], returns the generic type variable T.

is_stream_class_type

TypeGuard for determining whether or not the given type is a subclass of Stream / AsyncStream

API#

class nemo_microservices._streaming.AsyncStream(
*,
cast_to: type[nemo_microservices._streaming._T],
response: httpx.Response,
client: nemo_microservices._client.AsyncNeMoMicroservices,
)#

Bases: typing.Generic[nemo_microservices._streaming._T]

Provides the core interface to iterate over an asynchronous stream response.

Initialization

async close() None#

Close the response and release the connection.

Automatically called if the response body is read to completion.

response: httpx.Response#

None

class nemo_microservices._streaming.SSEBytesDecoder#

Bases: typing_extensions.Protocol

aiter_bytes(
iterator: AsyncIterator[bytes],
) AsyncIterator[nemo_microservices._streaming.ServerSentEvent]#

Given an async iterator that yields raw binary data, iterate over it & yield every event encountered

iter_bytes(
iterator: Iterator[bytes],
) Iterator[nemo_microservices._streaming.ServerSentEvent]#

Given an iterator that yields raw binary data, iterate over it & yield every event encountered

class nemo_microservices._streaming.SSEDecoder#

Initialization

async aiter_bytes(
iterator: AsyncIterator[bytes],
) AsyncIterator[nemo_microservices._streaming.ServerSentEvent]#

Given an iterator that yields raw binary data, iterate over it & yield every event encountered

decode(
line: str,
) nemo_microservices._streaming.ServerSentEvent | None#
iter_bytes(
iterator: Iterator[bytes],
) Iterator[nemo_microservices._streaming.ServerSentEvent]#

Given an iterator that yields raw binary data, iterate over it & yield every event encountered

class nemo_microservices._streaming.ServerSentEvent(
*,
event: str | None = None,
data: str | None = None,
id: str | None = None,
retry: int | None = None,
)#

Initialization

property data: str#
property event: str | None#
property id: str | None#
json() Any#
property retry: int | None#
class nemo_microservices._streaming.Stream(
*,
cast_to: type[nemo_microservices._streaming._T],
response: httpx.Response,
client: nemo_microservices._client.NeMoMicroservices,
)#

Bases: typing.Generic[nemo_microservices._streaming._T]

Provides the core interface to iterate over a synchronous stream response.

Initialization

close() None#

Close the response and release the connection.

Automatically called if the response body is read to completion.

response: httpx.Response#

None

nemo_microservices._streaming.extract_stream_chunk_type(
stream_cls: type,
*,
failure_message: str | None = None,
) type#

Given a type like Stream[T], returns the generic type variable T.

This also handles the case where a concrete subclass is given, e.g.

class MyStream(Stream[bytes]):
    ...

extract_stream_chunk_type(MyStream) -> bytes
nemo_microservices._streaming.is_stream_class_type(
typ: type,
) typing_extensions.TypeGuard[type[nemo_microservices._streaming.Stream[object]] | type[nemo_microservices._streaming.AsyncStream[object]]]#

TypeGuard for determining whether or not the given type is a subclass of Stream / AsyncStream