edit-icon download-icon

Initialization

Last Updated: Apr 08, 2018

The OTSClient is the client for Table Store, providing a series of methods for manipulating tables and reading/writing data from/to a single row or multiple rows.

Determine an endpoint

An endpoint is the domain of Alibaba Cloud Table Store in a region. It supports the following format.

Endpoint Type Description
Region address The region of the current Table Store instance, for example, https://instance.cn-hangzhou.ots.aliyuncs.com.

To query the endpoint where your Table Store instance is located, follow these steps:

  1. Log on to the Table Store console.

  2. Go to the Instance Details page and locate the Instance Access URL, which is the endpoint of the instance.

Configure an AccessKey

To access Alibaba Cloud Table Store, you need a valid AccessKey (including an AccessKeyId and AccessKeySecret) for signature authentication. To obtain the AccessKey, follow these steps:

  1. Register an Alibaba Cloud account.

  2. Log on to the AccessKey console to create an AccessKeyId and AccessKeySecret.

After you obtain the AccessKeyID and AccessKeySecret, use the endpoint to initialize an OTSClient instance as follows.

API

  1. """
  2. Initialize the ``OTSClient`` instance.
  3. ``end_point`` is the Table Store service address (for example, 'https://instance.cn-hangzhou.ots.aliyun.com:80'), which must be prefixed with 'https://'.
  4. ``access_key_id`` is the accessid used to access Table Store.
  5. ``access_key_secret`` is the accesskey used to access Table Store.
  6. ``instance_name`` is the name of the instance to access. You can create an instance on the Alibaba Cloud Table Store console.
  7. ``sts_token`` is the STS token used to access Table Store. You can get this from Alibaba Cloud STS service. When the STS token is expired, you must reacquire it.
  8. ``encoding`` is the encoding type of the request parameter string. The default value is utf8.
  9. ``socket_timeout`` is the time-out of each connection socket in the connection pool. It can be an integer or float number in the unit of seconds. The default value is 50.
  10. ``max_connection`` is the maximum number of connection pool connections. The default value is 50.
  11. ``logger_name`` is used to print the DEBUG in the request or print the ERROR log when an error occurs.
  12. ``retry_policy`` defines the retry policy. By default, the retry policy is DefaultRetryPolicy. You can inherit a RetryPolicy class to implement your own retry policy. For more information, see the DefaultRetryPolicy code.
  13. """
  14. class OTSClient(object):
  15. def __init__(self, endpoint, access_key_id, access_key_secret, instance_name, **kwargs):

Example

  1. ######### Set the log file name and retry policy #########
  2. # The log file name is table_store.log. The retry policy is WriteRetryPolicy, which retries the write operation.
  3. ots_client = OTSClient('endpoint', 'access_key_id', 'access_key_secret', 'instance_name', logger_name = 'table_store.log', retry_policy = WriteRetryPolicy())
  4. ######### Use STS #########
  5. ots_client = OTSClient('endpoint', 'STS.K8h*******GB77', 'CkuDj******Wn6', 'instance_name', sts_token = 'CAISjgJ1q6Ft5B2y********OFcsLLuw==')

HTTPS

HTTPS is supported from version 2.0.8.

The earliest version of OpenSSL (0.9.8j) is supported, but we recommend OpenSSL 1.0.2d.

The Python 2.0.8 release pack contains a certifi package that can be directly installed and used. To update the root certificate, download the latest root certificate from Root Certificate.

Thank you! We've received your feedback.