Skip to navigation

aistore.sdk.obj.object_reader

View as MarkdownOpen in Claude

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(
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

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: 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

Maximum consecutive attempts to resume the stream after interruptions without forward progress. 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.

Deprecated

Will be removed in 3.0. Use stream() instead to access the full response and response.raw.

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).

aistore.sdk.obj.object_reader.ObjectReader.stream() -> requests.Response

Return the full response with an open stream of object content.

The caller must close the response when finished, preferably using a context manager. Access headers, raw bytes via response.raw, or chunks via response.iter_content().

Example

>>> with obj.get_reader().stream() as response: … data = response.raw.read()

Returns: requests.Response

requests.Response: Response requested with stream=True.