Read Module

Read S3 objects into variables.

s3_tools.read.read_object_to_bytes(bucket: str, key: str)bytes[source]

Retrieve one object from AWS S3 bucket as a byte array.

Parameters
  • bucket (str) – AWS S3 bucket where the object is stored.

  • key (str) – Key where the object is stored.

Returns

Object content as bytes.

Return type

bytes

Raises

KeyError – When the key ‘Body’ is missing on the response.

Examples

>>> read_object_to_bytes(
...     bucket="myBucket",
...     key="myData/myFile.data"
... )
b"The file content"
s3_tools.read.read_object_to_dict(bucket: str, key: str)Dict[source]

Retrieve one object from AWS S3 bucket as a dictionary.

Parameters
  • bucket (str) – AWS S3 bucket where the object is stored.

  • key (str) – Key where the object is stored.

Returns

Object content as dictionary.

Return type

dict

Examples

>>> read_object_to_dict(
...     bucket="myBucket",
...     key="myData/myFile.json"
... )
{"key": "value", "1": "text"}
s3_tools.read.read_object_to_text(bucket: str, key: str)str[source]

Retrieve one object from AWS S3 bucket as a string.

Parameters
  • bucket (str) – AWS S3 bucket where the object is stored.

  • key (str) – Key where the object is stored.

Returns

Object content as string.

Return type

str

Examples

>>> read_object_to_text(
...     bucket="myBucket",
...     key="myData/myFile.data"
... )
"The file content"