aistore.sdk.obj.object_reader

View as Markdown

Module Contents

Classes

NameDescription
ObjectReaderProvide a way to read an object’s contents and attributes, optionally iterating over a stream of content.

API

class aistore.sdk.obj.object_reader.ObjectReader(
object_client: aistore.sdk.obj.object_client.ObjectClient,
chunk_size: typing.Optional[int] = None,
num_workers: typing.Optional[int] = None
)

Provide a way to read an object’s contents and attributes, optionally iterating over a stream of content.

Parameters:

object_client
ObjectClient

Client for making requests to a specific object in AIS

chunk_size
intDefaults to None

Size of each data chunk to be fetched from the stream. Defaults to DEFAULT_CHUNK_SIZE.

num_workers
intDefaults to None

If provided, use concurrent range-reads with this many workers.

_content_provider
attributes
ObjectAttributes

Object metadata attributes.

aistore.sdk.obj.object_reader.ObjectReader.__iter__() -> typing.Generator[bytes, None, None]

Make a request to get a stream from the provided object and yield chunks of the stream content.

Returns: None

Generator[bytes, None, None]: An iterator over each chunk of bytes in the object

aistore.sdk.obj.object_reader.ObjectReader._make_request(
stream: bool = True
) -> requests.Response

Use the object client to get a response from AIS and update the reader’s object attributes.

Parameters:

stream
boolDefaults to True

If True, use the requests library stream option to stream the response content. Defaults to True.

Returns: requests.Response

The response object from the request.

aistore.sdk.obj.object_reader.ObjectReader.as_file(
buffer_size: typing.Optional[int] = None,
max_resume: typing.Optional[int] = 5
) -> io.BufferedIOBase

Create a read-only, non-seekable ObjectFileReader instance for streaming object data in chunks. This file-like object primarily implements the read() method to retrieve data sequentially, with automatic retry/resumption in case of unexpected stream interruptions (e.g. ChunkedEncodingError, ConnectionError) or timeouts (e.g. ReadTimeout).

Parameters:

buffer_size
intDefaults to None

Currently unused; retained for backward compatibility and future enhancements.

max_resume
intDefaults to 5

Total number of retry attempts allowed to resume the stream in case of interruptions. Defaults to 5.

Returns: BufferedIOBase

A read-only, non-seekable file-like object for streaming object content.

Raises:

  • ValueError: If max_resume is invalid (must be a non-negative integer).
aistore.sdk.obj.object_reader.ObjectReader.head() -> aistore.sdk.obj.object_attributes.ObjectAttributes

Make a head request to AIS to update and return only object attributes.

Returns: ObjectAttributes

ObjectAttributes containing metadata for this object.

aistore.sdk.obj.object_reader.ObjectReader.raw() -> typing.Any

Return the raw byte stream of the object content.

Returns: Any

requests.Response.raw: Raw byte stream of the object content.

aistore.sdk.obj.object_reader.ObjectReader.read_all() -> typing.Union[bytes, aistore.sdk.obj.content_iterator.ParallelBuffer]

Read all object content into memory.

Returns: Union[bytes, ParallelBuffer]

When called without num_workers (single-stream GET).