Skip to main content

comfy-executors

Run ComfyUI workflows conveniently on different execution backends, including local ComfyUI servers and serverless execution on RunPod or Modal. Supports workflow templating, asynchronous execution and transparent batching.

Usage

Installation

pip install comfy-executors

Export ComfyUI workflow in API format

ComfyUI has two different workflow formats. The standard format for which contains additional meta data for the UI and a reduced API version which corresponds to the actual execution graph that is send to the backend. Exporting workflows in API format has to be enabled in the developer settings first.

API format export instructions

Afterwards, a separate button for API format export should appear below the normal "Save" button:

Prepare workflow for use with comfy-executors

The ComfyUI does not support parameterization of workflows out-of-the-box, i.e. a submitted workflow (in JSON format) will be executed as it is. To allow flexible parameterization of workflows, e.g. replacing prompts and the random seeds, comfy-executors uses workflow templating via the Jinja templating engine.

To prepare a workflow for use with comfy-executors, first append the .jinja suffix to the filename, e.g. workflow.json becomes workflow.json.jinja. The nodes for loading input images and supplying the empty latent image need to be templated to obtain their value from the input_images_dir and batch_size variables respectively. This should generally as follows:

{
    "1": {
        "inputs": {
            "directory": "{{ input_images_dir }}",
            "image_load_cap": 0,
            "start_index": 0,
            "load_always": false
    },
    "class_type": "LoadImagesFromDir",
        "_meta": {
            "title": "Load Reference Images"
        }
    },
    "2": {
        "inputs": {
            "width": 896,
            "height": 1152,
            {# Batch sizes need to be templated as it will be determined by comfy-executors #}
            "batch_size": {{ batch_size|int }}
        },
    "class_type": "EmptyLatentImage",
        "_meta": {
            "title": "Empty Latent Image"
        }
    },
}

Additional variables can, of course, be introduced as well which then have to be passed to the workflow rendering function.

Submitting a workflow an execution backend

comfy-executors supports different execution backends, including local or remote ComfyUI servers and execution on serverless GPUs on RunPod or Modal.

The RunpodComfyWorkflowExecutor class provides functionality to submit a workflow template to RunPod and handle the results.

ComfyUI server

from comfy_api_client import create_client
from comfy_executors import ComfyServerWorkflowExecutor, WorkflowTemplate

comfyui_server = "localhost:8188"

workflow_template = WorkflowTemplate.from_file("workflow.json.jinja")

async with ComfyServerWorkflowExecutor.create(
    comfyui_server,
    batch_size=8,
) as executor:
    async for item in executor.submit_workflow_async(
        workflow_template=workflow_template,
        num_samples=16
    ):
        print(item)

RunPod

Coming soon.

Modal

Coming soon.

A few notes on the example above:

  • The executor can be configured to use a certain batch size. The value can also be overwritten by providing a batch_size to the submit_workflow method.
  • A value for num_samples can be provided to generate approximately num_samples / batch_size batches within a single RunPod job. While multiple jobs could be submitted to achieve the same results, generating multiple batches within a single job will generally make better use of node results caching and thus improve efficiency and latency.
  • The result is a list of WorkflowOutputImage objects. These provide the output image, the filename as set by ComfyUI and optionally the subfolder to which the image has been saved originally.

Metadata

Release files for comfy-executors 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for comfy-executors 0.1.0
File Size Uploaded
comfy_executors-0.1.0.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for comfy-executors 0.1.0
File Interpreter ABI Platform
comfy_executors-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 kB

Release files / comfy_executors-0.1.0.tar.gz

Download URL comfy_executors-0.1.0.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e5d1dc37ce56d701abc8f2fb93cf16c64366fed18cf00b1fbea361562d598529
BLAKE2b-256 checksum
How to use checksums
cce17d813888b5d4f896720ba78d9768ead20f44f01d727ec7956b2aefc4a3d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.11.9 Darwin/24.0.0

Release files / comfy_executors-0.1.0-py3-none-any.whl

Download URL comfy_executors-0.1.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c968a3035c294fb47064b57670af412ff747185f97722b923f7b8e1db99fbf5e
BLAKE2b-256 checksum
How to use checksums
c0a2aa1d6b1fc9b04d767cbd0ba9ed1f44bb340343a82608d80a4536cab0cc99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.11.9 Darwin/24.0.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page