Delete Module

Delete objects from S3 bucket.

s3_tools.delete.delete_keys(bucket: str, keys: List[str], dry_run: bool = True)None[source]

Delete all objects in the keys list from S3 bucket.

Parameters
  • bucket (str) – AWS S3 bucket where the objects are stored.

  • keys (List[str]) – List of object keys.

  • dry_run (bool) – If True will not delete the objects.

Examples

>>> delete_keys(
...     bucket="myBucket",
...     keys=[
...         "myData/myMusic/awesome.mp3",
...         "myData/myDocs/paper.doc"
...     ],
...     dry_run=False
... )
s3_tools.delete.delete_object(bucket: str, key: str)None[source]

Delete a given object from S3 bucket.

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

  • key (str) – Key for the object that will be deleted.

Examples

>>> delete_object(bucket="myBucket", key="myData/myFile.data")
s3_tools.delete.delete_prefix(bucket: str, prefix: str, dry_run: bool = True)Optional[List[str]][source]

Delete all objects under the given prefix from S3 bucket.

Parameters
  • bucket (str) – AWS S3 bucket where the objects are stored.

  • prefix (str) – Prefix where the objects are under.

  • dry_run (bool) – If True will not delete the objects.

Returns

List of S3 keys to be deleted if dry_run True, else None.

Return type

List[str]

Examples

>>> delete_prefix(bucket="myBucket", prefix="myData")
[
    "myData/myMusic/awesome.mp3",
    "myData/myDocs/paper.doc"
]
>>> delete_prefix(bucket="myBucket", prefix="myData", dry_run=False)