Alibaba Cloud Tea Util for Python

0.3.14 · active · verified Thu Apr 09

The `alibabacloud-tea-util` library is a core utility module for the Alibaba Cloud Python SDK. It provides common functionalities such as model handling, various helper methods for data manipulation and validation, and definitions for runtime options. The library is actively maintained, supports Python 3.6 and later, and serves as a foundational component for many other Alibaba Cloud SDKs.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic usage of `alibabacloud-tea-util`, showing how to import and instantiate common models like `RuntimeOptions` and use utility methods such as `get_timestamp` and `to_jsonstring`. This library typically works in conjunction with specific service SDKs or `alibabacloud-tea-openapi`.

import os
from alibabacloud_tea_util.client import Client as UtilClient
from alibabacloud_tea_util import models as util_models

# NOTE: In a real application, AccessKey ID and Secret should be
# managed securely, e.g., via environment variables or STS tokens.
# NEVER hardcode credentials in your source code.
# export ALIBABA_CLOUD_ACCESS_KEY_ID="your_access_key_id"
# export ALIBABA_CLOUD_ACCESS_KEY_SECRET="your_access_key_secret"

# Example of using a utility method and a common model
def main():
    try:
        # Instantiate a common model provided by tea-util
        runtime_options = util_models.RuntimeOptions(
            connect_timeout=10000, # milliseconds
            read_timeout=15000    # milliseconds
        )

        # You would typically pass these options to a service client, 
        # but here we'll just print its string representation
        print(f"Created RuntimeOptions: {UtilClient.to_jsonstring(runtime_options)}")

        # Example of a simple utility function - getting a current timestamp
        timestamp = UtilClient.get_timestamp()
        print(f"Current timestamp (GMT): {timestamp}")

    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == '__main__':
    main()

view raw JSON →