ComfyUI Node

set

Add or update a key in a dict the way Python would — one node, one line

By StableLlama·Created about a year ago·Updated 4 days ago· 48
set
  • input_dict
  • value
  • DICT
key

Every dict workflow eventually needs to do the same thing: put a value in under a key. That's the whole job of set (Basic data handling: DictSet), and it does it with exactly the semantics you'd get from my_dict["key"] = value in Python - add if new, overwrite if it exists.

Three required inputs:

  • input_dict - the DICT you're modifying
  • key - the key to set, as a STRING
  • value - the value to store (ANY type, so strings, floats, other dicts, even lists)

and one output, the modified DICT.

It's a thin wrapper over the language: the node copies the dict, does result[key] = value, and returns the copy. The original dict stays untouched, which keeps this safe to drop into any branch of a workflow without side effects leaking into other wires.

When you'd actually use it

Dicts in ComfyUI are your way to carry bundles of data around the graph - think settings, prompts, per-item metadata. DictSet is how you add a new field or patch an existing one as data flows past. A common pattern: start with DictCreate, thread the DICT through a few DictSet nodes adding one field at a time, and read it back later with DictGet or hand it to the pack's DictItems. It's a tiny node, but it's the thing that makes "accumulate data as you go" possible.

A subtle thing to note: there's only a DICT output here - no "success" flag, no value returned. If the key was already there, it gets silently replaced. If that matters to you (say you want to know whether you're creating or overwriting), reach for this pack's setdefault, which returns the resulting value and only sets when the key is missing. For plain "put this in the dict," set is the one.

Installing it

This node is part of the Basic data handling pack by StableLlama. In ComfyUI Manager, search "Basic data handling", install, restart. Manual install:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

then restart ComfyUI. The pack has no dependencies (dependencies = [] in its pyproject), no requirements.txt, and no model downloads - this is plain Python.

Troubleshooting

Two things to keep in mind. First, the DICT type is custom to this pack, so both the input and output sockets only connect to other nodes that speak DICT - don't try to run the output into a standard STRING or INT socket expecting it to convert itself; use a cast node for that. Second, keys are exact strings: setting "seed" and later looking up "Seed" are two different keys, and the data will look like it vanished. Decide on a naming convention for your dict keys early and stick to it.

CategoryBasic/DICT

Inputs (3)

NameTypeDefaultDescription
input_dictDICT
keySTRING
value*

Outputs (1)

NameTypeDescription
DICTDICT