Alibaba Cloud OSS Gateway Client

0.0.24 · active · verified Thu Apr 16

alibabacloud-gateway-oss is a low-level, generated gateway client for Alibaba Cloud Object Storage Service (OSS). While its PyPI summary states "Alibaba Cloud OSS SDK Library for Python," it is *not* the primary, feature-rich SDK for direct OSS interactions. For most use cases involving OSS, the recommended library is `alibabacloud-oss-v2` (or `oss2`). This library, version 0.0.24, provides a basic client for interacting with the OSS API Gateway and is part of a larger `alibabacloud-gateway` monorepo. It has an infrequent release cadence, tied to updates in the underlying API Gateway specification.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the `alibabacloud-gateway-oss` client using environment variables for authentication and the OSS endpoint. This client provides a low-level interface to the OSS API Gateway. For higher-level, more user-friendly interactions (e.g., direct bucket and object manipulation), the `alibabacloud-oss-v2` (or `oss2`) SDK is generally recommended.

import os
from alibabacloud_gateway_oss.client import Client
from alibabacloud_gateway_oss import models
from alibabacloud_tea_openapi.models import Config

# Configure credentials and endpoint from environment variables
access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', 'your_access_key_id')
access_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', 'your_access_key_secret')
endpoint = os.environ.get('ALIBABA_CLOUD_OSS_ENDPOINT', 'oss-cn-hangzhou.aliyuncs.com') # e.g., 'oss-cn-hangzhou.aliyuncs.com'

# Basic client configuration
config = Config(
    access_key_id=access_key_id,
    access_key_secret=access_key_secret,
    endpoint=endpoint
)

# You can also set a security token for STS credentials
security_token = os.environ.get('ALIBABA_CLOUD_SECURITY_TOKEN')
if security_token:
    config.security_token = security_token

client = Client(config)

print("Alibaba Cloud OSS Gateway Client initialized.")
print(f"Endpoint: {client._endpoint}")

# Note: This is a low-level gateway client. Specific API operations
# are accessed via methods on the 'client' object, often requiring
# request and response models from 'alibabacloud_gateway_oss.models'.
# For common OSS operations like listing buckets, uploading/downloading objects,
# consider using the higher-level 'alibabacloud-oss-v2' (oss2) SDK.

# Example of a placeholder request (replace with actual API call if applicable)
# try:
#     # This is a hypothetical example as specific API methods are not readily documented for this gateway client.
#     # You would consult the Alibaba Cloud OSS API documentation for specific request/response types.
#     list_buckets_request = models.ListBucketsRequest(
#         prefix='my-prefix'
#     )
#     response = client.list_buckets(list_buckets_request)
#     print(f"List Buckets Response: {response.body}")
# except Exception as e:
#     print(f"Error performing operation: {e}")

view raw JSON →