> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/aistore/llms.txt.

# aistore.sdk.obj.object_reader

## Module Contents

### Classes

| Name                                                          | Description                                                                                               |
| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| [`ObjectReader`](#aistore-sdk-obj-object_reader-ObjectReader) | Provide a way to read an object's contents and attributes, optionally iterating over a stream of content. |

### API

```python
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`

[`ObjectClient`](/aistore/api-reference/python/aistore/sdk/obj/object_client#aistore-sdk-obj-object_client-ObjectClient) — Client for making requests to a specific object in AIS

---

**`chunk_size`** `int` — default: None

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

---

**`num_workers`** `int` — default: None

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

---

**`_content_provider`**

---

**`attributes`** `ObjectAttributes`

Object metadata attributes.

---

```python
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

```python
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`** `bool` — default: 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.

```python
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`** `int` — default: None

Currently unused; retained for backward compatibility and future
enhancements.

---

**`max_resume`** `int` — default: 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).

```python
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`](/aistore/api-reference/python/aistore/sdk/obj/object_attributes#aistore-sdk-obj-object_attributes-ObjectAttributes)

`ObjectAttributes` containing metadata for this object.

```python
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.

```python
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`](/aistore/api-reference/python/aistore/sdk/obj/content_iterator/buffer#aistore-sdk-obj-content_iterator-buffer-ParallelBuffer) `]`

When called without `num_workers` (single-stream GET).

```python
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.