0CodeKit icon

0CodeKit

A toolbox of no-code utilities

Actions132

Code → ASYNC Python Script Advanced (Complex Script)

AI-generated

Overview

This node allows you to execute asynchronous Python scripts remotely by sending the code to a dedicated execution endpoint. It is designed for running complex or advanced Python scripts that may include import statements and require external dependencies. Unlike simpler code execution nodes, this one does not require you to assign your output to a specific variable; instead, you can print JSON-formatted results directly in your script, which will be captured and parsed.

Common scenarios where this node is beneficial include:

  • Running advanced data processing or analysis scripts asynchronously.
  • Executing Python code that depends on external PyPI packages or system-level dependencies.
  • Integrating custom Python logic into an n8n workflow without blocking the workflow execution.
  • Sending results back via webhook for further processing or storage.

Example use case:
You want to run a Python script that fetches data from an API, processes it with pandas (a PyPI package), and then sends the processed data back to your workflow asynchronously. You specify the required packages, write your script including imports, and provide a webhook URL to receive the output.

Properties

Name Meaning
Code The Python code string to execute asynchronously. This should include any necessary import statements. Use print() to output JSON-formatted results that will be parsed by the receiving webhook.
Requirements A list of PyPI package names your Python code requires. These packages will be installed before execution. Explicitly specifying these is recommended for accuracy and reliability.
Dependencies A list of system-level dependencies (Alpine packages) your code requires. These will be installed using the Alpine Package manager (apk) before running your script.
Send To The webhook URL where the execution result will be sent after the script finishes. This URL must be accessible to receive the POST request containing the output data.

Output

The node itself does not produce immediate output within the workflow because the Python script runs asynchronously. Instead, the output is sent as a JSON payload to the specified webhook URL once execution completes.

  • The JSON output corresponds to whatever your Python script prints. Typically, you print a JSON string representing the result data.
  • If your script prints multiple lines or non-JSON content, only the JSON-parsable output will be forwarded.
  • Binary data is not handled directly by this node; if needed, encode binary data as base64 within your JSON output.

Dependencies

  • Requires an active internet connection to send the code and dependencies to the remote execution service.
  • Needs a valid webhook URL to send back the execution results.
  • Python environment on the remote service supports installing PyPI packages and Alpine system packages.
  • Requires an API key credential configured in n8n to authenticate requests to the remote execution endpoint.

Troubleshooting

  • Missing or incorrect webhook URL: Ensure the "Send To" property contains a valid, reachable URL that can accept POST requests. Otherwise, results will be lost.
  • Dependency installation failures: If your specified PyPI or system dependencies are misspelled or unavailable, the script may fail to run. Double-check package names.
  • Syntax errors in Python code: Since the code is executed remotely, syntax errors will cause the execution to fail. Test your code locally first.
  • Output parsing issues: Make sure your script prints valid JSON strings. Invalid JSON output will cause parsing errors on the receiving end.
  • Timeouts or long-running scripts: Asynchronous execution helps avoid blocking, but extremely long scripts might still face timeouts depending on the remote service limits.

Links and References

  • Python Packaging Index (PyPI) – For finding and verifying Python package names.
  • Alpine Linux Packages – For checking available system dependencies.
  • General Python async programming concepts for writing asynchronous scripts.
  • Webhook usage and security best practices to ensure safe and reliable reception of execution results.

Discussion