aistore.sdk.obj.object_writer

View as MarkdownOpen in Claude

Module Contents

Classes

NameDescription
ObjectWriterProvide a way to write an object’s contents and attributes.

API

class aistore.sdk.obj.object_writer.ObjectWriter(
client: aistore.sdk.request_client.RequestClient,
object_path: str,
query_params: typing.Dict[str, str]
)

Provide a way to write an object’s contents and attributes.

aistore.sdk.obj.object_writer.ObjectWriter._put_data(
data
) -> requests.Response
aistore.sdk.obj.object_writer.ObjectWriter.append_content(
content: bytes,
handle: str = '',
flush: bool = False
) -> str

Append bytes as an object to a bucket in AIS storage.

Parameters:

content
bytes

Bytes to append to the object.

handle
strDefaults to ''

Handle string to use for subsequent appends or flush (empty for the first append).

flush
boolDefaults to False

Whether to flush and finalize the append operation, making the object accessible.

Returns: str

Handle string to pass for subsequent appends or flush.

Raises:

  • requests.RequestException: “There was an ambiguous exception that occurred while handling…”
  • requests.ConnectionError: Connection error
  • requests.ConnectionTimeout: Timed out connecting to AIStore
  • requests.ReadTimeout: Timed out waiting response from AIStore
  • requests.exceptions.HTTPError(404): The object does not exist
aistore.sdk.obj.object_writer.ObjectWriter.as_file(
mode: str = 'a'
) -> aistore.sdk.obj.obj_file.object_file.ObjectFileWriter

Return a file-like object for writing object data.

Parameters:

mode
strDefaults to 'a'

Specifies the mode in which the file is opened (defaults to ‘a’).

- `'w'`

Write mode. Opens the object for writing, truncating any existing content. Writing starts from the beginning of the object.

- `'a'`

Append mode. Opens the object for appending. Existing content is preserved, and writing starts from the end of the object.

Returns: ObjectFileWriter

A file-like object for writing object data.

Raises:

  • ValueError: Invalid mode provided.
aistore.sdk.obj.object_writer.ObjectWriter.put_content(
content: bytes
) -> requests.Response

Puts bytes as an object to a bucket in AIS storage.

Parameters:

content
bytes

Bytes to put as an object.

Raises:

  • requests.RequestException: “There was an ambiguous exception that occurred while handling…”
  • requests.ConnectionError: Connection error
  • requests.ConnectionTimeout: Timed out connecting to AIStore
  • requests.ReadTimeout: Timed out waiting response from AIStore
aistore.sdk.obj.object_writer.ObjectWriter.put_file(
path: str or Path
) -> requests.Response

Puts a local file as an object to a bucket in AIS storage.

Parameters:

path
str or Path

Path to local file

Raises:

  • requests.RequestException: “There was an ambiguous exception that occurred while handling…”
  • requests.ConnectionError: Connection error
  • requests.ConnectionTimeout: Timed out connecting to AIStore
  • requests.ReadTimeout: Timed out waiting response from AIStore
  • ValueError: The path provided is not a valid file
aistore.sdk.obj.object_writer.ObjectWriter.set_custom_props(
custom_metadata: typing.Dict[str, str],
replace_existing: bool = False
) -> requests.Response

Set custom properties for the object.

Parameters:

custom_metadata
Dict[str, str]

Custom metadata key-value pairs.

replace_existing
boolDefaults to False

Whether to replace existing metadata. Defaults to False.