Skip to content

Reference

aios3.file

S3 "files" operations with aiobotocore.

Classes

Functions

aios3.file.chunks async

chunks(bucket: str, key: str, chunk_size: int | None = None, s3: AioBaseClient | None = None) -> AsyncGenerator[bytearray, None]

Generate file chunks chunk_size bytes max.

Parameters:

Name Type Description Default
bucket str

S3 bucket.

required
key str

path in the bucket including "file name".

required
chunk_size int | None

max number of bytes to read in one chunk. by default read file as one chunk.

None
s3 AioBaseClient | None

boto s3 client. by default it auto-created inside the function.

None
Return

Chunks of the file.

Raises:

Type Description
FileNotFoundError

If the S3 object does not exist.

ClientError

If other S3 operation fails.

aios3.file.read async

read(bucket: str, key: str, chunk_size: int | None = None, s3: AioBaseClient | None = None) -> bytes

Read the full content of the file as bytes.

Parameters:

Name Type Description Default
bucket str

S3 bucket.

required
key str

path in the bucket including "file name".

required
chunk_size int | None

max number of bytes to read in one chunk. by default read all.

None
s3 AioBaseClient | None

boto s3 client. by default it auto-created inside the function.

None
Return

The file content as bytes.

Raises:

Type Description
FileNotFoundError

If the S3 object does not exist.

ClientError

If other S3 operation fails.

aios3.file.save async

save(bucket: str, key: str, body: bytes, s3: AioBaseClient | None = None) -> None

Create the file with the body.

Parameters:

Name Type Description Default
bucket str

S3 bucket.

required
key str

path in the bucket including "file name".

required
body bytes

content to write into file.

required
s3 AioBaseClient | None

boto s3 client. by default it auto-created inside the function.

None

Raises:

Type Description
ClientError

If S3 operation fails.

aios3.file.stream async

stream(bucket: str, key: str, chunk_size: int | None = None, s3: AioBaseClient | None = None) -> IO[bytes]

Create file-like object to stream the file content.

Note: This function loads all chunks into memory to create a synchronous stream. For true streaming without loading all data into memory, use the chunks() function directly.

Parameters:

Name Type Description Default
bucket str

S3 bucket.

required
key str

path in the bucket including "file name".

required
chunk_size int | None

max number of bytes to read in one chunk. by default read file as one chunk.

None
s3 AioBaseClient | None

boto s3 client. by default it auto-created inside the function.

None
Return

Python file stream with the file content.

Raises:

Type Description
FileNotFoundError

If the S3 object does not exist.

ClientError

If other S3 operation fails.