A simple way to schedule ComfyUI prompts with different parameters
Project description
Comfy API Simplified
This is a small python wrapper over the ComfyUI API. It allows you to edit API-format ComfyUI workflows and queue them programmaticaly to the already running ComfyUI.
I use it to iterate over multiple prompts and key parameters of workflow and get hundreds of images overnight to cherrypick from.
Limitations
Only Basic auth and no auth (for local server) are supported.
Install
pip3 install comfy_api_simplified
Use prerequisits
Prepare workflow
You would like to have your node titles unique. Usually both positive and negative prompts have title "CLIP Text Encode (Prompt)", you would like to at least give them different names in case you would like to change it's parameters from python.
Enable "dev options"
In ComfyUI settings, check "Enable Dev mode Options":
Download your workflow in API-format
Have running ComfyUI server
Use
from comfy_api_simplified import ComfyApiWrapper, ComfyWorkflowWrapper
# create api wrapper using your ComfyUI url (add user and password params if needed)
api = ComfyApiWrapper("http://127.0.0.1:8188/")
# create workflow wrapper using your downloaded in api format workflow
wf = ComfyWorkflowWrapper("workflow_api.json")
# change anything you like in your workflow
# the syntax is "Node Title", then "Input param name", then value
wf.set_node_param("Empty Latent Image", "batch_size", 2)
wf.set_node_param("negative", "text", "embedding:EasyNegative")
# queue your workflow for completion
results = api.queue_and_wait_images(wf, "Save Image")
for filename, image_data in results.items():
with open(f"{filename}", "wb+") as f:
f.write(image_data)
More examples:
-
Queue prompt and get result images example.
-
Queue many prompts and do not wait for completion example.
-
Send input image and then call i2i workflow example.
Additional info
There are some other approaches to use Python with ComfyUI out there.
If you are looking to conver your workflows to backend server code, check out ComfyUI-to-Python-Extension
If you are looking to use running ComfyUI as backend, but declare workflow in Python imperatively, check out ComfyScript.
Known issues
If you try to run queue_and_wait_images in async method, it may give you an error since there is already async code inside. As a workaround, you can use
import nest_asyncio
nest_asyncio.apply()
for now.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file comfy_api_simplified-1.2.1.tar.gz
.
File metadata
- Download URL: comfy_api_simplified-1.2.1.tar.gz
- Upload date:
- Size: 878.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf1eb0742636537198b684e673ae2f3e95d46808c877848e42fa9e1482d8331a |
|
MD5 | 78a55a14a3a5b5c55e72cbdf12fce506 |
|
BLAKE2b-256 | 290810c08896e8b58eb1b8d51abb5dbf7927fac7cdb431f4b0e25c208ab68d01 |
File details
Details for the file comfy_api_simplified-1.2.1-py3-none-any.whl
.
File metadata
- Download URL: comfy_api_simplified-1.2.1-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1471ff22e64fe75e33716dcc8926c7fff419cb84cd43f4f0cbd14fbaaaa59529 |
|
MD5 | 39e9a7d70ad95410c721b16a57dfb126 |
|
BLAKE2b-256 | 6697e034ac0648831d18a1e6e489322eed979ae07343d707f1d70f15ef5130bc |