Skip to main content

A Python client library for interacting with ComfyUI servers and managing image generation workflows.

Project description

comfy-proxy

A Python client library for interacting with ComfyUI servers and managing image generation workflows.

Features

  • Single and multi-instance ComfyUI server management
  • Async workflow execution
  • Flexible address configuration (single, multiple, port ranges)
  • Built-in workflow templates
  • Customizable image sizes and parameters
  • Websocket-based image generation and retrieval

Installation

ComfyProxy requires Python 3.11 or later. Install using pip:

pip install comfy-proxy

Quick Start

import asyncio
from comfy_proxy.comfy import SingleComfy
from comfy_proxy.workflows.flux import FluxModel, FluxWorkflowParams, FluxWorkflow
from comfy_proxy.workflow import Sizes

async def generate_image():
    # Initialize a ComfyUI instance
    comfy = Comfy("127.0.0.1:7821")
    
    # Configure model and parameters
    model = FluxModel()
    params = FluxWorkflowParams(
        prompt="a beautiful sunset over mountains",
        model=model,
        size=Sizes.LANDSCAPE_16_9,
        seed=42,
        batch_size=1
    )
    
    # Create and execute workflow
    workflow = FluxWorkflow(params)
    async for image_data in comfy.generate(workflow):
        with open("generated_image.png", "wb") as f:
            f.write(image_data)
        break  # Save first image only

# Run the example
asyncio.run(generate_image())

Multiple ComfyUI Instances

ComfyProxy can distribute work across multiple ComfyUI servers:

from comfy_proxy.comfy import Comfy

# Initialize with multiple instances
comfy = Comfy("127.0.0.1:8188-8192")  # Port range
# or
comfy = Comfy(["127.0.0.1:8188", "127.0.0.1:8189"])  # List
# or
comfy = Comfy("127.0.0.1:8188,127.0.0.1:8189")  # Comma-separated

Development

Requirements:

  • Python 3.11+
  • Poetry for dependency management

Setup:

# Clone repository
git clone https://github.com/yourusername/comfy-proxy.git
cd comfy-proxy

# Install dependencies
poetry install

# Run tests
poetry run pytest

Custom Workflows

ComfyProxy comes with some built-in workflows (like FluxWorkflow), but you can easily create your own:

from comfy_proxy.workflow import ComfyWorkflow, ComfyNode

class MyCustomWorkflow(ComfyWorkflow):
    def __init__(self, params):
        super().__init__()
        self.params = params
        self._build_workflow()
        
    def _build_workflow(self):
        # Add nodes to create your workflow
        checkpoint_node = self.add_node(
            "CheckpointLoaderSimple",
            {"ckpt_name": "sd_xl_base_1.0.safetensors"}
        )
        # ... add more nodes and connect them

We welcome contributions of basic workflows for popular models:

  • Stable Diffusion 1.5
  • SDXL
  • SD Turbo
  • SD 3.0
  • etc.

For more complex use cases, you can implement the ComfyWorkflow class directly in your own codebase to create custom workflows with additional functionality.

License

MIT License - see LICENSE file for details.

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

comfy_proxy-0.1.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

comfy_proxy-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: comfy_proxy-0.1.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.10 Linux/6.8.0-48-generic

File hashes

Hashes for comfy_proxy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8b3c0f4bccfc66255be1b4032caf1f7ab9a8bdb14f91a58abc590d918fcab5d0
MD5 0ea0f428ab0f5a0954e97cf4470dd255
BLAKE2b-256 3979fc0063bd84b3968e90745ccee89e3b30978b0d3e45735e1044d8d71640db

See more details on using hashes here.

File details

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

File metadata

  • Download URL: comfy_proxy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.10 Linux/6.8.0-48-generic

File hashes

Hashes for comfy_proxy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b254fde0eced4b99ff713bf71be97658a4c529dc6714656ab42df71f43afed60
MD5 5485783f45f74cad9c05877b1af4b2f7
BLAKE2b-256 4715ba6f6bce14f6c1b24ce3be5f3481000fdb036e27c0c8bc655d76027e8ea5

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