All Products
Search
Document Center

Object Storage Service:Data type in OSS Connector

Last Updated:Mar 20, 2026

DataObject is a file-like object in OSS Connector for AI/ML that provides I/O access to OSS objects.

Note

DataObject supports only read-only or write-only mode—not both simultaneously. Read-only mode supports sequential read and random read. Write-only mode supports sequential write only.

Mode overview

Methods are mode-specific. The following table shows availability by mode:

MethodRead-onlyWrite-only
tellYes
seekYes
readYes
readintoYes
writeYes
closeYesYes

Class definition

class DataObject:
    key: str
    size: int
    label: str

    def __enter__(self) -> DataObject: ...
    def __exit__(self, exc_type, exc_val, exc_tb): ...
    def tell(self) -> int: ...
    def seek(self, offset: int, whence: int) -> int: ...
    def read(self, count: int) -> bytes: ...
    def readinto(self, buf) -> int: ...
    def write(self, data) -> int: ...
    def close(self) -> int: ...
    def copy(self) -> DataObject: ...

Properties

PropertyTypeDescription
keystrThe unique identifier of the object.
sizeintThe actual size of the object, in bytes.
labelstrThe tags associated with the object, used for classification or labeling.

Methods

Context manager methods

MethodReturn typeDescription
__enter__DataObjectEnters the context manager and initializes the DataObject instance.
__exit__NoneExits the context manager and releases resources.

Read-only methods

MethodReturn typeDescription
tellintReturns the current file pointer position in read-only mode, in bytes.
seek(offset, whence)intSpecifies the file pointer position in read-only mode, in bytes.
read(count)bytesReads the specified number of bytes from the current file pointer position in read-only mode.
readinto(buf)intReads bytes from the current file pointer position into a buffer in read-only mode. Returns the number of bytes read.

Write-only methods

MethodReturn typeDescription
write(data)intWrites data to the current file pointer position in write-only mode. Returns the number of bytes written.

Common methods

MethodReturn typeDescription
closeintCloses the object and releases related resources.
copyDataObjectCreates a new DataObject instance with all attributes of the current instance.