Skip to main content
Skip table of contents

Code Execution

The Code Execution node is a powerful feature that allows you to write and execute custom Python code directly within your tool. This node is ideal for performing advanced computations, data transformations, or custom logic that cannot be achieved using other nodes. By leveraging Python, you can extend the functionality of your tools and handle complex scenarios with precision.

Overview

The Code Execution node enables you to write Python code in a dedicated editor and execute it during the tool's workflow. Input variables can be mapped to the function parameters, and the output of the code can be stored in a variable for use in subsequent steps.

Key Components

Code Editor

The code editor is where you write your Python code. The editor provides a clean and focused environment for coding, with syntax highlighting to improve readability. Please note that Python code blocks are separate environments in which HALO controls the allowed package imports and their permitted functionalities.

Notes on method access:

  • Module methods: Available by default for all allowed packages

  • Classes: Must be explicitly listed in the configuration to be used

  • Instance methods: Automatically available for allowed classes

  • Class methods: Must be explicitly enabled in the configuration for each class

Allowed Python Packages

Package

Classes

Class Methods

_strptime

-

-

base64

-

-

cryptography

-

-

datetime

datetime.datetime
datetime.date
datetime.time
datetime.timedelta

datetime.datetime:

  • now

  • utcnow

  • today

  • fromtimestamp

  • fromisoformat

  • strptime

  • combine

  • _strptime

datetime.time:

  • fromisoformat

google

google.cloud.bigquery.Client
google.oauth2.service_account.Credentials

google.cloud.bigquery.Client:

  • all class methods allowed

google.oauth2.service_account.Credentials:

  • all class methods allowed

json

-

-

jwt

-

-

math

-

-

random

-

-

re

re.Match
re.Pattern

-

request

requests.Request
request.Response
requests.cookies.RequestsCookieJar

-

time

-

-

typing

-

-

uuid

-

-

  • Function Definition: The code must be written inside the predefined main function. This function serves as the entry point for the code execution.

    • Example:

      CODE
      def main(result):
          # Your custom logic here
          return result
  • Return Statement: The main function must return a value. This value will be stored in the output variable and can be used in subsequent steps.

image-20250515-135019.png

Function Parameters Mapping

The Function Parameters Mapping section allows you to map input variables to the parameters of the main function. This ensures that the data required for the code execution is passed correctly.

  • Input Variables: Select the input variables from the dropdown menu to map them to the function parameters.

  • Custom Parameters: You can define additional parameters in the main function and map them to specific variables or values.

image-20250515-135203.png

Example:

  • If the main function is defined as:

    CODE
    def main(a, b):
        return a + b

    You would need to add a and b in the parameters list and map them to a variable.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.