Updated on 2026-07-31 GMT+08:00

Listing Bucket Inventory Rules (SDK for Python)

Function

This API is used to list all inventory rules of a bucket on one page at a time. The GET method without inventory IDs is used.

Restrictions

  • The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.

Method

ObsClient.listBucketInventory(bucketName, extensionHeaders)

Request Parameters

Parameter

Type

Mandatory (Yes/No)

Description

bucketName

String

Yes

Explanation:

Bucket name

Restrictions:

  • A bucket name must be unique across all accounts and regions.
  • A bucket name:
    • Must be 3 to 63 characters long and start with a digit or letter. Lowercase letters, digits, hyphens (-), and periods (.) are allowed.
    • Cannot be formatted as an IP address.
    • Cannot start or end with a hyphen (-) or period (.).
    • Cannot contain two consecutive periods (..), for example, my..bucket.
    • Cannot contain a period (.) and a hyphen (-) adjacent to each other, for example, my-.bucket or my.-bucket.
  • If you repeatedly create buckets with the same name in the same region, no error will be reported and the bucket properties comply with those set in the first creation request.

Default value:

None

extensionHeaders

dict

No

Explanation:

Extension headers

Value range:

See User-defined Headers (SDK for Python).

Default value:

None

Responses

Type

Description

GetResult

Explanation:

SDK common results

Table 1 GetResult

Parameter

Type

Description

status

int

Explanation:

HTTP status code

Value range:

A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). For more information, see Status Code.

Default value:

None

reason

str

Explanation:

Reason description

Default value:

None

errorCode

str

Explanation:

Error code returned by the OBS server. If the value of status is less than 300, this parameter is left blank.

Default value:

None

errorMessage

str

Explanation:

Error message returned by the OBS server. If the value of status is less than 300, this parameter is left blank.

Default value:

None

requestId

str

Explanation:

Request ID returned by the OBS server

Default value:

None

indicator

str

Explanation:

Error indicator returned by the OBS server

Default value:

None

hostId

str

Explanation:

Requested server ID. If the value of status is less than 300, this parameter is left blank.

Default value:

None

resource

str

Explanation:

Error source (a bucket or an object). If the value of status is less than 300, this parameter is left blank.

Default value:

None

header

list

Explanation:

Response header list, composed of tuples. Each tuple consists of two elements, respectively corresponding to the key and value of a response header.

Default value:

None

body

object

Explanation:

Result content returned after the operation is successful. If the value of status is larger than 300, this parameter is left blank. The value varies with the API being called. For details, see the sections "Bucket-Related APIs" and "Object-Related APIs".

Default value:

None

GetResult.body Type

Description

Table 2

Explanation:

The list of bucket inventory rules. For details, see Table 2.

Table 2 ListBucketInventoryResponse

Parameter

Type

Description

configurations

Table 3

Explanation:

Bucket inventory configurations. For details, see Table 3.

Table 3 InventoryConfiguration

Parameter

Type

Description

inventoryId

str

Explanation:

ID of a bucket inventory rule

Restrictions:

The rule ID allows letters (a–z, A–Z), digits (0–9), hyphens (-), underscores (_), and periods (.).

Value range:

The value can be up to 64 characters long.

Default value:

None

isEnabled

bool

Explanation:

Whether the bucket inventory rule is enabled

Value range:

True: The rule is enabled, and inventory files are generated.

False: The rule is disabled, and inventory files are not generated.

Default value:

True

objectVersion

str

Explanation:

Whether versions of objects are included in an inventory

Value range:

  • If this parameter is set to All, all the versions of objects are included in the inventory, and version-related fields are added to the inventory, including: VersionId, IsLatest, and DeleteMarker.
  • If this parameter is set to Current, the inventory only lists information about the current object version and does not include any version-related fields.

Default value:

None

filter

Table 4

Explanation:

Inventory filter configuration. The inventory contains only objects that meet the filter criteria (filtering by object name prefix). If no filter criteria are configured, all objects are included. For details, see Table 4.

