Python Function icon

Python Function

Execute a python function

Overview

This node allows users to execute a Python function remotely via an API. It is designed to call a specific Python function by name or ID, passing in user-defined arguments, and then returning the result of that function execution. This is useful when you want to integrate custom Python logic into your n8n workflows without running Python code locally.

Common scenarios include:

  • Running data processing or transformation functions written in Python.
  • Leveraging existing Python-based APIs or services within an automation workflow.
  • Extending n8n capabilities with complex computations or machine learning models implemented in Python.

For example, you might use this node to call a Python function that analyzes text sentiment, processes images, or performs scientific calculations, feeding input data from previous nodes and using the output downstream.

Properties

Name Meaning
Function Name or ID Select the Python function to execute from a list or specify its ID using an expression.
Arguments Define the input arguments for the Python function. Supports mapping fields from previous nodes and auto-mapping.

Output

The node outputs a JSON array where each element corresponds to the response from executing the Python function for each input item. The structure of each JSON object depends on the Python function's return value but generally contains the processed data or results returned by the function.

No binary data output is indicated.

Dependencies

  • Requires an external API service accessible via HTTP that executes Python functions. The base URL for this service is provided through credentials.
  • Needs an API key or authentication token configured in the node’s credentials to authorize requests to the Python function execution server.
  • The node uses HTTP POST requests to send function arguments and receive results.

Troubleshooting

  • Common issues:

    • Incorrect or missing API credentials will cause authentication failures.
    • Specifying a non-existent function name or ID will likely result in errors from the remote API.
    • Malformed or incomplete arguments may cause the Python function to fail or return errors.
    • Network connectivity problems can prevent communication with the Python execution server.
  • Error messages:

    • Authentication errors typically indicate invalid or missing credentials; verify and update the API key/token.
    • HTTP request failures may show status codes like 404 (function not found) or 500 (server error); check the function name and server health.
    • JSON parsing or unexpected response errors suggest issues with the remote function implementation or argument formatting.

To resolve these, ensure correct credentials are set, validate function names/IDs, carefully prepare arguments, and confirm the remote Python service is operational.

Links and References

Discussion