stream#

Stream processing utilities

Classes:

AsyncBinaryIterator

Any object that asynchronously yields bytes when iterated e.g..

AsyncBinaryIteratorIO

Similar to BinaryIteratorIO except the iterator yields bytes asynchronously

AsyncReadable

Any object that has an async read(size) method

AsyncWritable

Any object that has an async write(buffer) method

BinaryIteratorIO

Read through a iterator that yields bytes as if it was a file

Stream

Generic stream that that leaves handling of the stream data to the caller.

Streamable

class AsyncBinaryIterator#

Any object that asynchronously yields bytes when iterated e.g.:

async for chunk in obj:
    print(chunk.decode())

Methods:

__init__(*args, **kwargs)

__init__(*args, **kwargs)#
class AsyncBinaryIteratorIO#

Similar to BinaryIteratorIO except the iterator yields bytes asynchronously

Methods:

__init__(iter)

__init__(iter: AsyncBinaryIterator)#
class AsyncReadable#

Any object that has an async read(size) method

Methods:

__init__(*args, **kwargs)

__init__(*args, **kwargs)#
class AsyncWritable#

Any object that has an async write(buffer) method

Methods:

__init__(*args, **kwargs)

__init__(*args, **kwargs)#
class BinaryIteratorIO#

Read through a iterator that yields bytes as if it was a file

Methods:

__init__(iter)

__init__(iter: Iterator[bytes])#
class Stream#

Generic stream that that leaves handling of the stream data to the caller. May accept stream data in any streamable format, though async formats must be consumed with async functions.

Methods:

__init__()

from_async_stream(stream, *[, media_type])

Asynchronously load from the given binary stream.

load(file, *[, media_type])

Load stream from a file path or readable byte stream.

__init__(*, stream: IO[bytes] = None, media_type: str | None = None)#
__init__(*, iterator: Iterator[bytes] = None, media_type: str | None = None)
__init__(*, astream: AsyncReadable = None, media_type: str | None = None)
__init__(*, aiterator: AsyncBinaryIterator = None, media_type: str | None = None)
async classmethod from_async_stream(stream: AsyncReadable, *, media_type: str | None = None)#

Asynchronously load from the given binary stream. The given stream parameter must at least have async read(n: int | None) -> bytes method.

classmethod load(file: str | PurePath | IO[bytes], *, media_type: str | None = None)#

Load stream from a file path or readable byte stream. The stream must at least implement the read(size) function.

class Streamable#

Attributes:

media_type

May override in subclasses to derive correct stream type, e.g., "application/x-cryosparc-dataset"

Methods:

api_schema()

Schema to use when an API endpoint returns or requests this streamable instance in the request or response body.

from_async_stream(stream, *[, media_type])

Asynchronously load from the given binary stream.

load(file, *[, media_type])

Load stream from a file path or readable byte stream.

classmethod api_schema()#

Schema to use when an API endpoint returns or requests this streamable instance in the request or response body.

abstract async classmethod from_async_stream(stream: AsyncReadable, *, media_type: str | None = None) Self#

Asynchronously load from the given binary stream. The given stream parameter must at least have async read(n: int | None) -> bytes method.

abstract classmethod load(file: str | PurePath | IO[bytes], *, media_type: str | None = None) Self#

Load stream from a file path or readable byte stream. The stream must at least implement the read(size) function.

media_type = 'application/octet-stream'#

May override in subclasses to derive correct stream type, e.g., “application/x-cryosparc-dataset”