Alibaba Cloud OpenAPI Utilities for Python (Tea Framework)
This library provides common utility functions for interacting with Alibaba Cloud's OpenAPI using the Tea Framework in Python. It includes methods for signature generation, string manipulation, and XML parsing. The current version is 0.2.4, and it is part of the Alibaba Cloud SDK ecosystem, primarily maintained on an as-needed basis for the Tea framework.
Warnings
- gotcha All utility methods within the `Client` class are static methods. There is no need to instantiate `Client` (e.g., `util = Client()`). Directly call methods like `Client.get_signature(...)`.
- gotcha Signature generation functions (e.g., `get_signature`, `get_string_to_sign`) require specific string inputs. Ensure inputs are properly formatted strings, not bytes, and that parameters like query, headers, and body are correctly structured dictionaries or `None` as expected.
- gotcha This library is part of the 'Tea Framework' for Alibaba Cloud SDKs. If you are using an older or different generation of Alibaba Cloud SDKs that do not rely on the Tea Framework, the signature generation logic provided here may not be compatible or correct for your specific use case.
Install
-
pip install alibabacloud-openapi-util
Imports
- Client
from alibabacloud_openapi_util.client import Client
Quickstart
from alibabacloud_openapi_util.client import Client
# Example of getting the string to sign
string_to_sign = Client.get_string_to_sign({
'method': 'GET',
'pathname': '/',
'query': {'key1': 'value1', 'key2': 'value2'},
'headers': {'User-Agent': 'Tea-Client'},
'body': None
})
print(f"String to sign: {string_to_sign}")
# Example of getting a signature (using a dummy secret for illustration)
access_key_secret = 'YOUR_ACCESS_KEY_SECRET'
signature = Client.get_signature(access_key_secret, string_to_sign)
print(f"Signature: {signature}")