We have recently added a Python client for the CloudTables API. This blog post, along with this video, will walk you through the steps on how to install and use it. The Python API is fully documented, with all methods and parameters listed. Read on for more details, or if you prefer a video format, see below:
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
The CloudTables API library provides a class whose constructor returns an API instance. First include the API in your project, then initialize the API:
from CloudTablesApi import CloudTablesApi
api = CloudTablesApi('{apiKey}', subdomain='{subdomain}')
where:
Now you've got your API instance, you can use that to query your application. Please see below for some examples:
from CloudTablesApi import CloudTablesApi
api = CloudTablesApi('{apiKey}', subdomain='{subdomain}')
# Display the application's datasets
datasets = api.datasets()
print(datasets)
# Get the data for a specific dataset
data = api.dataset({data-set-id}).data()
print(data)
# Add a record to a specific dataset
newrecord = api.dataset({data-set-id}).insert({'dp-1': 'aaa', 'dp-2': 5, 'l-1': 1})
print(newrecord)
Note
{data-set-id}
needs to be replaced with the ID of your data set - this can be found in the Data Set Inspector, on the Data tab for your data set.The API can also be used to get a script
tag to embed the CloudTable into your web page. This is secured by a token. The token ties that session to the web browser session - so if your network traffic was sniffed, hackers couldn't access the CloudTable or its data because that token is already tied to the original browser session.
from CloudTablesApi import CloudTablesApi
api = CloudTablesApi('{apiKey}', subdomain='{subdomain}')
token = api.token()
scripttag = api.dataset({data-set-id}).script_tag(token['token'], style='bs5')
As you've seen, it's very easy to securely embed a CloudTable in a Python application. I hope this has been useful - don't hesitate to get in touch if you have any questions or comments!
As always, please let us know if you'd like a topic discussed in a blog post, we're keen to tailor this to the needs of the community.