ComfyUI Workflow Templates Core

0.3.194 · active · verified Fri Apr 10

ComfyUI Workflow Templates Core provides fundamental utilities and helper functions for managing and loading ComfyUI workflow templates. It's a core component of the broader ComfyUI workflow template system, facilitating programmatic interaction with template manifests and their associated files. The library is actively developed as part of the Comfy-Org/workflow_templates repository, with releases tied to ComfyUI updates. The current PyPI version is 0.3.194. [1, 7, 9]

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically interact with `workflow_templates_core` by creating a mock workflow template manifest and then using the library's `WorkflowTemplateManifest` model to parse and validate it. It simulates the core functionality of loading template metadata, which is essential for ComfyUI's template browsing system. [1]

import json
from pathlib import Path
from workflow_templates_core.loader import WorkflowTemplateLoader

# Create a dummy workflow template manifest JSON file
dummy_manifest_content = {
    "id": "my_first_template",
    "name": "My First ComfyUI Template",
    "description": "A simple example template.",
    "version": "1.0.0",
    "tags": ["example", "basic"],
    "dependencies": [],
    "workflow": "path/to/my_first_template.json"
}

dummy_dir = Path('./my_templates')
dummy_dir.mkdir(exist_ok=True)

manifest_path = dummy_dir / 'my_first_template.manifest.json'
workflow_path = dummy_dir / 'my_first_template.json'

with open(manifest_path, 'w') as f:
    json.dump(dummy_manifest_content, f, indent=2)

with open(workflow_path, 'w') as f:
    # A minimal dummy ComfyUI workflow JSON
    json.dump({"nodes": [], "links": []}, f, indent=2)

print(f"Created dummy manifest: {manifest_path}")
print(f"Created dummy workflow: {workflow_path}")

# Initialize the loader with the base path where templates are stored
# The loader expects manifests in a 'manifests' sub-directory or directly in the templates_path
# For this example, we'll point it to the directory containing our manifest.
loader = WorkflowTemplateLoader(templates_path=dummy_dir)

# Load the manifest (usually done by scanning the templates_path)
# In a real scenario, you'd iterate through discovered manifests.
# For this quickstart, we'll simulate loading a specific manifest file directly.
# Note: The loader's `load` method typically expects the manifest file itself, not its containing directory.
# A more typical usage would involve the loader *finding* manifests.
# As a direct example, we can parse the content into a Manifest object:

print("\nAttempting to parse manifest content...")
try:
    with open(manifest_path, 'r') as f:
        raw_manifest = json.load(f)
    manifest = WorkflowTemplateManifest(**raw_manifest)
    print(f"Successfully parsed manifest: {manifest.name} (ID: {manifest.id})")
    print(f"Workflow file referenced: {manifest.workflow}")
except Exception as e:
    print(f"Error parsing manifest: {e}")

# Clean up dummy files
manifest_path.unlink()
workflow_path.unlink()
dummy_dir.rmdir()
print("\nCleaned up dummy files.")

view raw JSON →