Taipy Core provides the key concept of Scenario. Among other functionalities, a Scenario represents an instance of a data science problem with its datasets (modeled as Data nodes in Taipy Core) and holds the algorithms used to solve the problem. The algorithms are modeled as an execution graph (a Directed Acyclic Graph or DAG) that can be seen as a succession of functions (or Tasks) that exchange data. With Taipy Core, you can model simple or very complex algorithms.
This section aims to build a Hello world example to show how to quickly configure, create and submit a scenario. The following picture represents the scenario execution graph made of two data nodes (blue boxes) and one task (orange box).
It first consists in one data node named name. It represents an input data node. Then a task named build message takes the first data node and returns a second data node named message.
Building the corresponding Taipy Core application requires three easy steps.
Configuring the application¶
The purpose is to configure the structure of the execution graph. It includes in particular the configuration of the data nodes, tasks, and scenarios.
1 2 3 4 5 6 7 8 9 10 11
In lines 4-5, we define the function used later in the task to configure.
In lines 8 and 9, we configure the two data nodes named name and message.
In line 10, we configure the task named build_msg representing the function
Since the function has one parameter and returns one value, the task has one input data node name and one
output data node message.
Finally, in line 11, we configure the execution graph of the scenario providing the previously configured task.
Running Core service¶
Running Taipy Core as a service allows Taipy to set up all necessary variables to use Core functionalities.
1 2 3 4
Line 3 is a standard boilerplate code that ensures the code is executed only from the main module. It protects users from accidentally invoking the script when they didn't intend to. We strongly recommend using it.
In line 4, we simply instantiate and run a Core service.
Creating Scenarios and accessing data¶
Now you can create and manage Scenarios, submit the graph of Tasks for execution, and access the data nodes.
1 2 3 4 5 6 7 8 9 10 11
In line 3, method
tp.create_scenario() instantiates the new scenario
from the scenario configuration built before.
In line 4, we get the input data node
name of the
zinedine_scenario and set its data
with the string value
"Zinedine" using the method
In line 5, the
zinedine_scenario is submitted for an execution. This triggers the creation
and execution of a job. This job reads the input data node, passes the value
to the function
build_message() and writes the result in the output data node.
Line 6 reads and prints the output data node
message that has been written by the execution
of the scenario
In line 8, we use the same scenario configuration to instantiate a second scenario:
Similarly, in lines 9-11, we write some value in its input data node, submit it and print the result written
in its output data node.
Here is the complete python code corresponding to the example:
And here is the expected output.
[2023-02-08 20:19:35,062][Taipy][INFO] job JOB_build_msg_9e5a5c28-6c3e-4b59-831d-fcc8b43f882e is completed. Hello Zinedine! [2023-02-08 20:19:35,395][Taipy][INFO] job JOB_build_msg_684b8a3e-8e5a-406d-8790-009565ed57be is completed. Hello Kylian Mbappe!
This third step consists in calling the various Core APIs to access, manage and submit the Taipy entities. Typically it is implemented in Python functions that are called by a graphical interface built with Taipy GUI.
For example, the
tp.create_scenario() or the
methods are called when clicking respectively on a "create scenario" or "submit scenario" buttons.
When displaying a data node in a graphical component (chart, table, etc. ) the
method are called to edit and retrieve the data.
Please refer to the Getting started with Core manual for a more realistic use case.