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

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.
  • No public access — never expose the Python Executor port to the internet. Only Trendz needs to reach it.
  • 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.1.3"
ports:
- "127.0.0.1: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
127.0.0.1:8181:8181 Publishes the Python Executor port on the local host only. If Trendz runs on another host, publish it on an internal network address instead, never on a public one
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

Trendz authenticates to the Python Executor with a shared secret. Trendz and the executor both default to the publicly known value placeholder, so replace it with your own: generate a random value, for example with openssl rand -hex 32, and set the same value on both sides.

In the Python Executor docker-compose.yml, add it under environment::

PYTHON_EXECUTOR_SECRET: YOUR_SECRET

Add to /usr/share/trendz/conf/trendz.conf:

Terminal window
export PYTHON_EXECUTOR_SECRET=YOUR_SECRET

Apply the change: in the Python Executor folder, run docker compose up -d (a plain restart keeps the old environment), then restart Trendz. If the values differ, Trendz cannot run Python scripts.

Replace the shared secret in Docker and Kubernetes installations

Section titled “Replace the shared secret in Docker and Kubernetes installations”

The Python Executor that comes with a Docker or Kubernetes installation also uses the default secret placeholder. Generate a random value, for example with openssl rand -hex 32, and set it on both services:

  • Docker: add PYTHON_EXECUTOR_SECRET: YOUR_SECRET under environment: of both the trendz and trendz-python-executor services in docker-compose.yml, then run docker compose up -d. If Trendz runs alongside ThingsBoard, the services are in docker-compose-trendz.yml; apply with docker compose -f docker-compose.yml -f docker-compose-trendz.yml up -d.

  • Kubernetes: replace placeholder in trendz-python-executor-secret.yml and apply it. Trendz and the Python Executor read this Secret only at start, so restart them:

    Terminal window
    kubectl apply -f trendz-python-executor-secret.yml
    kubectl -n trendz rollout restart deployment/trendz-python-executor-deployment statefulset/trendz-app

    The StatefulSet restarts the Trendz pods one at a time. With one pod, Trendz is unavailable until it restarts.

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-cpu 2.1.0
requests 2.31.0

The executor installs other libraries from the requirements.txt file in its configuration folder, at every start, when INSTALL_PYTHON_DEPS_ON_STARTUP is true. This is off by default. When it is on:

  • The executor downloads pip and the libraries from PyPI (files.pythonhosted.org, pypi.org) at every start, so it needs outbound internet access.
  • The image has no compiler: a library with compiled code must be available as a binary wheel for Python 3.13 on Linux. Pure Python libraries install from source too.
  • If a library fails to install, the executor does not start. Check its log.

For example, to add the emoji library at version 2.2.0:

If Trendz runs alongside ThingsBoard, the trendz-python-executor service is in docker-compose-trendz.yml: edit that file and run the commands below as docker compose -f docker-compose.yml -f docker-compose-trendz.yml ....

  1. Add the library to requirements.txt in the executor configuration folder. Run from the directory containing your docker-compose.yml:

    Terminal window
    docker compose exec trendz-python-executor sh -c "echo 'emoji==2.2.0' >> /python-executor-config-files/requirements.txt"
  2. In docker-compose.yml, add to the environment: of the trendz-python-executor service:

    INSTALL_PYTHON_DEPS_ON_STARTUP: "true"
  3. Recreate the container so that it gets the new environment:

    Terminal window
    docker compose up -d trendz-python-executor
  4. Check the executor log:

    Terminal window
    docker compose logs trendz-python-executor

The log shows the installation:

Installing Python dependencies from /home/python-executor/configs/requirements.txt (startup mode enabled)...
...
Successfully installed emoji-2.2.0

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
INSTALL_PYTHON_DEPS_ON_STARTUP false Install the libraries listed in requirements.txt at every start; see Add custom Python libraries
PYTHON_EXECUTOR_SECRET placeholder Shared secret Trendz uses to authenticate to the Python Executor. Replace the default and set the same value in Trendz
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.