_.keys
Pull the keys out of a dict — and get a free index list for lists.
- py_dict
- LIST
_.keys does exactly what Underscore's keys does: hand you the names of an object's own enumerable properties. In Comfy terms, that means "give me the keys of this dict as a list." It's one of the more genuinely useful nodes in the underscore family, because dicts show up everywhere - metadata blobs, settings, JSON payloads - and keys are how you start doing anything with them.
What it is
Part of the ovum/underscore family in sfinktah/comfy-ovum, wrapping the keys method of underscore3, a Python port of Underscore.js. The port extends the plain behavior in ways that make it handier in a graph:
- Dict → a list of its keys.
- List or tuple →
range(len(...)), i.e.[0, 1, 2, ...]. So_.keysdoubles as a "give me an index list" node. - Other iterables with a length → same index list.
- Objects with no
.keys()→ falls back todir(obj).
That last fallback is a nice introspection trick: feed it a mystery object and you get its attribute names back, which pairs beautifully with _.methods when you're figuring out what a *-typed socket is actually carrying.
Inputs and outputs
One optional input, named py_dict (type *) - the generator labels object-ish methods that way, but the tooltip tells the real story: any JSON-serializable value works. One output, and this one is properly typed LIST, which is a pleasant surprise in a family where the generator often stamps everything *. Feed it a _.CHAIN and you get a chain back for continued chaining, resolved with _.value.
Where you'd use it
Looping is the headline. Wire _.keys into the pack's loop nodes to iterate over a dict's keys, or use the index list to fan out over a list with indices. It's also the natural setup step for _.mapObject: get the keys, understand the shape, then transform the values. And in any workflow that assembles a dict to pass downstream - say, to a JSON-writing node - _.keys is a quick way to eyeball what's actually inside.
Installing comfy-ovum
ComfyUI Manager: search for comfy-ovum, install, restart. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
pip install -r comfy-ovum/requirements.txt
Restart and you're set. No model downloads, no CUDA - pure-Python utilities. The family caveat still applies (work in progress, not production-hardened), but _.keys is one of the members you can actually build a small workflow around without feeling brave.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| py_dictopt | * | Primary input object (expected object). You can still pass any JSON-serializable value. Also accepts _.CHAIN to continue chaining. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LIST | LIST | — |