fabricatio_comfyui.models.workflow
Typed models for ComfyUI workflow graphs.
Provides Node (a single workflow node) and Workflow
(a full workflow graph) with proper typing, validation, and clean
API-format serialization.
Classes
A typed reference to another node's output. |
|
A single node in a ComfyUI workflow graph. |
|
Programmatic builder for ComfyUI workflow graphs. |
Module Contents
- class fabricatio_comfyui.models.workflow.NodeRef(/, **data: Any)
Bases:
pydantic.BaseModelA typed reference to another node’s output.
In the ComfyUI API format, connections are stored as
[node_id, output_index]. This model makes that explicit.- model_config
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class fabricatio_comfyui.models.workflow.Node(/, **data: Any)
Bases:
pydantic.BaseModelA single node in a ComfyUI workflow graph.
Inputs are stored in their API-format representation. Literal values keep their native types. Node connections are stored as
[node_id, output_index]lists — useconnect()/get_ref()for typed access.- model_config
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- inputs: Dict[str, Any] = None
Input values. Literals are native types; node refs are
[node_id, output_index].
- class fabricatio_comfyui.models.workflow.Workflow
Programmatic builder for ComfyUI workflow graphs.
Load from exported API-format JSON or build from scratch:
wf = Workflow.from_file("demo.json") wf.set_positive_prompt("masterpiece, best quality") wf.set_checkpoint("v1-5-pruned-emaonly.safetensors") # Serialize for client.queue_prompt() data = wf.to_api() # Build from scratch wf = Workflow.new() ckpt = wf.add("CheckpointLoaderSimple", inputs={"ckpt_name": "model.safetensors"}) empty = wf.add("EmptyLatentImage", inputs={"width": 512, "height": 512, "batch_size": 1}) pos = wf.add("CLIPTextEncode", inputs={"text": "a cat"}) pos.connect("clip", ckpt, 1)
- classmethod new() Self
Create an empty workflow.
- classmethod from_file(path: str | pathlib.Path) Self
Load from a
.jsonfile.
- classmethod default() Self
Load the bundled demo workflow shipped with the package.
- add(type: str, *, title: str = '', inputs: Dict[str, Any] | None = None) Node
Add a new node, auto-assigning the next available ID.
- set_checkpoint(ckpt_name: str, *, node_id: str | None = None) Node
Set the checkpoint on a
CheckpointLoaderSimplenode.
- set_positive_prompt(text: str, *, node_id: str | None = None) Node
Set the positive prompt text on a
CLIPTextEncodenode.
- set_negative_prompt(text: str, *, node_id: str | None = None) Node
Set the negative prompt text on a
CLIPTextEncodenode (second one).
- set_sampler(*, seed: int | None = None, steps: int | None = None, cfg: float | None = None, sampler_name: str | None = None, scheduler: str | None = None, denoise: float | None = None, node_id: str | None = None) Node
Update sampler parameters on a
KSamplerorKSamplerAdvancednode.