Python scripts can be run from TD Workflow or Digdag, using the Python operator py>. You can create your workflows for TD using the TD Console or from the command line.
For the workflow to run the Python script, you must specify a Docker image. When the workflow task starts, a new Docker container is created based on the specified Docker image. Docker allows the Python script to execute in the container in an isolated environment.
Running this tutorial takes about 30 minutes and does not require that you have prior experience with Python or Docker images.
Make sure this feature is enabled for your TD account.
Download and install the TD Toolbelt and the TD Toolbelt Workflow module. For more information, see Using Treasure Workflow
Python 3.9. Your Python code must be compatible with those versions.
Basic Knowledge of Treasure Workflow's syntax
The Python scripts in TD Workflows are managed and run by Treasure Data in isolated Docker containers. Treasure Data provides a number of base Docker images to run in the container.
import os
import sys
os.system(f"{sys.executable} -m pip install tensorflow")
import tensorflow3rd-party Python libraries can be installed from your Python script using the pip install command.
- To add more libraries from within your Python script use:
pip install ${package_name}See examples, for basics such as:
How to call functions
How to pass parameters to functions
How to use environment variables
How to import functions
The examples show how to read data in Treasure Data into a Dataframe, manipulate data, and write it back to Treasure Data as a table.
You can copy or clone the entire repository.
Navigate to:
treasure-boxes/integration-box/python/simple.digFrom the command line, type
lsto verify that you are in the correct directory. You should see the following:README.md other_scripts scripts simple.digPush the simple examples to your TD environment by typing the following:
td wf push simple-exampleThis runs the simple.dig workflow and uploads the simple-example to TD.
Open TD Console.
Navigate to Workflows.
Search for simple.
Double click the simple workflow to open up the editor. For example:

- Select New Run.

- Type
td wf start simple-example simple --session now

From the TD Console, navigate to the workflow editor.
Select Run History.

- If there are multiple instances of the job, select one to open the job history. From here you can view at what time the job ran, audit logs, and other helpful diagnostic information about the job.
