Skip to content

Execution Overview

This section explains how to execute a function in the Python runtime. First, we examine the usage pattern, then delve into the parameter structure.

Usage Pattern

To execute a function, follow this pattern:

  1. Use dh.new_function() or project.new_function() to create the function, passing function parameters.
  2. Call function.run() with the desired action, passing task parameters and run parameters.
# Create function with function parameters
function = dh.new_function(
    name="my-function",
    kind="python",
    code_src="handler.py",
    handler="main",
    python_version="PYTHON3_10"
)

# Execute with task and run parameters
run = function.run(
    action="job",  # Task parameter
    inputs={"data": dataitem.key},  # Run parameter
    parameters={"threshold": 0.5}  # Run parameter
)

You can control whether the execution happens locally on your machine or remotely on the platform by setting the local_execution parameter (see Local vs Remote Execution for details).

Local vs Remote Execution

When executing a function, you can choose between local execution and remote execution by setting the local_execution parameter in the run parameters.

  • Local Execution (local_execution=True): The function runs directly on your local machine. You need to have the required dependencies of your function installed locally.

  • Remote Execution (local_execution=False, default): The function is executed on a remote server or cluster managed by the platform. Remember to provide the dependencies in the function's requirements parameter or in your requirements.txt.

Note

Note that some features, like serving functions, are only available with remote execution.

Parameter Structure

Parameters are organized into three categories, each serving a distinct purpose in the function execution lifecycle and in the specification of execution entities (Function, Task, Run):

  • Function Parameters: Define the function's spec attributes, such as source code, handler, Python version, and execution environment. These are set when creating the function using dh.new_function() or project.new_function().

  • Task Parameters: Specify the action type and execution environment configuration. For Python runtimes, actions are job, serve, or build.

  • Run Parameters: Control runtime behavior, such as local vs. remote execution, input mappings, and additional parameters passed to the function handler.

Detailed Documentation

For comprehensive details on each parameter category: