- Documentation
Torch Object Storage
SDK Reference
Python
Bucket interface
Manage bucket configuration
Manage bucket storage types (Python SDK)
Manage bucket configuration
Manage bucket storage types (Python SDK)
Manage bucket storage types (Python SDK)
Bucket is the globally unique namespace of TOS, which is equivalent to a data container and is used to store object data. TOS provides a variety of bucket storage types, which can be applied to various application scenarios. This article describes how to set the storage type of a bucket.
Storage type description
Bucket storage types include the following categories. For more information on storage types, see Storage Type . Set storage type
warning
- Set the bucket storage type. By default, only the bucket owner has this permission.
- After setting the bucket storage type, if the object storage type is not specified when uploading objects, copying objects, and initializing the shard upload task, the object inherits the bucket storage type.
- When creating a bucket, if the bucket storage type is not specified, the default storage type is standard storage.
Sample code
The following code sets the storage type of the bucket-testbucket.
ak = os.getenv('TOS_ACCESS_KEY')
sk = os.getenv('TOS_SECRET_KEY')
endpoint = "your endpoint"
bucket_name = "bucket-test"
client = tos.TosClientV2(ak, sk, endpoint, region)
client.put_bucket_storage_class(bucket_name, tos.StorageClassType.Storage_Class_Ia)
except tos.exceptions.TosClientError as e:
print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))
except tos.exceptions.TosServerError as e:
print('fail with server error, code: {}'.format(e.code))
print('error with request id: {}'.format(e.request_id))
print('error with message: {}'.format(e.message))
print('error with http code: {}'.format(e.status_code))
print('error with ec: {}'.format(e.ec))
print('error with request url: {}'.format(e.request_url))
print('fail with unknown error: {}'.format(e))
Get bucket storage type
warning
Gets the bucket storage type. By default, only the bucket owner has this permission.
Sample code
The following code is used to get the storage type of the bucket-test.
ak = os.getenv('TOS_ACCESS_KEY')
sk = os.getenv('TOS_SECRET_KEY')
endpoint = "your endpoint"
bucket_name = "bucket-test"
client = tos.TosClientV2(ak, sk, endpoint, region)
resp = client.head_bucket(bucket_name)
print('bucket storage class {}'.format(resp.storage_class.value))
except tos.exceptions.TosClientError as e:
print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))
except tos.exceptions.TosServerError as e:
print('fail with server error, code: {}'.format(e.code))
print('error with request id: {}'.format(e.request_id))
print('error with message: {}'.format(e.message))
print('error with http code: {}'.format(e.status_code))
print('error with ec: {}'.format(e.ec))
print('error with request url: {}'.format(e.request_url))
print('fail with unknown error: {}'.format(e))
Related documentation
Last updated: 2025.09.17 18:22:13