delete_object

Improve the delete_object API.

s3pathlib.better_client.delete_object.delete_object(s3_client: S3Client, bucket: str, key: str, version_id: str = OPT, mfa: str = OPT, request_payer: str = OPT, bypass_governance_retention: bool = OPT, expected_bucket_owner: str = OPT, ignore_not_found: bool = False) DeleteObjectOutputTypeDef | None[source]

Wrapper of delete_object.

Parameters:
Returns:

See delete_object.

s3pathlib.better_client.delete_object.delete_dir(s3_client, bucket: str, prefix: str, batch_size: int = 1000, limit: int = OPT, mfa: str = OPT, request_payer: str = OPT, bypass_governance_retention: bool = OPT, expected_bucket_owner: str = OPT, check_sum_algorithm: str = OPT, skip_prompt: bool = False) int[source]

Recursively delete all objects under a s3 prefix. It is a wrapper of delete_objects. Include the hard folder itself.

Parameters:
  • s3_clientboto3.session.Session().client("s3") object.

  • bucket – S3 bucket name.

  • prefix – The s3 prefix (logic directory) you want to delete, it has to be a directory (end with “/”).

  • batch_size – Number of s3 object to delete per micro-batch, valid value is from 1 ~ 1000. large number can reduce IO.

  • limit – Total Number of s3 object to delete.

  • mfa – See delete_object.

  • request_payer – See delete_object.

  • bypass_governance_retention – See delete_object.

  • expected_bucket_owner – See delete_object.

  • check_sum_algorithm – See delete_object.

  • skip_prompt – Default False, it will prompt you to confirm when deleting everything in an S3 bucket.

Returns:

number of deleted objects

Added in version 2.0.1.

s3pathlib.better_client.delete_object.delete_object_versions(s3_client: S3Client, bucket: str, prefix: str, batch_size: int = 1000, limit: int = OPT, mfa: str = OPT, request_payer: str = OPT, bypass_governance_retention: bool = OPT, expected_bucket_owner: str = OPT, check_sum_algorithm: str = OPT, skip_prompt: bool = False) int[source]

Recursively delete all objects and their versions under a s3 prefix. It is a wrapper of delete_objects. It will delete all historical versions and hard folder permanently.

Parameters:
  • s3_clientboto3.session.Session().client("s3") object.

  • bucket – S3 bucket name.

  • prefix – The s3 prefix (logic directory) you want to delete, it has to be a directory (end with “/”).

  • batch_size – Number of s3 object to delete per micro-batch, valid value is from 1 ~ 1000. large number can reduce IO.

  • limit – Total Number of s3 object to delete.

  • mfa – See delete_object.

  • request_payer – See delete_object.

  • bypass_governance_retention – See delete_object.

  • expected_bucket_owner – See delete_object.

  • check_sum_algorithm – See delete_object.

  • skip_prompt – Default False, it will prompt you to confirm when deleting everything in an S3 bucket.

Returns:

number of deleted objects

Added in version 2.0.1.