Scalar search lets you query objects in a bucket by metadata conditions — filtering by size, storage class, tags, or custom attributes — without iterating through the entire object list. OSS builds and maintains a metadata index for the bucket, so queries return results quickly even across millions of objects.
Prerequisites
Before you begin, make sure you have:
An OSS bucket
The
alibabacloud_oss_v2Python SDK installedAccessKey credentials stored in environment variables (loaded via
EnvironmentVariableCredentialsProvider)
Usage notes
The sample code uses cn-hangzhou as the region and a public endpoint by default. To access OSS from another Alibaba Cloud service in the same region, use an internal endpoint instead. For a full list of regions and endpoints, see Regions and endpoints.
Set up the client
All examples use the same client initialization pattern. Initialize it once and reuse it across all operations below.
import alibabacloud_oss_v2 as oss
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = "<region-id>" # e.g., cn-hangzhou
# cfg.endpoint = "<custom-endpoint>" # Uncomment to use an internal or custom endpoint
client = oss.Client(cfg)Replace <region-id> with the region where your bucket is located.