- Overview
- Prerequisites
- Python Executor Standalone Installation
- How to Migrate Trendz Python Executor 1.13.2 to Trendz Python Executor 1.14.0
- How to Connect Additional Libraries to the Python Executor
- Next steps
Overview
Trendz Python Executor is required to run:
- Python Calculation fields
- All prediction models (except Fourier Transformation)
- Code generation for Metric Explorer
Starting from version 1.14.0, the only way to run these features is via Trendz Python Executor using Docker (or Kubernetes).
Prerequisites
Windows
- Have Docker Desktop for Windows. You can find out how to install it here
Linux
- Have Docker CE. You can find out how to install it here
- Have Docker Compose. You can find out how to install it here
Python Executor Standalone Installation
Step 1: Create Docker Compose File
Create the Docker Compose file with the following configuration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
services:
trendz-python-executor:
restart: always
image: "thingsboard/trendz-python-executor:1.15.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
Explanation of key fields:
8181- Python executor port for communication with Trendz servicerestart: always- automatically restarts the executor on failure or system rebootthingsboard/trendz-python-executor:1.15.0- Docker image for Trendz Python Executortrendz-python-executor-conf:/python-executor-config-files- mounts the volume ``trendz-python-executor-conf` to Trendz Python Executor directory with configuration filestrendz-python-executor-data:/data- mounts the volumetrendz-python-executor-datato Trendz Python Executor additional data directory
Step 2: Start Python Executor
1
2
docker compose up -d
docker compose logs -f trendz-python-executor
Step 3: Connect Trendz to Python Executor
- Linux or Mac OS
Configure Trendz to communicate with the Python Executor.
Edit /usr/share/trendz/conf/trendz.conf and add:
1
2
3
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 your Python Executor service values and ensure Trendz can reach this network destination.
- Windows
Open Notepad as Administrator and edit:
1
C:\Program Files (x86)\trendz\conf\trendz.yml
Locate the script-engine block and configure:
1
2
3
4
5
6
7
script-engine:
provider: "${SCRIPT_ENGINE_PROVIDER:DOCKER_CONTAINER}"
runtime-timeout: "${SCRIPT_ENGINE_TIMEOUT:60000}"
callback-timeout: "${SCRIPT_ENGINE_TIMEOUT:60000}"
docker-provider-url: "${SCRIPT_ENGINE_DOCKER_PROVIDER_URL:PYTHON_EXECUTOR_HOST:PYTHON_EXECUTOR_PORT}"
websocket-buffer-size: "${SCRIPT_ENGINE_WEBSOCKET_BUFFER_SIZE:20971520}"
websocket-concurrency: "${SCRIPT_ENGINE_WEBSOCKET_CONCURRENCY:5}"
Replace PYTHON_EXECUTOR_HOST and PYTHON_EXECUTOR_PORT with your Python Executor service values and ensure Trendz can reach this network destination.
How to Migrate Trendz Python Executor 1.13.2 to Trendz Python Executor 1.14.0
If you already have a Python Executor with a version earlier than 1.14.0 connected to Trendz, you should migrate it before updating Trendz to 1.14.0.
Step 1. Modify Docker Compose File
Locate the docker-compose.yml file from which the Python Executor was launched.
Change the Python Executor image tag to version 1.14.0 and update the volumes section to include configuration and data directories.
The final docker-compose.yml should look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
services:
trendz-python-executor:
restart: always
image: "thingsboard/trendz-python-executor:1.15.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
Step 2. Restart Python Executor
Restart the Python Executor to apply the changes:
1
2
docker compose up -d
docker compose logs -f trendz-python-executor
How to Connect Additional Libraries to the Python Executor
If necessary, you can add additional Python libraries to the Python Executor and use them in your Trendz Calculation Fields or Trendz Custom Prediction Models.
For example, if you want to add the emoji library (specific version 2.2.0), follow these steps.
Step 1. Open a shell in the running container
1
docker compose exec trendz-python-executor bash
Step 2. Add library to requirements.txt
You need to append the library name and version to the requirements.txt file located in your configuration directory (/python-executor-config-files):
1
echo 'emoji==2.2.0' >> /python-executor-config-files/requirements.txt
After append all necessary dependencies type exit to exit from a shell.
Step 3. Restart the Docker Container
Find the container name and restart it:
1
docker compose restart trendz-python-executor
Step 4. Verify Installation
Check the logs to ensure the library was installed successfully:
1
docker compose logs trendz-python-executor
You should see:
1
2
Installing custom Python requirements...
Requirement already satisfied: emoji==2.2.0 in /usr/local/lib/python3.9/site-packages
After the container restarts, you can import and use the custom libraries in your Trendz Calculation Fields or Trendz Custom Prediction Models.
Next steps
-
Getting started guide - These guide provide quick overview of main Trendz features.
-
Metric Explorer - Learn how to explore and create new metrics with Trendz Metric Explorer.
-
Anomaly Detection - Learn how to identify anomalies in the data.
-
Calculated Fields - Learn about Calculated fields and how to use them.
-
States - Learn how to define and analyse states for assets based on raw telemetry.
-
Prediction - Learn how to make forecasts and predict telemetry behavior.
-
Filters - Learn how filter dataset during analysis.
-
Available Visualizations - Learn about visualization widgets available in Trendz and how to configure them.
-
Share and embed Visualizations - Learn how to add Trendz visualizations on ThingsBoard dashboard or 3rd party web pages.
-
AI Assistant - Learn how to utilize Trendz AI capabilities.