Skip to main content

A Python package for generating ComfyUI workflow APIs from object_info.json using AST code generator

Project description

ComfyUI Workflow Generator

A Python package for generating ComfyUI workflow APIs from object_info.json using AST code generator. Like ComfyScript, but much more simple.

Installation

pip install comfyui-workflow-generator

Usage

1. Generate Workflow API

From Command Line

# Generate from local object_info.json (auto-detected)
comfyui-generate object_info.json -o my_workflow_api.py

# Generate from ComfyUI server (auto-detected)
comfyui-generate http://127.0.0.1:8188 -o workflow_api.py

# Generate with default output name
comfyui-generate object_info.json

From Python

# Import the generated API
from workflow_api import Workflow
from comfyui_workflow_generator import ComfyUIWorkflowExecutor

# Step 1: Upload image with custom name
executor = ComfyUIWorkflowExecutor("http://127.0.0.1:8188")
uploaded_filename = executor.upload_image(
    "my_very_own_image.png", 
    image_name="my_very_own_image.png"
)

# Step 2: Create workflow
wf = Workflow()

# Load checkpoint
model, clip, _ = wf.CheckpointLoaderSimple(ckpt_name="Illustrious-XL-v1.0.safetensors")

# Load vae, i usually do it via separate node
vae = wf.VAELoader(vae_name="sdxl_vae.safetensors")

# Load uploaded image (use the uploaded filename)
image, mask = wf.LoadImage(image="my_very_own_image.png")

# Encode prompts
positive = wf.CLIPTextEncode(text="1girl, lisa_\(genshin_impact\)", clip=clip)
negative = wf.CLIPTextEncode(text="blurry, low quality", clip=clip)

# Encode image for img2img
latent = wf.VAEEncode(pixels=image, vae=vae)

# Sample
denoized_latent = wf.KSampler(
    model=model,
    seed=42,
    steps=20,
    cfg=8.0,
    sampler_name="euler",
    scheduler="normal",
    positive=positive,
    negative=negative,
    latent_image=latent,
    denoise=0.8
)

# Decode
result_image = wf.VAEDecode(samples=denoized_latent, vae=vae)

# Save
wf.SaveImage(images=result_image, filename_prefix="lisa_from_genshin")

# Step 3: Get workflow JSON (for debugging or manual inspection)
workflow_json = wf.get_workflow()
print("Generated workflow:", workflow_json)

# save it to file, it could be loaded in comfyui
with open("workflow_json.json", "w") as f:
    f.write(workflow_json)

# Step 4: Execute it (do not feed it with json, it expects dict)
results = executor.execute_workflow(wf.workflow_dict, output_dir="./results")

Generated workflow look like this:

Example workflow in ComfyUI

Key Design Principles

1. No Input Manipulation

The workflow executor executes workflows exactly as provided, without any modifications.

1. No Weird Features

No nested event loops, no Real Mode, Unreal Mode, or other terms from the jargon of x86 assembler programmers of the 90s. It's just a workflow generator, thicc as brick.

3. Type Safety

Generated APIs include proper return type hints:

def CheckpointLoaderSimple(self, ckpt_name: str) ->(MODEL, CLIP, VAE):
    ...

def LoadImage(self, image: str) ->(IMAGE, MASK):
    ...

def KSampler(self, model: MODEL, seed: int, steps: int, cfg: float,
        sampler_name: str, scheduler: str, positive: CONDITIONING, negative:
        CONDITIONING, latent_image: LATENT, denoise: float) ->LATENT:
    ...

Package Structure

comfyui_workflow_generator/
├── __init__.py          # Package exports
├── generator.py         # AST-based code generator
├── executor.py          # Workflow execution (no input manipulation)
└── cli.py              # Command-line interface

Development

# Install in development mode
pip install -e .

# Run tests
pytest

# Format code
black comfyui_workflow_generator/

# Lint code
flake8 comfyui_workflow_generator/

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

comfyui_workflow_generator-0.1.0.tar.gz (59.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

comfyui_workflow_generator-0.1.0-py3-none-any.whl (60.8 kB view details)

Uploaded Python 3

File details

Details for the file comfyui_workflow_generator-0.1.0.tar.gz.

File metadata

File hashes

Hashes for comfyui_workflow_generator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3a3c407712332bfa2044ccc1a10ac7fd5ab2c0eaa64afa204100bc32992d5ad9
MD5 710911c72dab21568a1f37b9a589a89e
BLAKE2b-256 6030b1caf55929b202a43d12432ea362381f3afbc026ad49881d196a44934491

See more details on using hashes here.

File details

Details for the file comfyui_workflow_generator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for comfyui_workflow_generator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8668a95eb81977711ee8e9a404f3dd683ddcdb99a74361cb292a78fea0b0c872
MD5 4b3b3597ad6f37bd9c4fad9a9bba0125
BLAKE2b-256 fe3b8c862f70f34d6ab1b048f0e3ebc965c3ddac4804bae95cedfed3ee726399

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page