Write Module

Write variables into S3 objects.

s3_tools.write.write_object_from_bytes(bucket: str, key: str, data: bytes)str[source]

Upload a bytes object to an object into AWS S3 bucket.

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

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

  • data (bytes) – The object data to be uploaded to AWS S3.

Returns

The S3 full URL to the file.

Return type

str

Raises

TypeError – If data is not a bytes type.

Examples

>>> data = bytes("String to bytes", "utf-8")
>>> write_object_from_bytes(
...     bucket="myBucket",
...     key="myFiles/file.data",
...     data=data
... )
http://s3.amazonaws.com/myBucket/myFiles/file.data
s3_tools.write.write_object_from_dict(bucket: str, key: str, data: Dict)str[source]

Upload a dictionary to an object into AWS S3 bucket.

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

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

  • data (dict) – The object data to be uploaded to AWS S3.

Returns

The S3 full URL to the file.

Return type

str

Raises

TypeError – If data is not a dict type.

Examples

>>> data = {"key": "value", "1": "text"}
>>> write_object_from_dict(
...     bucket="myBucket",
...     key="myFiles/file.json",
...     data=data
... )
http://s3.amazonaws.com/myBucket/myFiles/file.json
s3_tools.write.write_object_from_text(bucket: str, key: str, data: str)str[source]

Upload a string to an object into AWS S3 bucket.

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

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

  • data (str) – The object data to be uploaded to AWS S3.

Returns

The S3 full URL to the file.

Return type

str

Raises

TypeError – If data is not a str type.

Examples

>>> data = "A very very not so long text"
>>> write_object_from_text(
...     bucket="myBucket",
...     key="myFiles/file.txt",
...     data=data
... )
http://s3.amazonaws.com/myBucket/myFiles/file.txt