Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Adding new StringFormat node (#13997)

Pauan7ec7b6ffe93b
diff --git a/comfy_extras/nodes_string.py b/comfy_extras/nodes_string.py
index 925a40da8..97485c8c5 100644
--- a/comfy_extras/nodes_string.py
+++ b/comfy_extras/nodes_string.py
@@ -1,10 +1,41 @@
import re
import json
+import string
from typing_extensions import override
from comfy_api.latest import ComfyExtension, io
+class StringFormat(io.ComfyNode):
+ @classmethod
+ def define_schema(cls) -> io.Schema:
+ autogrow = io.Autogrow.TemplateNames(
+ input=io.AnyType.Input("value"),
+ names=list(string.ascii_lowercase),
+ min=0,
+ )
+ return io.Schema(
+ node_id="StringFormat",
+ display_name="Format Text",
+ category="text",
+ search_aliases=["string", "format"],
+ description="Same as Python's string format method. Supports all of Python's format options and features.",
+ inputs=[
+ io.Autogrow.Input("values", template=autogrow),
+ io.String.Input("f_string", default="{a}", multiline=True),
+ ],
+ outputs=[
+ io.String.Output(),
+ ],
+ )
+
+ @classmethod
+ def execute(
+ cls, values: io.Autogrow.Type, f_string: str
+ ) -> io.NodeOutput:
+ return io.NodeOutput(f_string.format(**values))
+
+
class StringConcatenate(io.ComfyNode):
@classmethod
def define_schema(cls):
@@ -413,6 +444,7 @@ class StringExtension(ComfyExtension):
@override
async def get_node_list(self) -> list[type[io.ComfyNode]]:
return [
+ StringFormat,
StringConcatenate,
StringSubstring,
StringLength,