A fluent, type-safe Python API for building and executing ComfyUI workflows.
Project description
ComfyFlow
ComfyFlow is a Python package for building and executing ComfyUI node graphs programmatically. It provides a fluent, type-safe API that is dynamically generated from your actual ComfyUI instance's schema.
Features
- Fluent API: Build ComfyUI workflows using a natural, method-call syntax. No more manual JSON construction.
- Live Previews: The
run()method is an async generator that yields images as they are ready, including intermediatePreviewImagesnapshots. - Model Discovery: Easily access lists of available
checkpoints,loras,vaes, anddiffusion_modelsdirectly from the client. - Smart Validation:
- Strict Keyword Check: Ensures all keyword arguments match the node schema.
- Default Value Support: Automatically fills in missing arguments with schema defaults.
- Range Validation: Validates
min/maxconstraints for numeric inputs. - Enum Validation: Ensures list-based options (like samplers or schedulers) are valid.
- Dynamic Schema: Queries your local ComfyUI instance to automatically support all installed custom nodes and extensions.
- Export Options:
- Export to API JSON format for direct ComfyUI execution.
- Export to UI JSON format with basic auto-layout for manual editing in the ComfyUI web interface.
Installation
From Git (Latest)
To install the latest development version directly from GitHub using uv:
uv add git+https://github.com/TianyuCheng/ComfyFlow.git
Usage Example
from comfyflow import ComfyClient, Workflow
async def main():
# 1. Initialize the client (connects to ComfyUI)
cli = ComfyClient("127.0.0.1:8188")
await cli.init()
# 2. Access available models
print(f"Checkpoints: {cli.checkpoints}")
# 3. Create a workflow
wf = Workflow(cli)
# Nodes are dynamically available based on your ComfyUI instance
ckpt = wf.CheckpointLoaderSimple(
ckpt_name=cli.checkpoints[0]
)
pos = wf.CLIPTextEncode(
text="a high-tech laboratory with glowing blue lights",
clip=ckpt.CLIP
)
neg = wf.CLIPTextEncode(
text="blurry, low quality",
clip=ckpt.CLIP
)
latent = wf.EmptyLatentImage(
width=512,
height=512,
batch_size=1
)
sample = wf.KSampler(
model=ckpt.MODEL,
positive=pos.CONDITIONING,
negative=neg.CONDITIONING,
latent_image=latent.LATENT,
steps=20,
cfg=7.5,
sampler_name="euler",
scheduler="normal",
denoise=1.0
)
image = wf.VAEDecode(
samples=sample.LATENT,
vae=ckpt.VAE
)
# Optional: Add a preview node to get live updates during sampling
wf.PreviewImage(images=image.IMAGE)
# 4. Run the workflow and receive images as they are ready
async for node_id, image in wf.run():
# 'node_id' is the string ID of the node that produced the image
# 'image' is a PIL.Image object
print(f"Received image from node {node_id}")
image.show()
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Advanced Usage
Accessing Node Outputs
Each node call returns a NodeOutputs object. You can access specific output slots by name (uppercase, e.g., ckpt.MODEL) or by index (e.g., ckpt[0]).
Exporting Workflows
# Export to API format (for /prompt endpoint)
api_json = wf.to_api_json()
# Export to UI format (for loading into ComfyUI browser)
ui_json = wf.to_ui_json()
How it works
ComfyFlow queries http://127.0.0.1:8188/object_info to understand the schema of all available nodes. It then uses this information to provide a dynamic API where each node is a method on the Workflow class.
The run() method establishes a WebSocket connection to ComfyUI, allowing it to stream live progress and binary image data directly to your Python application.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file comfyflow-0.1.0.tar.gz.
File metadata
- Download URL: comfyflow-0.1.0.tar.gz
- Upload date:
- Size: 64.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfdc057e0290f83dc8e680d33c374911f836f7ca51730cdbf3c09e4494c08907
|
|
| MD5 |
f64744b86c77cb9c530867600dd929be
|
|
| BLAKE2b-256 |
0863830c0058b898536ef329709b66c71d9a9338922b90682a7eda5eb483093f
|
File details
Details for the file comfyflow-0.1.0-py3-none-any.whl.
File metadata
- Download URL: comfyflow-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b69d0f352d5503bc942a6c5d9e13aeadeb334604f0997a1f2c017050f4596cc
|
|
| MD5 |
cfe4b36094d5de7e33153d976ba44e28
|
|
| BLAKE2b-256 |
20b0bc604d32758ac6671bcf054392e8d84d69ffba0b628e32c5417df64fe01d
|