Nodes/APZmedia Naming Tools/APZmedia Text To Hash
ComfyUI Node

APZmedia Text To Hash

Stamp a deterministic hash on your filenames and stop worrying about collisions

By APZmedia·Created 2 years ago·Updated 5 months ago· 8
APZmedia Text To Hash
  • input_value
  • hash
hash_length8

Sooner or later you need a short, unique ID to slap on a filename - a deduplication tag, a content fingerprint, a way to tell two versions of the same prompt apart. APZmedia Text To Hash gives you that with one input, one widget, and one output. You feed it any text or number, it returns a deterministic SHA-256 hash of fixed length, and that's the whole job.

The two inputs are input_value (typed *, so it accepts strings, numbers, anything, and coerces to string) and hash_length - an integer from 1 to 64, default 8. The single output is hash, a STRING. The mechanism is about as transparent as it gets: str(input_value) → SHA-256 hex digest → take the first hash_length characters. Same input always produces the same output, which is the entire point of "deterministic" - the node is explicitly a hash of content, not a random UUID.

Where you'll actually use it in a naming pipeline:

  • Content fingerprinting. Hash the prompt, or the seed plus prompt, and stamp the result onto the filename. Run the same prompt again and you get the same name - run a different prompt and you get a different one. It's a poor-man's dedup.
  • Making unique IDs without a counter. APZmediaCycleInt gives you sequential numbers that reset on restart; a hash gives you a stable ID derived from the content itself. They solve different problems and pair well.
  • Satisfying a "serious pipeline" aesthetic. The README admits this is also for "making your workflow look more serious than it is." Fair.

A few honest caveats. The default hash_length of 8 is a slice of the hex digest, not a full SHA-256 - at 8 hex chars you have 32 bits of entropy, which is plenty for a few hundred files and absolutely not collision-proof if you're hashing tens of thousands of distinct inputs. If you want to be safe, bump it to 12–16; the node allows up to the full 64. Also note the truncation is a simple prefix slice, so a longer hash_length is a different string, not a refinement of the shorter one - if you ever change the length, every downstream name changes too. Pick a length and stick with it. And because it hashes whatever text you give it verbatim, whitespace or case changes alter the result; feed it a normalized string (say, through APZmediaDictionaryReplace) if you want stable IDs from slightly messy input.

Install

ComfyUI Manager → search "APZmedia Naming Tools". Or:

cd ComfyUI/custom_nodes
git clone https://github.com/APZmedia/ComfyUI-APZmedia-cleanName-from-string
cd ComfyUI-APZmedia-cleanName-from-string
pip install -e .

Restart, find it under APZmedia. Standard-library hashlib under the hood, no model downloads, no real dependencies. It's a five-minute add to any workflow that wants a stable content-derived ID without pulling in a full utilities pack.

CategoryAPZmedia

Inputs (2)

NameTypeDefaultDescription
input_value*
hash_lengthINT81–64

Outputs (1)

NameTypeDescription
hashSTRING