# Python 3.10+: pip install comfy-sdk==0.4.0
import os
from comfy_sdk import Comfy
api_key = os.environ.get("COMFY_API_KEY", "").strip()
if not api_key: raise RuntimeError("Set COMFY_API_KEY")
os.environ.setdefault("COMFY_BASE_URL", "https://cloud.comfy.org")
client = Comfy(api_key=api_key)
workflow = client.workflows.from_json({
"2": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "comfyui-relight-product",
"images": [
"46:40:20",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"3": {
"class_type": "LoadImage",
"inputs": {
"image": "gsc3_landscape.png"
},
"_meta": {
"title": "Load Image"
}
},
"7": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"46:40:10": {
"class_type": "ImageCrop",
"inputs": {
"height": [
"46:40:16",
0
],
"image": [
"7",
0
],
"width": [
"46:40:15",
0
],
"x": [
"46:40:24",
0
],
"y": [
"46:40:12",
0
]
},
"_meta": {
"title": "3"
}
},
"46:40:11": {
"class_type": "ImageCrop",
"inputs": {
"height": [
"46:40:16",
0
],
"image": [
"7",
0
],
"width": [
"46:40:15",
0
],
"x": [
"46:40:13",
0
],
"y": [
"46:40:12",
0
]
},
"_meta": {
"title": "4"
}
},
"46:40:12": {
"class_type": "SimpleMath+",
"inputs": {
"a": [
"46:40:16",
0
],
"b": [
"46:40:14",
0
],
"value": "a + (b/2)"
},
"_meta": {
"title": "Row 2 - Y val"
}
},
"46:40:13": {
"class_type": "SimpleMath+",
"inputs": {
"a": [
"46:40:15",
0
],
"b": [
"46:40:14",
0
],
"value": "a + (b/2)"
},
"_meta": {
"title": "Col 2 - X val"
}
},
"46:40:14": {
"class_type": "SimpleMath+",
"inputs": {
"a": 0,
"b": 0,
"value": "a"
},
"_meta": {
"title": "🔧 Simple Math"
}
},
"46:40:15": {
"class_type": "SimpleMath+",
"inputs": {
"a": [
"46:40:17",
0
],
"b": [
"46:40:14",
0
],
"value": "(a-2*b) / 2"
},
"_meta": {
"title": "WIDTH"
}
},
"46:40:16": {
"class_type": "SimpleMath+",
"inputs": {
"a": [
"46:40:17",
1
],
"b": [
"46:40:14",
0
],
"value": "(a-2*b) / 2"
},
"_meta": {
"title": "HEIGHT"
}
},
"46:40:17": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"7",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"46:40:19": {
"class_type": "ImageBatchMulti",
"inputs": {
"image_1": [
"46:40:8",
0
],
"image_2": [
"46:40:9",
0
],
"image_3": [
"46:40:10",
0
],
"image_4": [
"46:40:11",
0
],
"inputcount": 4
},
"_meta": {
"title": "Image Batch Multi"
}
},
"46:40:20": {
"class_type": "ImageResizeKJv2",
"inputs": {
"crop_position": "center",
"device": "cpu",
"divisible_by": 2,
"height": [
"46:40:22",
0
],
"image": [
"46:40:19",
0
],
"keep_proportion": "stretch",
"pad_color": "0, 0, 0",
"upscale_method": "lanczos",
"width": [
"46:40:23",
0
]
},
"_meta": {
"title": "Resize Images"
}
},
"46:40:22": {
"class_type": "SimpleMath+",
"inputs": {
"a": [
"46:40:17",
1
],
"b": 0,
"value": "(a) / 2"
},
"_meta": {
"title": "HEIGHT / 2"
}
},
"46:40:23": {
"class_type": "SimpleMath+",
"inputs": {
"a": [
"46:40:17",
0
],
"b": 0,
"value": "(a) / 2"
},
"_meta": {
"title": "WIDTH / 2"
}
},
"46:40:24": {
"class_type": "SimpleMath+",
"inputs": {
"a": 0,
"b": [
"46:40:14",
0
],
"value": "b/2"
},
"_meta": {
"title": "Col 1 - X val"
}
},
"46:40:4": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"46:40:8",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"46:40:5": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"46:40:9",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"46:40:6": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"46:40:10",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"46:40:7": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"46:40:11",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"46:40:8": {
"class_type": "ImageCrop",
"inputs": {
"height": [
"46:40:16",
0
],
"image": [
"7",
0
],
"width": [
"46:40:15",
0
],
"x": [
"46:40:24",
0
],
"y": [
"46:40:24",
0
]
},
"_meta": {
"title": "1"
}
},
"46:40:9": {
"class_type": "ImageCrop",
"inputs": {
"height": [
"46:40:16",
0
],
"image": [
"7",
0
],
"width": [
"46:40:15",
0
],
"x": [
"46:40:13",
0
],
"y": 0
},
"_meta": {
"title": "2"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("7", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)