Baidu AI Cloud
中国站

百度智能云

Time-Spatial Database

Management Interface

The management operations of TSDB database are called through the management interface, including creating the database, deleting the database and obtaining the database information. Use TsdbAdminClient class in the Python SDK to encapsulate the management interface.

Create a TsdbAdminClient

import baidubce.protocol
from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.services.tsdb.tsdb_admin_client import TsdbAdminClient

# when use https as the protocol, you may find certificate expire problem, this can be resovled by adding the following lines
# import ssl
# ssl._create_default_https_context = ssl._create_unverified_context
 
HOST = 'tsdb.<region>.baidubce.com'
AK = '<your ak>'
SK = '<your sk>'
 
###########optional config#############
protocol=baidubce.protocol.HTTP
# protocol= baidubce.protocol.HTTPS
connection_timeout_in_mills=None
send_buf_size=None
recv_buf_size=None
retry_policy=None
#######################################
 
 
 
config = BceClientConfiguration(
        credentials=BceCredentials(AK, SK),
        endpoint=HOST,
        protocol=protocol,
        connection_timeout_in_mills=connection_timeout_in_mills,
        send_buf_size=send_buf_size,
        recv_buf_size=recv_buf_size,
        retry_policy=retry_policy)
 
tsdb_admin_client = TsdbAdminClient(config)

Create a Time Series Database

Create a database using the following code:

# create a database
database_name = 'pythonsdksample'  # database name
description = 'description'        # database description. Optional
ingest_datapoints_monthly = 1      # monthly write data points quota, unit, point/ millions 
store_bytes_quota = 0              # byte storage capacity quota, unit, byte. Optional, the default value is 0
purchase_length = 1                # purchase time, unit, month
coupon_name = ''                   # coupon number. Optional. If entered, coupon payment is preferred by default
 
client_token = 'testtttt'          # any string is appointed to guarantee the idempotence of the creation. That is, problems such as network retries will not cause repeated creation.
try:
    # use str.encode("UTF-8") in python 3.0+, since str.decode is not supported in unicode,
    # you need to make changes in description, database_name and coupon_name.
    result = tsdb_admin_client.create_database(
            client_token=client_token,
            description=description,
            database_name=database_name,
            ingest_datapoints_monthly=ingest_datapoints_monthly,
            purchase_length=purchase_length,
            store_bytes_quota=store_bytes_quota,
            coupon_name=coupon_name)
    print result                   # successful creation returns the order number, database id, spent amount, and due date information
except BaseException as e:
    print e                        # If the creation fails, an exception is thrown with the details of the error

Delete a Time Series Database

Delete a database using the following code:

# delete the appointed database
database_id = 'tsdb-xxxxxx'  # database_id can be viewed on the details page of the console database on the official website
try:
    response = tsdb_admin_client.delete_database(database_id)
    print response
except BaseException as e:
    print e                  # failed deletion contains detailed error information in the exception

Get a Time Series Database Instance

Get a time series database instance with the following code:

# get the database instance
database_id = 'tsdb-xxxxxx'
print tsdb_admin_client.get_database(database_id)

Return result:

{'status': u'Active', 'autoExport': False, 'databaseId': u'tsdb-xxxxx', 'endpoint': u'pythonsdksample.tsdb-xxxxx.tsdb.iot.bj.baidubce.com', 'createTime': u'2018-07-20T08:57:53Z', 'description': u'', 'databaseName': u'pythonsdksample', 'quota': {ingestDataPointsMonthly:1,storeBytesQuota:0}, 'expiredTime': u'2018-08-20T08:57:54Z'}

Get a Time Series Database Instance List

Get a time series database instance with following code:

# get database instance list
result = tsdb_admin_client.get_all_databases()
print result

Return result:

[{'status': u'Active', 'autoExport': False, 'databaseId': u'tsdb-xxxxx', 'endpoint': u'pythonsdksample.tsdb-xxxxx.tsdb.iot.bj.baidubce.com', 'createTime': u'2018-07-20T08:57:53Z', 'description': u'', 'databaseName': u'pythonsdksample', 'quota': {ingestDataPointsMonthly:1,storeBytesQuota:0}, 'expiredTime': u'2018-08-20T08:57:54Z'},{...},..
Previous
Gzip Compression Instruction of Writing Data Points
Next
Version Description