Python Helpers
These are the essential helper functions inherited from BaseNode that you will use in almost every custom node.
Input & Output
Section titled “Input & Output”self.get_input(data, name, default=None)
Section titled “self.get_input(data, name, default=None)”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)self.pack_outputs(output_list)
Section titled “self.pack_outputs(output_list)”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 pathreturn self.pack_outputs([output_path])
# Returning multiple outputsreturn self.pack_outputs([output_path_1, output_path_2])self.report_progress(percent, message="")
Section titled “self.report_progress(percent, message="")”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...")Batching & Synchronization
Section titled “Batching & Synchronization”self.sync_to_master(master, *others)
Section titled “self.sync_to_master(master, *others)”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 = 3File Operations
Section titled “File Operations”self.save_image(image, prefix="img")
Section titled “self.save_image(image, prefix="img")”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 loglog_path = self.save_file("Processing complete.", prefix="log", ext="txt")self.load_to_temp(path)
Section titled “self.load_to_temp(path)”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 locationtemp_path = self.load_to_temp(input_file)# Now you can safely edit 'temp_path'Path Management
Section titled “Path Management”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/')