All Products
Search
Document Center

Object Storage Service:Delete object tags (OSS SDK for Python 1.0)

Last Updated:Feb 28, 2026

Delete all tags from an object. When versioning is enabled, Object Storage Service (OSS) removes tags from the current version by default. To delete tags from a specific version, pass its version ID.

Prerequisites

Before you begin, make sure that you have:

  • An OSS bucket with objects that have tags

  • The oss:DeleteObjectTagging permission granted to your RAM user. For details, see Attach a custom policy to a RAM user

  • The OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables configured

  • Python SDK V1 (oss2) installed

Method signature

bucket.delete_object_tagging(key, params=None)
ParameterTypeRequiredDescription
keystrYesFull path of the object, excluding the bucket name. Example: exampledir/exampleobject.txt
paramsdictNoAdditional parameters. Set params['versionId'] to delete tags from a specific object version

Delete tags from an object

The following example deletes all tags from the exampledir/exampleobject.txt object in the examplebucket bucket:

# -*- coding: utf-8 -*-

import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Get access credentials from environment variables.
# Make sure OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the endpoint for your bucket's region.
# Example: https://oss-cn-hangzhou.aliyuncs.com for China (Hangzhou).
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the region. Required for V4 signatures.
region = "cn-hangzhou"

bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Full path of the object, excluding the bucket name.
object_name = 'exampledir/exampleobject.txt'

# Delete all tags from the object.
result = bucket.delete_object_tagging(object_name)
print('HTTP response status:', result.status)

Expected output:

HTTP response status: 204

Delete tags from a specific object version

When versioning is enabled on a bucket, specify the version ID to delete tags from a particular version of the object.

Note

For details on how to get version IDs, see List objects.

# -*- coding: utf-8 -*-

import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Get access credentials from environment variables.
# Make sure OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the endpoint for your bucket's region.
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the region. Required for V4 signatures.
region = "cn-hangzhou"

bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Full path of the object, excluding the bucket name.
object_name = 'exampledir/exampleobject.txt'
# Specify the version ID of the target object.
version_id = 'CAEQMxiBgICAof2D0BYiIDJhMGE3N2M1YTI1NDQzOGY5NTkyNTI3MGYyMzJm****'

params = {'versionId': version_id}
bucket.delete_object_tagging(object_name, params=params)

Usage notes

  • Endpoints: The examples use the public endpoint of the China (Hangzhou) region. To access OSS from other Alibaba Cloud services in the same region, use an internal endpoint. For more information, see Regions and endpoints.

  • Client initialization: The examples create an oss2.Bucket instance using an OSS endpoint. To use custom domain names or Security Token Service (STS), see Initialization.

Related operations

References