Skip to content
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 Executor Setup

The Trendz Python Executor is a Docker-based microservice required for:

  • Python Calculation fields
  • All prediction models (except Fourier Transformation)
  • Code generation for Metric Explorer

Deployment recommendations:

  • Same host — deploy the Python Executor on the same host as Trendz. Communication uses WebSockets; placing them on separate hosts requires opening the executor port in the firewall and increases latency.
  • Resources — allocate at least 1 GB RAM and 1 CPU core. More CPU directly speeds up prediction model training and execution.

Use these steps only if you installed Trendz via a package (Ubuntu, RHEL/CentOS, or Windows) and need to add the Python Executor separately.

Create a new docker-compose.yml with the following content:

services:
trendz-python-executor:
restart: always
image: "thingsboard/trendz-python-executor:1.16.0"
ports:
- "8181:8181"
environment:
EXECUTOR_MANAGER: 1
EXECUTOR_SCRIPT_ENGINE: 6
THROTTLING_QUEUE_CAPACITY: 10
THROTTLING_THREAD_POOL_SIZE: 6
NETWORK_BUFFER_SIZE: 5242880
volumes:
- trendz-python-executor-conf:/python-executor-config-files
- trendz-python-executor-data:/data
volumes:
trendz-python-executor-conf:
name: trendz-python-executor-conf
driver: local
trendz-python-executor-data:
name: trendz-python-executor-data
driver: local

Docker Compose parameters:

Parameter Description
8181:8181 Maps host port 8181 to the Python Executor port
restart: always Auto-restarts the container on failure or system reboot
EXECUTOR_MANAGER Number of executor manager threads
EXECUTOR_SCRIPT_ENGINE Number of script engine threads
THROTTLING_QUEUE_CAPACITY Maximum number of queued script executions
THROTTLING_THREAD_POOL_SIZE Number of threads for throttling
NETWORK_BUFFER_SIZE WebSocket network buffer size in bytes
trendz-python-executor-conf:/python-executor-config-files Persists Python Executor configuration files
trendz-python-executor-data:/data Persists Python Executor data directory

Run from the directory containing your docker-compose.yml:

Terminal window
docker compose up -d
docker compose logs -f trendz-python-executor

Step 3. Connect Trendz to the Python Executor

Section titled “Step 3. Connect Trendz to the Python Executor”

Edit /usr/share/trendz/conf/trendz.conf and add:

Terminal window
export SCRIPT_ENGINE_TIMEOUT=30000
export SCRIPT_ENGINE_PROVIDER=DOCKER_CONTAINER
export SCRIPT_ENGINE_DOCKER_PROVIDER_URL=PYTHON_EXECUTOR_HOST:PYTHON_EXECUTOR_PORT

Replace PYTHON_EXECUTOR_HOST and PYTHON_EXECUTOR_PORT with the actual host and port where your Python Executor is running. Ensure Trendz can reach this network destination.

Restart Trendz to apply the changes:

Terminal window
sudo systemctl restart trendz

You can extend the Python Executor with additional libraries to use in Calculation Fields or Custom Prediction Models.

The following libraries are bundled in the official Docker image and available out of the box:

Library Min version
numpy 2.0
pandas 2.1.0
scikit-learn 1.6.0
statsmodels 0.14.0
matplotlib 3.7.0
prophet 1.2.0
xgboost 1.8.0
requests 2.31.0

To add a library not listed above, follow these steps. For example, to add the emoji library at version 2.2.0:

Step 1. Open a shell in the running container

Section titled “Step 1. Open a shell in the running container”
Terminal window
docker compose exec trendz-python-executor bash

Step 2. Add the library to requirements.txt

Section titled “Step 2. Add the library to requirements.txt”

Append the library name and version to the requirements.txt file in the configuration directory:

Terminal window
echo 'emoji==2.2.0' >> /python-executor-config-files/requirements.txt

Type exit to leave the container shell.

Terminal window
docker compose restart trendz-python-executor
Terminal window
docker compose logs trendz-python-executor

Look for a line confirming successful installation:

Installing custom Python requirements...
Requirement already satisfied: emoji==2.2.0 in /usr/local/lib/python3.9/site-packages

The library is now available in your Trendz Calculation Fields and Custom Prediction Models.

All Python Executor settings are configured via environment variables. Pass them under the environment: key in your docker-compose.yml.

Environment variable Default Description
EXECUTOR_MANAGER 1 Number of manager executor threads
EXECUTOR_SCRIPT_ENGINE 6 Number of script engine threads. Increase for higher parallel script execution throughput
THROTTLING_QUEUE_CAPACITY 10 Maximum number of script execution requests that can wait in queue. Requests beyond this limit are rejected
NETWORK_BUFFER_SIZE 20971520 WebSocket message buffer size in bytes (default 20 MB). Increase when scripts transfer large datasets
SCRIPT_ENGINE_RUNTIME_TIMEOUT 10000 Python script execution timeout in milliseconds. Scripts that exceed this limit are terminated

To confirm that Trendz is successfully connected to the Python Executor, create a simple Python Calculation Field and run it — for example:

return 42

If the script executes and returns a result, the connection is working. If it times out or returns an error, check that the Python Executor is running and that SCRIPT_ENGINE_DOCKER_PROVIDER_URL points to the correct host and port.