{"id":1899,"library":"alibabacloud-tea-util","title":"Alibaba Cloud Tea Util for Python","description":"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.","status":"active","version":"0.3.14","language":"en","source_language":"en","source_url":"https://github.com/aliyun/tea-util","tags":["Alibaba Cloud","SDK","utility","Tea Framework","cloud"],"install":[{"cmd":"pip install alibabacloud-tea-util","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"Commonly imported as 'UtilClient' to avoid naming conflicts with service-specific 'Client' classes.","symbol":"Client","correct":"from alibabacloud_tea_util.client import Client as UtilClient"},{"note":"Provides shared data models like `RuntimeOptions` for request configuration.","symbol":"models","correct":"from alibabacloud_tea_util import models as util_models"}],"quickstart":{"code":"import os\nfrom alibabacloud_tea_util.client import Client as UtilClient\nfrom alibabacloud_tea_util import models as util_models\n\n# NOTE: In a real application, AccessKey ID and Secret should be\n# managed securely, e.g., via environment variables or STS tokens.\n# NEVER hardcode credentials in your source code.\n# export ALIBABA_CLOUD_ACCESS_KEY_ID=\"your_access_key_id\"\n# export ALIBABA_CLOUD_ACCESS_KEY_SECRET=\"your_access_key_secret\"\n\n# Example of using a utility method and a common model\ndef main():\n    try:\n        # Instantiate a common model provided by tea-util\n        runtime_options = util_models.RuntimeOptions(\n            connect_timeout=10000, # milliseconds\n            read_timeout=15000    # milliseconds\n        )\n\n        # You would typically pass these options to a service client, \n        # but here we'll just print its string representation\n        print(f\"Created RuntimeOptions: {UtilClient.to_jsonstring(runtime_options)}\")\n\n        # Example of a simple utility function - getting a current timestamp\n        timestamp = UtilClient.get_timestamp()\n        print(f\"Current timestamp (GMT): {timestamp}\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n\nif __name__ == '__main__':\n    main()","lang":"python","description":"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`."},"warnings":[{"fix":"Store credentials in environment variables or use an STS token service. Access them via `os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID')`.","message":"Never hardcode AccessKey ID or AccessKey Secret directly in your code. Always use environment variables (`ALIBABA_CLOUD_ACCESS_KEY_ID`, `ALIBABA_CLOUD_ACCESS_KEY_SECRET`) or more secure credential management solutions like RAM roles or STS tokens to prevent credential leakage.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade your Python interpreter to version 3.6 or newer.","message":"The `alibabacloud-tea-util` library requires Python 3.6 or higher. Ensure your environment meets this minimum requirement to avoid compatibility issues.","severity":"gotcha","affected_versions":"< 0.1.0 (earlier versions might have been less strict, but current requires >=3.6)"},{"fix":"Understand `tea-util`'s role as a foundational layer. For API calls, install the relevant service SDK or `alibabacloud-tea-openapi`.","message":"While `tea-util` provides core utilities, it's typically used as a dependency for service-specific SDKs (e.g., `alibabacloud-airec`) or the generic `alibabacloud-tea-openapi` package. For full functionality, you'll usually need to install and integrate with these other packages.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement `try...except TeaException as e:` blocks to gracefully handle errors returned by Alibaba Cloud services.","message":"When handling API responses or network operations, be prepared to catch `TeaException` for business-related errors or `TeaUnretryableException` for network/retry exhaustion. Direct exception handling is crucial for robust applications.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}