Skip to content

Python Helpers

These are the essential helper functions inherited from BaseNode that you will use in almost every custom node.

The single source of truth for retrieving data. It automatically attempts to fetch the value from connected inputs wires, then widgets, and finally defaults.

def execute(self, data):
# Get "Strength" from wire or slider, default to 1.0
strength = self.get_input(data, "Strength", 1.0)

Standardizes your results. Wraps your return data in the correct dictionary format required by the frontend. Always use this to return data.

# Returning a single image path
return self.pack_outputs([output_path])
# Returning multiple outputs
return self.pack_outputs([output_path_1, output_path_2])

Updates the UI progress bar. Use this for nodes that take a long time to process (e.g., AI generation, rendering).

self.report_progress(50, "Processing frame 5/10...")

Handles Batch Inputs. If your node processes lists of data (like video frames), this ensures all inputs match the length of your primary input (master).

  • master: The primary list (e.g., images).
  • others: Other lists to synchronize (e.g., prompts).
  • Returns: A tuple of synchronized lists + the count.
# Usage Example:
# images = [img1, img2, img3] (3 frames)
# prompts = [prompt1] (1 prompt)
(s_images, s_prompts, count) = self.sync_to_master(images, prompts)
# Result:
# s_images = [img1, img2, img3]
# s_prompts = [prompt1, prompt1, prompt1] (Repeated to match)
# count = 3

Saves a PIL Image to the session temp folder. Returns the HTTP path needed by the frontend to display the image.

from PIL import Image
# ... create image ...
output_path = self.save_image(my_pil_image, prefix="generated_preview")

self.save_file(data, prefix="file", ext="bin")

Section titled “self.save_file(data, prefix="file", ext="bin")”

Saves raw data/text to the session temp folder.

# Save a text log
log_path = self.save_file("Processing complete.", prefix="log", ext="txt")

Copies an input file to the session temp folder. Useful if you want to modify a file passed from another node without changing the original.

# 'input_file' might be from a different session or read-only location
temp_path = self.load_to_temp(input_file)
# Now you can safely edit 'temp_path'

FileManager.get_session_temp_dir(session_id)

Section titled “FileManager.get_session_temp_dir(session_id)”

Gets the safe temporary directory for this execution. Use this if you need to create custom folders or save complex assets.

from node_utils import FileManager
def execute(self, data):
session_dir = FileManager.get_session_temp_dir(self.session_id)
# Result: Path('.../temp/session_123/NodeName_456/')