# 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": "LoadImage",
"inputs": {
"image": "moonlit_cliff_house.png"
},
"_meta": {
"title": "Load Image"
}
},
"4": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"7",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"5": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"6",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"6": {
"class_type": "ImageScaleBy",
"inputs": {
"image": [
"2",
0
],
"scale_by": 4,
"upscale_method": "nearest-exact"
},
"_meta": {
"title": "Upscale Image By"
}
},
"7": {
"class_type": "TopazImageEnhanceV2",
"inputs": {
"image": [
"2",
0
],
"model": "Reimagine",
"model.color_preservation": True,
"model.creativity": 3,
"model.crop_to_fill": False,
"model.face_enhancement": True,
"model.face_enhancement_creativity": 0,
"model.face_enhancement_strength": 1,
"model.face_preservation": True,
"model.prompt": "",
"model.subject_detection": "All",
"output_height": [
"5",
1
],
"output_width": [
"5",
0
]
},
"_meta": {
"title": "Topaz Image Enhance"
}
},
"10": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": None,
"image_a": [
"2",
0
],
"image_b": [
"4",
0
]
},
"_meta": {
"title": "Compare Images"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)