All Products
Search
Document Center

Object Storage Service:Delete object tags (Python SDK V2)

Last Updated:Jul 31, 2025

This topic describes how to use Python SDK V2 to delete object tags.

Notes

  • The sample code in this topic uses the China (Hangzhou) region ID cn-hangzhou as an example. The public endpoint is used by default. If you access OSS from another Alibaba Cloud service in the same region, use an internal endpoint. For more information about the mappings between OSS regions and endpoints, see OSS regions and endpoints.

  • Object tagging uses key-value pairs to tag an object. For more information about object tagging, see Object tagging in the development guide.

  • For more information about how to delete object tags, see DeleteObjectTagging.

  • To delete object tags, you must have the oss:DeleteObjectTagging permission. For more information, see Grant custom permissions to a RAM user.

Method definition

delete_object_tagging(request: DeleteObjectTaggingRequest, **kwargs) → DeleteObjectTaggingResult

Request parameters

Parameter

Type

Description

request

DeleteObjectTaggingRequest

The request parameters. For more information, see DeleteObjectTaggingRequest

Return values

Type

Description

DeleteObjectTaggingResult

The return value. For more information, see DeleteObjectTaggingResult

For the complete method definition, see delete_object_tagging.

Sample code

You can use the following code to delete the tags of a specified object in a bucket.

import argparse
import alibabacloud_oss_v2 as oss

# Create a command-line argument parser.
parser = argparse.ArgumentParser(description="delete object tagging sample")
# Add command-line arguments.
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
parser.add_argument('--key', help='The name of the object.', required=True)

def main():
    # Parse command-line arguments.
    args = parser.parse_args()

    # Load the authentication information required for OSS from environment variables.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Create a configuration object using the default configurations provided by the SDK.
    cfg = oss.config.load_default()

    # Set the credential provider.
    cfg.credentials_provider = credentials_provider

    # Set the region.
    cfg.region = args.region

    # If an endpoint is provided, set the endpoint.
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    # Create an OSS client instance using the preceding configurations.
    client = oss.Client(cfg)

    # Delete the tags of the specified object.
    result = client.delete_object_tagging(oss.DeleteObjectTaggingRequest(
        bucket=args.bucket,
        key=args.key,
    ))

    # Print the result.
    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
          f' version id: {result.version_id},'
    )

# Call the main function when the script is directly run.
if __name__ == "__main__":
    main()

References