Skip to main content

Minimal ComfyUI runtime for deploying custom nodes as microservices

Project description

comfy-runtime

Minimal ComfyUI Runtime for Custom Nodes

comfy-runtime is a minimal Python runtime for loading and executing ComfyUI nodes outside the full ComfyUI app. It is designed for packaging custom nodes into scripts, workers, and microservices. It is not a server, not a UI, and not a workflow engine.

Installation

pip install comfy-runtime
# Optional: built-in extra nodes
pip install comfy-builtin-nodes

Quick Start

import comfy_runtime

# Configure model paths (optional — has defaults)
comfy_runtime.configure(
    models_dir="/path/to/models",
    output_dir="/path/to/output",
)

# Execute a built-in node
result = comfy_runtime.execute_node(
    "EmptyLatentImage",
    width=512, height=512, batch_size=1,
)
latent = result[0]
print(f"Latent shape: {latent['samples'].shape}")

# Load extra nodes from a file
comfy_runtime.load_nodes_from_path("/path/to/my_custom_node.py")

# List all registered nodes
print(comfy_runtime.list_nodes())

# Get node info
info = comfy_runtime.get_node_info("EmptyLatentImage")
print(info["input_types"])

API Reference

configure(models_dir, output_dir, input_dir, temp_dir, vram_mode, device)

Configures runtime directories and device flags. This must be called before importing comfy.model_management.

execute_node(class_type, **kwargs) -> tuple

Runs one registered node and returns its output tuple. Handles both V1 and V3 node styles transparently.

create_node_instance(class_type) -> object

Creates a reusable instance of a registered node class. Useful for stateful nodes.

register_node(class_type, node_cls, display_name)

Registers a node class manually under a given class type.

load_nodes_from_path(path) -> list[str]

Loads nodes from a .py file or a directory of Python files. Supports both V1 mapping based nodes and V3 entrypoint based nodes.

list_nodes() -> list[str]

Returns all registered node class names.

get_node_info(class_type) -> dict

Returns public metadata for a node, including input types, return types, category, and execution method.

unregister_node(class_type)

Removes a registered node from the runtime registry.

get_config() -> dict

Returns the current runtime configuration.

Exceptions

  • NodeNotFoundError
  • NodeExecutionError

Microservice Example

# Example: wrapping a node with FastAPI
from fastapi import FastAPI
import comfy_runtime

app = FastAPI()
comfy_runtime.configure(models_dir="/data/models", output_dir="/data/output")

@app.post("/generate")
def generate(width: int = 512, height: int = 512):
    result = comfy_runtime.execute_node(
        "EmptyLatentImage", width=width, height=height, batch_size=1,
    )
    return {"shape": list(result[0]["samples"].shape)}

Memory Management

from comfy.model_management import soft_empty_cache, cleanup_models
soft_empty_cache()  # Free unused VRAM

Limitations

  • Single-node execution only, no workflow graph
  • Single-process only, no interrupt signaling across processes
  • No built-in HTTP server, wrap it with FastAPI or gRPC yourself
  • configure() must be called before importing model_management

License

GPL-3.0, same as ComfyUI

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_runtime-0.1.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

comfy_runtime-0.1.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: comfy_runtime-0.1.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for comfy_runtime-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d3f089194204c0f38642f0001a1d6a74bcb8f6e10d07351d7270a1047d5e5db9
MD5 f755fca36dffc98f1cf692fd6eb8bae3
BLAKE2b-256 cf51422a0128820958beb98431a2453d14f925e49b3f9a0b196b79c237a9650f

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_runtime-0.1.0.tar.gz:

Publisher: publish.yml on anyin233/comfy-runtime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: comfy_runtime-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for comfy_runtime-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7edfe756f93c85a3f11a39c7a9ab7200bfdbed6e5d1c70ce4cee1f4db897c8f3
MD5 dddd27987bd8f4284f53ac6d5ce2d4f2
BLAKE2b-256 a3b55309f06ad33dfeb1a8b02b573aeb06b28af06b07e2e4fb3e83f8aaef6adb

See more details on using hashes here.

Provenance

The following attestation bundles were made for comfy_runtime-0.1.0-py3-none-any.whl:

Publisher: publish.yml on anyin233/comfy-runtime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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