# 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({
"4": {
"class_type": "LoadVideo",
"inputs": {
"file": "white_armored_warrior.mp4"
},
"_meta": {
"title": "Load Video"
}
},
"7": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"16:5",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"16:1": {
"class_type": "FrameInterpolationModelLoader",
"inputs": {
"model_name": "film_net_fp16.safetensors"
},
"_meta": {
"title": "Load Frame Interpolation Model"
}
},
"16:10": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"16:3",
2
],
"on_true": [
"16:11",
0
],
"switch": [
"16:13",
0
]
},
"_meta": {
"title": "If/Else Switch"
}
},
"16:11": {
"class_type": "ComfyMathExpression",
"inputs": {
"expression": "min(abs(b), 16) * a",
"values.a": [
"16:3",
2
],
"values.b": [
"16:9",
0
]
},
"_meta": {
"title": "Math Expression"
}
},
"16:13": {
"class_type": "PrimitiveBoolean",
"inputs": {
"value": True
},
"_meta": {
"title": "Boolean (Apply multiplier to FPS?)"
}
},
"16:2": {
"class_type": "FrameInterpolate",
"inputs": {
"images": [
"16:3",
0
],
"interp_model": [
"16:1",
0
],
"multiplier": [
"16:9",
0
]
},
"_meta": {
"title": "Run Frame Interpolation Model"
}
},
"16:3": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"4",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"16:5": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"16:3",
1
],
"bit_depth": "auto",
"chroma_subsampling": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": [
"16:10",
0
],
"images": [
"16:2",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"16:9": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 2
},
"_meta": {
"title": "Int (Multiplier)"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)