The Tablestore client provides a series of methods to manage tables and perform read and write operations on a single row or multiple rows.
Obtain an endpoint
An endpoint is the domain name that is used to access a Tablestore instance in a region. To query an endpoint, perform the following operations:
- Log on to the Tablestore console.
- Go to the Instance Details tab. You can view the endpoints of the instance in the Instance Access URL section.
Configure an AccessKey pair
To access Tablestore, you must have an AccessKey pair that consists of an AccessKey ID and AccessKey secret to verify your identity. For more information, see Create an AccessKey.
""" Initialize the OTSClient instance. end_point indicates the endpoint used to access the Tablestore instance, which must start with https://. Example: https://instance.cn-hangzhou.ots.aliyun.com:80. access_key_id indicates the AccessKey ID used to access the Tablestore instance. You can visit the Alibaba Cloud official website or contact an administrator to obtain an AccessKey ID. access_key_secret indicates the AccessKey secret used to access the Tablestore instance. You can visit the Alibaba Cloud official website or contact an administrator to obtain an AccessKey ID. instance_name indicates the name of the instance to access. You can create an instance in the Tablestore console or contact an administrator to obtain the name of an existing instance. sts_token indicates the STS token used to access the Tablestore instance. You can use Alibaba Cloud STS to obtain an STS token. The STS token has a validity period. You must obtain a new token after the existing token expires. encoding indicates the method used to encode the request parameter string. The default value is utf8. socket_timeout indicates the timeout period in seconds for each socket connection in the connection pool. The value can be an integer or floating-point number. The default value is 50. max_connection indicates the maximum number of connections in a connection pool. The default value is 50. logger_name is used to display the debug log in the request or display the error log when an error occurs. retry_policy defines the retry policy. The default retry policy is DefaultRetryPolicy. You can define a retry policy based on a RetryPolicy class. For more information, see the code in DefaultRetryPolicy. """ class OTSClient(object): def __init__(self, endpoint, access_key_id, access_key_secret, instance_name, **kwargs):
######### Configure the name of the log file and retry policy. ######### # The name of the log file is table_store.log. The retry policy is WriteRetryPolicy, which defines the retry attempts to write the table when a write operation fails. ots_client = OTSClient('endpoint', 'access_key_id', 'access_key_secret', 'instance_name', logger_name = 'table_store.log', retry_policy = WriteRetryPolicy()) ######### Use STS ######### ots_client = OTSClient('endpoint', 'STS.K8h*******GB77', 'CkuDj******Wn6', 'instance_name', sts_token = 'CAISjgJ1q6Ft5B2y********OFcsLLuw==')
- HTTPS is supported in Python 2.0.8 and later.
- OpenSSL 0.9.8j or later is required. We recommend that you use OpenSSL 1.0.2d.
- The Python 2.0.8 release package contains a certifi package that can be installed and used. To update the root certificate, download the latest root certificate from Root Certificate.