|
| 1 | +# API Reference |
| 2 | + |
| 3 | +Complete API reference for ComfyKit. |
| 4 | + |
| 5 | +## ComfyKit Class |
| 6 | + |
| 7 | +### Constructor |
| 8 | + |
| 9 | +```python |
| 10 | +class ComfyKit: |
| 11 | + def __init__( |
| 12 | + self, |
| 13 | + # Local ComfyUI configuration |
| 14 | + comfyui_url: Optional[str] = None, |
| 15 | + executor_type: Literal["http", "websocket"] = "http", |
| 16 | + api_key: Optional[str] = None, |
| 17 | + cookies: Optional[str] = None, |
| 18 | + |
| 19 | + # RunningHub cloud configuration |
| 20 | + runninghub_url: Optional[str] = None, |
| 21 | + runninghub_api_key: Optional[str] = None, |
| 22 | + runninghub_timeout: int = 300, |
| 23 | + runninghub_retry_count: int = 3, |
| 24 | + ) |
| 25 | +``` |
| 26 | + |
| 27 | +### execute Method |
| 28 | + |
| 29 | +```python |
| 30 | +async def execute( |
| 31 | + self, |
| 32 | + workflow: Union[str, Path], |
| 33 | + params: Optional[Dict[str, Any]] = None, |
| 34 | +) -> ExecuteResult |
| 35 | +``` |
| 36 | + |
| 37 | +**Parameters:** |
| 38 | +- `workflow`: Workflow source (file path, URL, or RunningHub ID) |
| 39 | +- `params`: Workflow parameters |
| 40 | + |
| 41 | +**Returns:** |
| 42 | +- `ExecuteResult`: Structured execution result |
| 43 | + |
| 44 | +### execute_json Method |
| 45 | + |
| 46 | +```python |
| 47 | +async def execute_json( |
| 48 | + self, |
| 49 | + workflow_json: Dict[str, Any], |
| 50 | + params: Optional[Dict[str, Any]] = None, |
| 51 | +) -> ExecuteResult |
| 52 | +``` |
| 53 | + |
| 54 | +**Parameters:** |
| 55 | +- `workflow_json`: Workflow JSON dictionary |
| 56 | +- `params`: Workflow parameters |
| 57 | + |
| 58 | +**Returns:** |
| 59 | +- `ExecuteResult`: Structured execution result |
| 60 | + |
| 61 | +## ExecuteResult Class |
| 62 | + |
| 63 | +```python |
| 64 | +class ExecuteResult: |
| 65 | + status: str # "completed" or "failed" |
| 66 | + prompt_id: Optional[str] # Prompt ID |
| 67 | + duration: Optional[float] # Duration in seconds |
| 68 | + |
| 69 | + # Media outputs |
| 70 | + images: List[str] # All image URLs |
| 71 | + videos: List[str] # All video URLs |
| 72 | + audios: List[str] # All audio URLs |
| 73 | + texts: List[str] # All text outputs |
| 74 | + |
| 75 | + # Grouped by variable name |
| 76 | + images_by_var: Dict[str, List[str]] # Images by variable |
| 77 | + videos_by_var: Dict[str, List[str]] # Videos by variable |
| 78 | + audios_by_var: Dict[str, List[str]] # Audios by variable |
| 79 | + texts_by_var: Dict[str, List[str]] # Texts by variable |
| 80 | + |
| 81 | + # Raw outputs |
| 82 | + outputs: Optional[Dict[str, Any]] # Raw output data |
| 83 | + msg: Optional[str] # Error message (if failed) |
| 84 | +``` |
| 85 | + |
| 86 | +## Usage Example |
| 87 | + |
| 88 | +```python |
| 89 | +import asyncio |
| 90 | +from comfykit import ComfyKit |
| 91 | + |
| 92 | +async def main(): |
| 93 | + # Initialize |
| 94 | + kit = ComfyKit() |
| 95 | + |
| 96 | + # Execute workflow |
| 97 | + result = await kit.execute("workflow.json", { |
| 98 | + "prompt": "a cute cat" |
| 99 | + }) |
| 100 | + |
| 101 | + # Access results |
| 102 | + print(f"Status: {result.status}") |
| 103 | + print(f"Images: {result.images}") |
| 104 | + print(f"Duration: {result.duration}s") |
| 105 | + |
| 106 | +asyncio.run(main()) |
| 107 | +``` |
| 108 | + |
| 109 | +## Next Steps |
| 110 | + |
| 111 | +- Check out complete [Examples](examples.md) |
| 112 | +- Learn about [Configuration](configuration.md) |
| 113 | + |
0 commit comments