Python task

This page doesn't intend to explain Python. So please refer to official Python documentation for details on it. It's about the Python task. The basic coded task features are language independent and explained in the link including:

  • Having an optional title attribute
  • Using the code in attribute with same name
  • Having an optional tag attribute
  • Having an optional variable attribute
  • Having an optional with attribute

Please note:

  • The Python command line tool is required to be found in the search path.
  • It's assumed that the name is "python"

Minimal example

The minimal example does not require a variable but the task does have one (always) with the name 'default'. The default regex is the whole text, and the default group is 0.

---
taskgroups:
  - title: test
    tasks:
      - type: python
        code: print('hello world!')

Minimal example with tags

The application can be called with the repeatable option --tag. Specifying the those filter task will be executed only contain those tags. Task with other tags or even without any tags will be ignored then.

---
taskgroups:
  - title: test
    tasks:
      - type: python
        code: print('hello world!')
        tags:
          - simple
          - example         

Example with variable

The example with variable shows how to use the variable to extract information. It's exactly the same way as it does work for other tasks. You can specify the regex for filtering and - if required

  • the regex group; the default group is 0.
---
taskgroups:
  - title: test
    tasks:
      - type: python
        title: a simple example
        code: print('---> this is a demo <---')
        variable:
          name: test2
          regex: ">(.*)<"
          group: 1

Example with templating

The task group does store a map of key/value where key is the name of the variable, and the value is a variable. If you do not specify a name for a variable the name is 'default'. In the following example the first task does write 'hello world!' into the variable, and the second task does evaluate the value from the first task. Of course the second one write into the same variable its output since also there no name has been specified.

---
taskgroups:
  - title: test
    tasks:
      - type: python
        title: a simple example 1
        code: print('hello world!')
      - type: python
        title: a simple example 2
        code: print('{{ variables.default.value }}')

In addition, you can evaluate the model if you have one.

---
model:
  description: some description

taskgroups:
  - title: test
    tasks:
      - type: python
        title: a simple example 1
        code: print('{{ model.attributest.description }}')

The rules on how to access the individual elements of a model are explained here.