- Overview
- Python Executor Standalone Installation
- How to Migrate Trendz Python Executor 1.13.3 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).
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
16
version: '3.0'
services:
mypyexecutor:
restart: always
image: "thingsboard/trendz-python-executor:1.14.0"
ports:
- "8181:8181"
environment:
SCRIPT_ENGINE_RUNTIME_TIMEOUT: 30000
EXECUTOR_MANAGER: 1
EXECUTOR_SCRIPT_ENGINE: 6
THROTTLING_QUEUE_CAPACITY: 10
THROTTLING_THREAD_POOL_SIZE: 6
NETWORK_BUFFER_SIZE: 10485760
volumes:
- ~/.mytrendz-data/python-executor:/python-executor
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.14.0- Docker image for Trendz Python ExecutorSCRIPT_ENGINE_RUNTIME_TIMEOUT- timeout for Python script execution~/.mytrendz-data/python-executor:/python-executor- mounts the volume~/.mytrendz-data/python-executorto Trendz Python Executor additional data directory
Step 2: Create Volumes
Run the following commands before starting the Docker container. These commands also change the owner of the newly
created folders to the Docker container user. The chown command requires sudo permissions and will prompt for your password:
1
2
mkdir -p ~/.mytrendz-data && sudo chown -R 799:799 ~/.mytrendz-data
mkdir -p ~/.mytrendz-data/python-executor && sudo chown -R 799:799 ~/.mytrendz-data/python-executor
Note: Replace the directory ~/.mytrendz-data with the directories you plan to use in docker-compose.yaml.
Step 3: Start Python Executor
1
2
docker compose up -d
docker compose logs -f mypyexecutor
Step 4: Connect Trendz to Python Executor
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 actual host and port values.
How to Migrate Trendz Python Executor 1.13.3 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.
Modify Docker Compose File
Locate the docker-compose.yaml file from which the Python Executor was launched.
Change the Python Executor image tag to version 1.14.0:
1
image: "thingsboard/trendz-python-executor:1.14.0"
Add the following lines at the end of the Python Executor configuration:
1
2
volumes:
- ~/.mytrendz-data/python-executor:/python-executor
The final docker-compose.yaml should look like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
version: '3.0'
services:
mypyexecutor:
restart: always
image: "thingsboard/trendz-python-executor:1.14.0"
ports:
- "8181:8181"
environment:
SCRIPT_ENGINE_RUNTIME_TIMEOUT: 30000
EXECUTOR_MANAGER: 1
EXECUTOR_SCRIPT_ENGINE: 6
THROTTLING_QUEUE_CAPACITY: 10
THROTTLING_THREAD_POOL_SIZE: 6
NETWORK_BUFFER_SIZE: 10485760
volumes:
- ~/.mytrendz-data/python-executor:/python-executor
Create Volumes for Python Executor
Run the following commands before starting the Docker container. These commands also change the owner of the newly
created folders to the Docker container user. The chown command requires sudo permissions and will prompt for your password:
1
2
mkdir -p ~/.mytrendz-data && sudo chown -R 799:799 ~/.mytrendz-data
mkdir -p ~/.mytrendz-data/python-executor && sudo chown -R 799:799 ~/.mytrendz-data/python-executor
Note: Replace the directory ~/.mytrendz-data with the directories you plan to use in docker-compose.yaml.
Restart Python Executor
Restart the Python Executor to apply the changes:
1
2
docker compose restart -d
docker compose logs -f mypyexecutor
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. Locate the Volume
The volume is usually at:
1
cd ~/.mytrendz-data/python-executor
Step 2. Add a requirements.txt File
Create the file with the library:
1
echo 'emoji==2.2.0' > requirements.txt
Step 3. Restart the Docker Container
Find the container name and restart it:
1
2
docker compose ps
docker compose restart mypyexecutor
Step 4. Verify Installation
Check the logs:
1
docker compose logs mypyexecutor
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.