Skip to main content

fabricatio-comfyui

MIT License Python Versions PyPI Version PyPI Downloads

Async ComfyUI API client for Fabricatio — submit workflow graphs, poll for completion, and download generated images. Built on httpx with full Pydantic-typed API coverage.

Architecture

The package is split into small, single-responsibility modules composed through nominal inheritance — no plugin dicts, no hasattr, no duck typing:

Layer Module / Class Purpose
Graph core WorkflowCore (models/workflow_core.py) Graph container: CRUD, construction, serialization
Graph ops LoaderOps / PromptOps / SamplerOps / ResolutionOps (models/workflow_ops.py) Typed node-family setters, composed into Workflow
Workflow Workflow (models/workflow.py) Thin composition: WorkflowCore + all *Ops ABCs
Client ABC ComfyuiClientBase (client_base.py) Nominal HTTP client interface
Client ComfyuiHTTPClient (http_client.py) Concrete httpx-backed implementation, async with
Capability Comfyui (capabilities/comfyui.py) Mixin: orchestration (queue → poll → download) + DI
Action ComfyuiGenerateImage, ComfyuiUploadImage Pluggable steps for Fabricatio WorkFlow

Pre-built workflow templates (Txt2Img, Txt2ImgWithDownload) are also available as a quick starting point.

Installation

pip install fabricatio[comfyui]
# or
uv pip install fabricatio[comfyui]

Configuration

Configure the ComfyUI server URL via environment, .env, fabricatio.toml, or pyproject.toml:

FABRICATIO_COMFYUI__BASE_URL=http://127.0.0.1:8188
FABRICATIO_COMFYUI__TIMEOUT=300

Or in fabricatio.toml:

[comfyui]
base_url = "http://127.0.0.1:8188"
timeout = 300

The config dataclass supports two fields:

Field Default Description
base_url http://127.0.0.1:8188 ComfyUI server base URL
timeout 300.0 Request timeout in seconds

Access config at runtime: from fabricatio_comfyui import comfyui_config

Usage

Standalone client

Use ComfyuiHTTPClient directly as an async context manager — no Fabricatio dependency beyond config:

import asyncio
from fabricatio_comfyui import ComfyuiHTTPClient


async def main() -> None:
    async with ComfyuiHTTPClient.create() as client:
        resp = await client.queue_prompt(workflow)
        result = await client.wait_for_completion(resp.prompt_id)
        if result.succeeded:
            await client.download_images(result, "./outputs")
        for img in result.all_images:
            image_bytes = await client.get_image(img.filename)


asyncio.run(main())

Capability mixin (with a Role)

Mix Comfyui into a Role to get acomfyui_* predicate-verb methods (following the same a-prefix convention as UseLLM.aask):

import asyncio
from fabricatio import Role
from fabricatio_comfyui import Comfyui


class ImageRole(Role, Comfyui):
    """Role with ComfyUI image generation capability."""


async def main() -> None:
    role = ImageRole(name="ComfyUI Worker")
    result = await role.acomfyui_generate(workflow, download_dir="./outputs")
    for img in result.all_images:
        print(img.filename)


asyncio.run(main())

Action (in a WorkFlow)

Use ComfyuiGenerateImage and ComfyuiUploadImage as composable steps:

from fabricatio import WorkFlow
from fabricatio_comfyui import ComfyuiGenerateImage, ComfyuiUploadImage

GenerateImage = WorkFlow(
    name="ComfyUI Generate",
    steps=(ComfyuiGenerateImage(workflow=WORKFLOW, download_dir="./outputs"),),
)

UploadThenGenerate = WorkFlow(
    name="Img2Img Pipeline",
    steps=(
        ComfyuiUploadImage(image_path="./input.png"),
        ComfyuiGenerateImage(workflow=IMG2IMG_WORKFLOW),
    ),
)

Upload an image (img2img)

result = await role.acomfyui_upload("./input_photo.png")
print(result.name)  # filename on the server

Built-in workflow templates

Two minimal templates are provided as quick starting points. In practice, you should export your own workflows via "Save (API Format)" from the ComfyUI interface.

from fabricatio_comfyui.workflows import Txt2Img, Txt2ImgWithDownload

API Reference

ComfyuiHTTPClient / Comfyui capability

The HTTP client owns single REST endpoints only. The capability mixin owns orchestration (queue → poll → download). All capability methods are prefixed with acomfyui_, following the a-prefix predicate-verb convention used by UseLLM.

Client method Capability method Returns Description
queue_prompt(workflow) acomfyui_queue(…) PromptResponse Submit a workflow graph for execution
get_queue_info() acomfyui_inspect_queue() QueueInfo Fetch current queue status (running + pending)
get_history(prompt_id) acomfyui_history(prompt_id) HistoryEntry | None Retrieve execution history for a prompt
wait_for_completion(prompt_id) acomfyui_retrieve(prompt_id) ComfyuiExecutionResult Poll until execution finishes or fails
get_image(filename, …) acomfyui_retrieve_image(filename, …) bytes Download a single generated image
upload_image(image_path, …) acomfyui_upload(image_path, …) UploadResponse Upload an image for img2img workflows
interrupt() acomfyui_interrupt() None Interrupt the currently running workflow
download_images(result, dir) — (used internally by acomfyui_generate) None Download all output images concurrently
acomfyui_generate(…) ComfyuiExecutionResult Queue + wait + optionally download images

Actions

Class Fields Description
ComfyuiGenerateImage workflow, download_dir, timeout Queue a workflow and wait for images
ComfyuiUploadImage image_path, image_type Upload an image to the server

Models

All API responses are deserialized into frozen Pydantic models. Key types:

Model Description
PromptResponse Response from POST /prompt — contains prompt_id
ComfyuiExecutionResult Final result — outputs, all_images, succeeded
ComfyuiOutputImage Single image metadata — filename, subfolder, type
HistoryEntry Execution history — status, per-node outputs
QueueInfo Queue state — queue_running, queue_pending
UploadResponse Upload result — name, subfolder, type

Workflow types (PEP 695)

Type alias Definition Description
NodeInputs dict[str, Any] Per-node input map (literals + node refs)
NodeApi dict[str, Any] Per-node API dict (class_type, inputs, …)
WorkflowDict dict[str, NodeApi] Full ComfyUI API-format workflow graph

License

MIT — see the LICENSE file.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

fabricatio_comfyui-0.3.6-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

File details

Details for the file fabricatio_comfyui-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: fabricatio_comfyui-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 36.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fabricatio_comfyui-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f9a5ab6279a218af29d67512f078f9fb88cbf78e77dad7fe4794a473416c45db
MD5 8d8d1c9eb4d0aa46fb154deedbd06bf6
BLAKE2b-256 34c402037f1009ff02185cc600b02bb959ae1ad7e258b27ab4ec777ddc1bbbb4

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.1

1 file

0.4.0

1 file

This release

0.3.6 This release

1 file

0.3.5

1 file

0.3.3

1 file

0.3.2

1 file

0.3.1

1 file

0.3.0

1 file

0.2.0

1 file

0.1.0

1 file

Supported by

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