1- class Example:
1+ from typing_extensions import override
2+
3+ from comfy_api.latest import ComfyExtension, io
4+
5+
6+ class Example(io.ComfyNode):
27 """
3- A example node
8+ An example node
49
510 Class methods
611 -------------
7- INPUT_TYPES (dict ):
8- Tell the main program input parameters of nodes.
9- IS_CHANGED :
12+ define_schema (io.Schema ):
13+ Tell the main program the metadata, input, output parameters of nodes.
14+ fingerprint_inputs :
1015 optional method to control when the node is re executed.
16+ check_lazy_status:
17+ optional method to control list of input names that need to be evaluated.
1118
12- Attributes
13- ----------
14- RETURN_TYPES (`tuple`):
15- The type of each element in the output tuple.
16- RETURN_NAMES (`tuple`):
17- Optional: The name of each output in the output tuple.
18- FUNCTION (`str`):
19- The name of the entry-point method. For example, if `FUNCTION = "execute"` then it will run Example().execute()
20- OUTPUT_NODE ([`bool`]):
21- If this node is an output node that outputs a result/image from the graph. The SaveImage node is an example.
22- The backend iterates on these output nodes and tries to execute all their parents if their parent graph is properly connected.
23- Assumed to be False if not present.
24- CATEGORY (`str`):
25- The category the node should appear in the UI.
26- DEPRECATED (`bool`):
27- Indicates whether the node is deprecated. Deprecated nodes are hidden by default in the UI, but remain
28- functional in existing workflows that use them.
29- EXPERIMENTAL (`bool`):
30- Indicates whether the node is experimental. Experimental nodes are marked as such in the UI and may be subject to
31- significant changes or removal in future versions. Use with caution in production workflows.
32- execute(s) -> tuple || None:
33- The entry point method. The name of this method must be the same as the value of property `FUNCTION`.
34- For example, if `FUNCTION = "execute"` then this method's name must be `execute`, if `FUNCTION = "foo"` then it must be `foo`.
3519 """
36- def __init__(self):
37- pass
3820
3921 @classmethod
40- def INPUT_TYPES(s) :
22+ def define_schema(cls) -> io.Schema :
4123 """
42- Return a dictionary which contains config for all input fields.
43- Some types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT".
44- Input types "INT", "STRING" or "FLOAT" are special values for fields on the node.
45- The type can be a list for selection.
46-
47- Returns: `dict`:
48- - Key input_fields_group (`string`): Can be either required, hidden or optional. A node class must have property `required`
49- - Value input_fields (`dict`): Contains input fields config:
50- * Key field_name (`string`): Name of a entry-point method's argument
51- * Value field_config (`tuple`):
52- + First value is a string indicate the type of field or a list for selection.
53- + Second value is a config for type "INT", "STRING" or "FLOAT".
24+ Return a schema which contains all information about the node.
25+ Some types: "Model", "Vae", "Clip", "Conditioning", "Latent", "Image", "Int", "String", "Float", "Combo".
26+ For outputs the "io.Model.Output" should be used, for inputs the "io.Model.Input" can be used.
27+ The type can be a "Combo" - this will be a list for selection.
5428 """
55- return {
56- "required": {
57- "image": ("IMAGE",),
58- "int_field": ("INT", {
59- "default": 0,
60- "min": 0, #Minimum value
61- "max": 4096, #Maximum value
62- "step": 64, #Slider's step
63- "display": "number", # Cosmetic only: display as "number" or "slider"
64- "lazy": True # Will only be evaluated if check_lazy_status requires it
65- }),
66- "float_field": ("FLOAT", {
67- "default": 1.0,
68- "min": 0.0,
69- "max": 10.0,
70- "step": 0.01,
71- "round": 0.001, #The value representing the precision to round to, will be set to the step value by default. Can be set to False to disable rounding.
72- "display": "number",
73- "lazy": True
74- }),
75- "print_to_screen": (["enable", "disable"],),
76- "string_field": ("STRING", {
77- "multiline": False, #True if you want the field to look like the one on the ClipTextEncode node
78- "default": "Hello World!",
79- "lazy": True
80- }),
81- },
82- }
83-
84- RETURN_TYPES = ("IMAGE",)
85- #RETURN_NAMES = ("image_output_name",)
86-
87- FUNCTION = "test"
88-
89- #OUTPUT_NODE = False
90-
91- CATEGORY = "Example"
92-
93- def check_lazy_status(self, image, string_field, int_field, float_field, print_to_screen):
29+ return io.Schema(
30+ node_id="Example",
31+ display_name="Example Node",
32+ category="Example",
33+ inputs=[
34+ io.Image.Input("image"),
35+ io.Int.Input(
36+ "int_field",
37+ min=0,
38+ max=4096,
39+ step=64, # Slider's step
40+ display_mode=io.NumberDisplay.number, # Cosmetic only: display as "number" or "slider"
41+ lazy=True, # Will only be evaluated if check_lazy_status requires it
42+ ),
43+ io.Int.Input(
44+ "int_field",
45+ min=0,
46+ max=4096,
47+ step=64, # Slider's step
48+ display_mode=io.NumberDisplay.number, # Cosmetic only: display as "number" or "slider"
49+ lazy=True, # Will only be evaluated if check_lazy_status requires it
50+ ),
51+ io.Combo.Input("print_to_screen", options=["enable", "disable"]),
52+ io.String.Input(
53+ "string_field",
54+ multiline=False, # True if you want the field to look like the one on the ClipTextEncode node
55+ default="Hello world!",
56+ lazy=True,
57+ )
58+ ],
59+ outputs=[
60+ io.Image.Output(),
61+ ],
62+ )
63+
64+ @classmethod
65+ def check_lazy_status(cls, image, string_field, int_field, float_field, print_to_screen):
9466 """
9567 Return a list of input names that need to be evaluated.
9668
@@ -107,7 +79,8 @@ class Example:
10779 else:
10880 return []
10981
110- def test(self, image, string_field, int_field, float_field, print_to_screen):
82+ @classmethod
83+ def execute(cls, image, string_field, int_field, float_field, print_to_screen) -> io.NodeOutput:
11184 if print_to_screen == "enable":
11285 print(f"""Your input contains:
11386 string_field aka input text: {string_field}
@@ -116,7 +89,7 @@ class Example:
11689 """)
11790 #do some processing on the image, in this example I just invert it
11891 image = 1.0 - image
119- return (image, )
92+ return io.NodeOutput (image)
12093
12194 """
12295 The node will always be re executed if any of the inputs change but
@@ -127,7 +100,7 @@ class Example:
127100 changes between executions the LoadImage node is executed again.
128101 """
129102 #@classmethod
130- #def IS_CHANGED (s, image, string_field, int_field, float_field, print_to_screen):
103+ #def fingerprint_inputs (s, image, string_field, int_field, float_field, print_to_screen):
131104 # return ""
132105
133106# Set the web directory, any .js file in that directory will be loaded by the frontend as a frontend extension
@@ -143,13 +116,13 @@ async def get_hello(request):
143116 return web.json_response("hello")
144117
145118
146- # A dictionary that contains all nodes you want to export with their names
147- # NOTE: names should be globally unique
148- NODE_CLASS_MAPPINGS = {
149- "Example": Example
150- }
119+ class ExampleExtension(ComfyExtension):
120+ @override
121+ async def get_node_list(self) -> list[type[io.ComfyNode]]:
122+ return [
123+ Example,
124+ ]
125+
151126
152- # A dictionary that contains the friendly/humanly readable titles for the nodes
153- NODE_DISPLAY_NAME_MAPPINGS = {
154- "Example": "Example Node"
155- }
127+ async def comfy_entrypoint() -> ExampleExtension: # ComfyUI calls this to load your extension and its nodes.
128+ return ExampleExtension()
0 commit comments