Python API

If you are working with a Python environment we provide a PyPI package that makes interacting with the CloudTables API as simple as calling a class constructor and then the method. Using the library you can easily embed data sets securely into your pages, get information about data sets, the data of a dataset, and also add, edit and delete data in a data set.

Installing

The CloudTables library is available as the CloudTablesApi package on PyPi and can be installed for your project using:

# pip
pip install CloudTablesApi
# python
python3 -m pip uninstall CloudTablesApi

Use

The CloudTables API libraries provide a class whose constructor returns an API handle.

from CloudTablesApi import CloudTablesApi

Initialisation

Once imported into your application, you need to create an API instance so the methods it provides can be configured and accessed. This can be done using:

api = CloudTablesApi('{apiKey}', subdomain='sub-domain', options={
	clientId: 'Unique client id', # Client id (e.g. a login id) - optional
	clientName: 'Name'            # Client's name - optional
})

Where:

  • {apiKey} should be replaced by the API key that you want to use for the access.
  • clientId and clientName in the configuration object are optional, but we strongly recommend they are used when integrating with your own login system as it allows the identification of each client's actions in CloudTables' auditing features. Typically the clientId would be set to your login system's user id and clientName the user's username or full name.

A new CloudTablesApi instance should be created for each access request, as it will cache and reuse the access token if one is required.

Embedding data sets

There are two methods provided by the library to embed a data set into your HTML page. The end result is a <script> tag which includes an access token that can then be inserted into your HTML.

Fully automatic script tag

The dataset().script_tag() method can be used to get an access token (based on the initialisation options) for a data set, and will return a string that contains the full <script> tag that should be inserted into your HTML:

token = api.token()
script = api.dataset('{data-set-id}').script_tag(token)

Where:

  • {data-set-id} is the ID of the data set you wish to embed into the page. The data set ID can be found in the Inspector for the data set on the Data tab.

Custom script tag

You can also build your own <script> tag based on a token:

token = api.token()
script = (
	"<script "
	"src='https://sub-domain.cloudtables.io/loader/{data-set-id}/table/d'
	"data-token='${token}'"
	"></script>"
  )

API Reference

Source

Our API libraries for CloudTables are open source under the MIT license. The Python source is available here and pull requests or suggestions for it are welcome.