frequency

str

Explanation:

The intervals at which inventories are generated. You can set it to Daily or Weekly. An inventory is generated within one hour after it is configured for the first time, and subsequently at the specified intervals.

Value range:

Daily: Inventories are generated once a day.

Weekly: Inventories are generated once a week.

Default value:

None

destination

Table 5

Explanation:

Destination configuration of an inventory. For details, see Table 5.

optionalFields

list

Explanation:

Additional object metadata fields that are contained in an inventory file

Value range:

Size: the object size

LastModifiedDate: the last modification time of an object

StorageClass: the storage class of an object

ETag: the ETag value of an object

IsMultipartUploaded: whether an object is uploaded in a multipart upload

ReplicationStatus: the cross-region replication status of an object

EncryptionStatus: the encryption status of an object

Default value:

None

Table 4 InventoryFilter

Parameter

Type

Description

prefix

str

Explanation:

Prefix for filtering objects. Only objects with the specified name prefix are included in the inventory.

Value range:

The value must contain 1 to 1,024 characters.

Default value:

None

Table 5 InventoryDestination

Parameter

Type

Description

bucket

str

Explanation:

Name of the bucket for storing inventories

Restrictions:

  • A bucket name must be unique across all accounts and regions.
  • A bucket name:
    • Must be 3 to 63 characters long and start with a digit or letter. Lowercase letters, digits, hyphens (-), and periods (.) are allowed.
    • Cannot be formatted as an IP address.
    • Cannot start or end with a hyphen (-) or period (.).
    • Cannot contain two consecutive periods (..), for example, my..bucket.
    • Cannot contain a period (.) and a hyphen (-) adjacent to each other, for example, my-.bucket or my.-bucket.
  • If you repeatedly create buckets with the same name in the same region, no error will be reported and the bucket properties comply with those set in the first creation request.

Default value:

None

prefix

str

Explanation:

The prefix of the inventory file name

Value range:

The value must contain 1 to 1,024 characters.

Default value:

If you do not specify this parameter, BucketInventory is used as the prefix by default.

format

str

Explanation:

Inventory file format. Only the CSV format is supported.

Value range:

CSV

Default value:

None

Sample Code

This example lists inventory rules of bucket examplebucket.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from obs import ObsClient
import os
import traceback

# Obtain an AK/SK pair using environment variables (recommended) or import it in other ways. Using hard coding may result in leakage.
# Obtain an AK and SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
ak = os.getenv("AccessKeyID")
sk = os.getenv("SecretAccessKey")
# If you use a temporary AK/SK pair and a security token to access OBS, obtain them from environment variables.
# security_token = os.getenv("SecurityToken")
# Set server to the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
server = "https://obs.ap-southeast-1.myhuaweicloud.com" 

# Create an obsClient instance.
# If you use a temporary AK/SK pair and a security token to access OBS, you must specify security_token when creating an instance.
obsClient = ObsClient(access_key_id=ak, secret_access_key=sk, server=server)
try:
    bucketName = "examplebucket"
    # List bucket inventory rules.
    resp = obsClient.listBucketInventory(bucketName)

    # If status code 2xx is returned, the API call succeeds. Otherwise, the API call fails.
    if resp.status < 300:
        print('List Bucket Inventory Succeeded')
        for config in resp.body.configurations:
            print('inventoryId:', config.inventoryId)
            print('isEnabled:', config.isEnabled)
            print('objectVersion:', config.objectVersion)
            print('filter:', config.filter)
            print('frequency:', config.frequency)
            print('destination:', config.destination)
            print('optionalFields:', config.optionalFields)
    else:
        print('List Bucket Inventory Failed')
        print('requestId:', resp.requestId)
        print('errorCode:', resp.errorCode)
        print('errorMessage:', resp.errorMessage)
except Exception:
    print('List Bucket Inventory Failed')
    print(traceback.format_exc())