Python
Task Python.
- class pydolphinscheduler.tasks.python.Python(name: str, definition: str | LambdaType, *args, **kwargs)[source]
Bases:
Task
Task Python object, declare behavior for Python task to dolphinscheduler.
Python task support two types of parameters for :param:
definition
, and here is an example:Using str type of :param:
definition
python_task = Python(name="str_type", definition="print('Hello Python task.')")
Or using Python callable type of :param:
definition
def foo(): print("Hello Python task.") python_task = Python(name="str_type", definition=foo)
- Parameters:
name – The name for Python task. It define the task name.
definition – String format of Python script you want to execute or Python callable you want to execute.
- _build_exe_str() str [source]
Build executable string from given definition.
Attribute
self.definition
almost is a function, we need to call this function after parsing it to string. The easier way to call a function is using syntaxfunc()
and we use it to call it too.
- _downstream_task_codes: Set[int]
- _task_custom_attr: set = {'definition', 'raw_script'}
- _task_relation: Set[TaskRelation]
- _timeout: timedelta
- _upstream_task_codes: Set[int]
- ext: set = {'.py'}
- ext_attr: str | LambdaType = '_definition'
- property raw_script: str
Get python task define attribute raw_script.
YAML file example
# Define the workflow
workflow:
name: "Python"
# Define the tasks within the workflow
tasks:
- name: python
task_type: Python
definition: |
import os
print(os)
print("1")
print("2")