Delete Objects
The following SDK methods will allow you to perform delete operations in Stratus. The Bucket reference used in the below code snippet is the component instance.
Parameters Used
Parameter Name | Data Type | Definition |
---|---|---|
key | String | A Mandatory parameter. Will hold the complete name of the object along with it's path. |
version_id | String | An Optional parameter. If Versioning is enabled for your bucket then, this param will help you refer to a particular version using its unique Version ID. |
ttl | int | An Optional parameter. It allows you to schedule your delete operations. For example, if you provide the value of ttl as 60, the delete operation will only occur after 60 seconds. The value of ttl has to be >= 60 seconds. |
Delete a Single Object
Using this SDK method, you can delete a particular object by passing the object name to the delete_object() method.
copydelete_res = bucket.delete_object("sam/out/sample.txt") print(delete_res)
Delete a Specific Version of an Object after a Specific Time
Ensure you provide the versionId of the object if you enabled Versioning for your bucket.
You can also schedule your delete operation using the ttl variable. For example, if you provide the value of ttl as 100, the delete operation will only occur after 100 seconds. Always ensure that the value of ttl is greater than equal to 60 seconds.
copydelete_res = bucket.delete_object("sam/out/sample.txt", 'version_id', ttl=300) print(delete_res)
Delete Multiple Objects
Using this SDK method, you can delete multiple objects by passing the names of the objects that need to be deleted as an array.
Ensure you provide the versionId of the object if you enabled Versioning for your bucket. You can also schedule your delete operation using the ttl variable. For example, if you provide the value of ttl as 100, the delete operation will only occur after 100 seconds. Always ensure that the value of ttl is greater than equal to 60 seconds.
copydelete_objects_res = bucket.delete_objects([ { 'key' : "sam/out/sample.txt", 'version_id':'01hj6ackcxpha9151n7mj0cq6g' }, { 'key' :"sam/out/sample1.txt", 'version_id':'01hj68v1tmb33wa7zchb1vtbjn' }],ttl=300) print(delete_objects_res)
Example Response for Delete Operation
copy{'message': 'Object Deletion successful.'}
Truncate Bucket
Using this SDK method you will be able to essentially every single object present in the bucket.
copy# delete all the objects in the bucket truncate_res = bucket.truncate() print(truncate_res)
Delete a Path in the Bucket
Using this SDK, you will be able to delete all the objects present in a path.
You need to pass the complete path to the delete_path() method.
copypath_res = bucket.delete_path("sam/") print(path_res)
Example Response
copy{ "path": "sam/", "message": "Path deletion scheduled" }
Last Updated 2025-05-30 16:54:59 +0530 +0530
Yes
No
Send your feedback to us