ComfyUI Workflow Templates Core
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
- breaking Incomplete ComfyUI updates can lead to missing or broken workflow templates. This library is a core dependency of ComfyUI's template system and must be updated alongside ComfyUI's main code and other related packages (like `comfyui-frontend-package` and `comfyui-embedded-docs`) to ensure compatibility and access to the latest templates. [7]
- gotcha When creating or modifying workflow templates, ensure the JSON structure conforms to the `WorkflowTemplateManifest` schema. Crucially, any models required by the workflow must be correctly embedded with `name`, `url` (direct download link), and `directory` (relative to `ComfyUI/models`) fields. Incorrectly formatted model information can prevent templates from being fully functional or models from being auto-downloaded. [4]
- gotcha For developers creating custom nodes that include example workflow templates, these templates must be placed in a specific folder structure (e.g., `example_workflows`, `workflow`, `workflows`, `example`, or `examples`) within the custom node's directory for ComfyUI's template browser to discover and display them. [5]
Install
-
pip install comfyui-workflow-templates-core
Imports
- WorkflowTemplateManifest
from workflow_templates_core.manifest import WorkflowTemplateManifest
- WorkflowTemplateLoader
from workflow_templates_core.loader import WorkflowTemplateLoader
Quickstart
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.")