Skip to content

Cookie preferences

We use cookies for our own analytics, to see how our campaigns perform and, if you allow it, to load content from other services such as the Google site search. We never sell your data. Necessary cookies keep the site working and cannot be switched off. See our Cookie Policy for details and our Privacy Policy for how we handle personal data.

Security, load balancing and remembering your cookie choice.

Show us which pages people read, how they find the site and where they get stuck, so we can improve it (Google Analytics, Microsoft Clarity).

Show us which of our ad campaigns bring visitors to the site and remember the campaign or partner link you arrived from (Google Ads, LinkedIn, Meta, partner program). We do not use these cookies to build advertising profiles.

Load the site search from Google when you use it. Google sets its own cookies and shows ads in the search results.

© 2026 The ThingsBoard Authors
22.5k Try for free

ThingsBoard Cloud

Choose your data region

Your data stays in the region you choose, for residency and compliance. No credit card required.

Rather run it yourself? Install on your own servers

Python REST Client (Legacy)

The ThingsBoard Python REST Client wraps the REST API and lets Python scripts manage devices, assets, dashboards, customers, and other platform entities. It supports context managers for automatic token refresh.

Terminal window
pip3 install tb-rest-client==4.3.1.6
import logging
from tb_rest_client.rest_client_ce import *
from tb_rest_client.rest import ApiException
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(module)s - %(lineno)d - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
url = "https://eu.thingsboard.cloud"
api_key = "YOUR_API_KEY_HERE"
def main():
with RestClientCE(base_url=url) as rest_client:
try:
rest_client.api_key_login(api_key)
device_profile = DeviceProfile(name="Thermometer",
type="DEFAULT",
transport_type="DEFAULT",
profile_data=DeviceProfileData(
configuration={"type": "DEFAULT"},
import logging
from tb_rest_client.rest_client_ce import *
from tb_rest_client.rest import ApiException
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(module)s - %(lineno)d - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
url = "https://eu.thingsboard.cloud"
username = "[email protected]"
password = "tenant"
def main():
with RestClientCE(base_url=url) as rest_client:
try:
rest_client.login(username=username, password=password)
default_asset_profile_id = rest_client.get_default_asset_profile_info().id
asset = Asset(name="Building 12", asset_profile_id=default_asset_profile_id)
asset = rest_client.save_asset(asset)
logging.info("Asset was created:\n%r\n", asset)

Create a device, save and read attributes, then delete:

import logging
from tb_rest_client.rest_client_ce import *
from tb_rest_client.rest import ApiException
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(module)s - %(lineno)d - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
url = "https://eu.thingsboard.cloud"
username = "[email protected]"
password = "tenant"
def main():
with RestClientCE(base_url=url) as rest_client:
try:
rest_client.login(username=username, password=password)
default_device_profile_id = rest_client.get_default_device_profile_info().id
device = Device(name="Thermometer 1",
device_profile_id=default_device_profile_id)
device = rest_client.save_device(device)
logging.info("Device was created:\n%r\n", device)
found_device = rest_client.get_device_by_id(DeviceId(device.id, 'DEVICE'))
rest_client.save_device_attributes(DeviceId(device.id, 'DEVICE'), 'SERVER_SCOPE',
import logging
from tb_rest_client.rest_client_ce import *
from tb_rest_client.rest import ApiException
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(module)s - %(lineno)d - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
url = "https://eu.thingsboard.cloud"
username = "[email protected]"
password = "tenant"
def main():
with RestClientCE(base_url=url) as rest_client:
try:
rest_client.login(username=username, password=password)
res = rest_client.get_tenant_devices(page_size=10, page=0)
logging.info("Device info:\n%r", res)
except ApiException as e:
logging.exception(e)
if __name__ == '__main__':
main()
import logging
from tb_rest_client.rest_client_ce import *
from tb_rest_client.rest import ApiException
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(module)s - %(lineno)d - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
url = "https://eu.thingsboard.cloud"
username = "[email protected]"
password = "tenant"
with RestClientCE(base_url=url) as rest_client:
try:
rest_client.login(username=username, password=password)
entity_count_query = EntityCountQuery(
entity_filter=EntityFilter(type='entityType', entity_type='DEVICE'),
key_filters=[KeyFilter(
key={"type": "ATTRIBUTE", "key": "active"},
value_type='BOOLEAN',

The Python REST Client includes helper scripts for saving and loading entities to/from version control (ThingsBoard 3.4+).

Terminal window
python3 configure_vcs_access.py -H YOUR_THINGSBOARD_HOST -p YOUR_THINGSBOARD_PORT \
-U YOUR_USER_EMAIL -P YOUR_USER_PASSWORD \
-r YOUR_REPOSITORY_URL -b DEFAULT_BRANCH \
-gu YOUR_VCS_USERNAME -gp YOUR_VCS_ACCESS_TOKEN

For private key authentication, use -pk and -pkp instead of -gp.

Terminal window
wget https://raw.githubusercontent.com/thingsboard/thingsboard-python-rest-client/master/examples/load_all_entities_to_vcs_ce.py
python3 load_all_entities_to_vcs_ce.py -H YOUR_THINGSBOARD_HOST -p YOUR_THINGSBOARD_PORT \
-U YOUR_USER_EMAIL -P YOUR_USER_PASSWORD
Terminal window
wget https://raw.githubusercontent.com/thingsboard/thingsboard-python-rest-client/master/examples/load_all_entities_from_vcs_ce.py
python3 load_all_entities_from_vcs_ce.py -H YOUR_THINGSBOARD_HOST -p YOUR_THINGSBOARD_PORT \
-U YOUR_USER_EMAIL -P YOUR_USER_PASSWORD -N YOUR_VERSION_NAME

See the thingsboard-python-rest-client repository for complete examples.