The Problem

ComfyUI is great for visual workflow creation, but it’s a dead end if you need to integrate those workflows into actual Python projects. You’re stuck manually translating nodes and parameters into code—tedious, error-prone, and downright annoying when you’re trying to build something that moves beyond tinkering in a GUI. If you’ve ever thought, “Why can’t I just export this as Python and move on?”, this repo is for you.

What This Does

ComfyUI-to-Python-Extension takes your ComfyUI workflows and spits out Python code that actually works. The meat of the project lives in comfyuitopython.py, which does the heavy lifting of converting nodes and connections into Python functions. There’s also comfyuitopython_utils.py to handle supporting tasks like parameter parsing.

The repo uses pyproject.toml and requirements.txt for dependency management—no surprises there—and a GitHub Actions workflow (.github/workflows/publish.yml) for CI/CD. The images/ folder is just marketing fluff (banners, screenshots, etc.), and there’s a lone JavaScript file, js/save-as-script.js, which likely integrates with ComfyUI’s UI.

You get Python code that imports reusable components (KSamplerAdvanced, VAEDecode, etc.) from the original ComfyUI repo and replicates your workflow logic. No reinventing the wheel here—just clean, modular code that mirrors what you designed visually.

Real-World Use

Say you’re prototyping an AI-powered image generator in ComfyUI. You’ve got a killer workflow built, but now you're tasked with deploying it as part of a larger Python app. Instead of manually rewriting everything, you use this extension to generate the Python equivalent of your workflow:

Boom—your workflow is now a Python script with all the nodes, parameters, and connections intact. You can tweak the generated code to fit your app’s needs, add logging, or scale it for production.

The Bottom Line

This extension is a lifesaver if you’re knee-deep in ComfyUI and need to get workflows into Python without losing your sanity. The code generation is solid, but don’t expect miracles—you’ll still need to understand how the generated code works if you plan to customize it. If you’re building a quick prototype or integrating ComfyUI workflows into a larger system, this is absolutely worth using. For tiny projects? Maybe overkill.