ComfyUI Node

ListUnWrapper

Turn a Python list into a real ComfyUI for-each

By lldacing·Created 3 years ago·Updated 8 months ago· 96
ListUnWrapper
  • lst
  • *

ComfyUI's graph looks like it should support loops - it's a visual DAG, surely you can wire something back into itself? You can't; cycles aren't allowed. What ComfyUI does have, quietly, is a different mechanism that gets you most of the way there: a node can mark an output as a list, and when it does, the scheduler re-runs every downstream node once per item instead of once for the whole batch. Almost nothing exposes this directly. ListUnWrapper does, and it's the closest thing this pack gives you to a real for-each.

How it works

Feed it any Python list and it flips that switch. Nothing about the data changes - the node doesn't transform your values at all - it just re-declares the output as list-typed, which tells ComfyUI's execution engine to iterate rather than pass the list through as one unit. Everything wired downstream of it then runs once per element, exactly as if you'd copy-pasted that branch of the graph N times.

The inputs and outputs that matter

There's exactly one input and one output, and both are untyped (*), so ComfyUI won't stop you wiring in anything:

  • lst - the list you want to iterate. This is usually something built with ListWrapper (this pack's counterpart), or a LIST coming out of LoadJsonStrToList or LoadLocalFilePath's paths output.
  • The single output is also *, but marked as a list output - plug it into anything and that node runs once per item, collecting results as it goes.

Where you'd actually use it

The pack's own example is previewing images at different sizes. Batch a handful of differently-sized images together and ComfyUI's normal batching either errors or forces a resize to match. Instead: wrap the images into a list with ListWrapper, run that list through ListUnWrapper, and wire the result into PreviewImage. It now runs once per image at its own size, instead of trying to force them into one tensor.

More generally, this is the node you reach for anywhere you'd write a for loop in real code - process every file LoadLocalFilePath found, run a step once per item in a LoadJsonStrToList result, and so on.

How to install it

Via ComfyUI Manager: search comfyui-easyapi-nodes (or EasyApi), install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/lldacing/comfyui-easyapi-nodes.git
cd comfyui-easyapi-nodes
pip install -r requirements.txt

Restart ComfyUI. To upgrade later, git pull inside that same folder. No models, no heavy dependencies - this whole pack is glue code for API-style workflows.

Common issues & troubleshooting

Because lst is untyped, ComfyUI can't validate what's actually flowing into it. If you feed it something that isn't really a list - a single image tensor, say - don't expect a clean type error; you'll more likely get a single pass through with no warning that the "loop" never happened.

The bigger trap is cost, not correctness. A list of 20 items downstream of ListUnWrapper means the rest of that branch runs 20 times, full stop. If anything further down calls an external or paid API node, that's 20x the calls, and ComfyUI won't warn you ahead of time - it just executes the graph as instructed. Check the size of whatever list you're unwrapping before you fire off a run you didn't mean to multiply.

CategoryEasyApi/List

Inputs (1)

NameTypeDefaultDescription
lst*

Outputs (1)

NameTypeDescription
**