Skip to main content

Add your description here

Project description

Comfy Nodekit

Utilities for working with ComfyUI node graphs from Python. The project provides typed wrappers around ComfyUI nodes, lightweight graph primitives, and helpers for exporting a workflow back to the JSON format that the ComfyUI API expects.

  • Typed Node and Edge models (Pydantic) for tracking dependencies and serialising graphs.
  • A generated nodes.py module that mirrors the ComfyUI node catalogue with Python callables.
  • Tooling (nodes_to_py.py) to regenerate those bindings directly from a running ComfyUI server.
  • Example workflow builder scaffolding that shows how to stitch nodes into higher-level pipelines.

Requirements

  • Python 3.12+
  • requests and pydantic (installed automatically when the package is installed)
  • Access to a running ComfyUI server when regenerating node bindings

Installation

uv add comfy_nodekit
# pip install comfy_nodekit

Generate node bindings (required before usage)

Before using the factory functions, generate nodes.py from your running ComfyUI:

uv run python -m comfy_nodekit.nodes_to_py http://127.0.0.1:8188/
# or: just run

If you omit the URL, it defaults to http://127.0.0.1:8188/. This writes nodes.py based on the server's /object_info. Re-run whenever your ComfyUI nodes change.

You can also generate from a local JSON schema (previously fetched from /object_info):

# From default server (same as before)
uv run python -m comfy_nodekit.nodes_to_py

# From a specific server and write to a custom path
uv run python -m comfy_nodekit.nodes_to_py http://127.0.0.1:8188/ ./nodes.py

# From a local JSON file and write to a custom path
uv run python -m comfy_nodekit.nodes_to_py ./object_info.json ./nodes.py

Usage

Create nodes the same way you would wire a ComfyUI graph. Each factory function from nodes.py returns a typed Edge that keeps track of its originating node. When you are ready to export the workflow, grab the source_node of your terminal edge and call build_json_workflow().

from comfy_nodekit.models import Edge
from comfy_nodekit.nodes import (
    CheckpointLoaderSimple,
    CLIPTextEncode,
    EmptyLatentImage,
    KSampler,
    VAEDecode,
)

# Load base models
model, clip, vae = CheckpointLoaderSimple("juggernautXL_v9Rdphoto2Lightning.safetensors")

# Encode prompts
positive = CLIPTextEncode(text="a cinematic portrait of an astronaut", clip=clip)
negative = CLIPTextEncode(text="", clip=clip)

# Create latents and sample
latent = EmptyLatentImage(width=1024, height=1024, batch_size=1)
sampled = KSampler(
    model=model,
    seed=42,
    steps=20,
    cfg=7.5,
    sampler_name="euler",
    scheduler="normal",
    positive=positive,
    negative=negative,
    latent_image=latent,
    denoise=1.0,
)
decoded = VAEDecode(samples=sampled, vae=vae)

# Export to ComfyUI JSON format
workflow = decoded.source_node.build_json_workflow()

# Optionally: print or send to a ComfyUI server
import json
print(json.dumps(workflow, indent=2))

Notes

  • The generator downloads the node schema, sanitises type names, and rewrites nodes.py with updated classes and helper functions.
  • The just recipe just run wraps the generation command if you prefer using just.

Acknowledgments

Thanks to ComfyScript for inspiration and prior art.

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_nodekit-0.2.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

comfy_nodekit-0.2.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file comfy_nodekit-0.2.1.tar.gz.

File metadata

  • Download URL: comfy_nodekit-0.2.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for comfy_nodekit-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6ec76e7a63b303e6945d1fddeb76695ae579a291d4f5124d1a645e8e4e5d1e0d
MD5 090887c724cddcc09cb4efd09a632e2c
BLAKE2b-256 6a825bf0dd717611fa52d8365cfe0fc9347798d07402335234e5a39002452d32

See more details on using hashes here.

File details

Details for the file comfy_nodekit-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for comfy_nodekit-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 12e05cdf6b44fee3896f723e3fde1274dad667448f76c85a6e2c5e3f551b5b13
MD5 1de2ab0ecaa75db5fac0fca6656454b3
BLAKE2b-256 5808e149508f7d7a65e78014cdd2604064b5cfc8e0087d935a023afa5f70d52e

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