# 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({
"1": {
"class_type": "MagnificImageUpscalerCreativeNode",
"inputs": {
"auto_downscale": True,
"creativity": 2,
"engine": "automatic",
"fractality": 0,
"hdr": 3,
"image": [
"2",
0
],
"optimized_for": "standard",
"prompt": "A monumental bronze bust of an ancient celestial sovereign, cast in patinated bronze and oxidized verdigris copper, with a fan-shaped crest of pierced geometric fretwork behind the head. Every surface is covered in fine guilloché engraving, arabesque filigree, repoussé acanthus leaves and beaded copper borders, with crisp tool marks and stippled metal grain. Alternating bands of seafoam-green patina and burnished warm copper catch a low amber cross-light, throwing razor-sharp shadows into every groove. The sculpture stands on dark basalt flagstones against polished charcoal slate. Ultra-sharp museum photograph with deep focus, rich verdigris, turquoise, copper and umber tones, and realistic weathered metal and stone texture throughout.",
"resemblance": 1,
"scale_factor": "4x"
},
"_meta": {
"title": "Magnific Image Upscale (Creative)"
}
},
"2": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"3": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"1",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"4": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": {
"__value__": [
"",
""
]
},
"image_a": [
"2",
0
],
"image_b": [
"1",
0
]
},
"_meta": {
"title": "Compare Images"
}
}
})
workflow.set_input("2", "image", client.assets.from_url("https://comfy.org/catalog-media/d522573d-afaa-4e8e-b354-e5cfa064ecb1/1c19562f-8f81-41b1-8b11-34b11e129c46"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)
for output in job.get_outputs("3"):
output.to_file(output.name)