{"id":15036847,"url":"https://github.com/pydn/comfyui-to-python-extension","last_synced_at":"2026-04-02T17:08:18.877Z","repository":{"id":186779697,"uuid":"672678720","full_name":"pydn/ComfyUI-to-Python-Extension","owner":"pydn","description":"A powerful tool that translates ComfyUI workflows into executable Python code.","archived":false,"fork":false,"pushed_at":"2025-01-14T17:03:18.000Z","size":1658,"stargazers_count":1687,"open_issues_count":40,"forks_count":158,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-05T13:00:38.347Z","etag":null,"topics":["ai-art","comfyui","generative-art","image-generation","pytorch","stable-diffusion"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pydn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-30T22:23:43.000Z","updated_at":"2025-04-05T09:06:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"713ebde1-8bbd-4c38-aff7-000bf45b5e47","html_url":"https://github.com/pydn/ComfyUI-to-Python-Extension","commit_stats":null,"previous_names":["pydn/comfyui-to-python-extension"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydn%2FComfyUI-to-Python-Extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydn%2FComfyUI-to-Python-Extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydn%2FComfyUI-to-Python-Extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydn%2FComfyUI-to-Python-Extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pydn","download_url":"https://codeload.github.com/pydn/ComfyUI-to-Python-Extension/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248585892,"owners_count":21128980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-art","comfyui","generative-art","image-generation","pytorch","stable-diffusion"],"created_at":"2024-09-24T20:32:30.895Z","updated_at":"2026-04-02T17:08:18.865Z","avatar_url":"https://github.com/pydn.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ComfyUI-to-Python-Extension\n\n![banner](images/comfyui_to_python_banner.png)\n\nBuild a workflow in ComfyUI, then walk away with runnable Python.\n\n`ComfyUI-to-Python-Extension` turns visual workflows into executable scripts so you can move from node graphs to automation, experiments, and repeatable generation without rebuilding everything by hand.\n\nThis project supports:\n- exporting from the ComfyUI UI with `Save As Script`\n- converting saved API-format workflows with the CLI\n\n## Install\n\nChoose the setup that matches how you want to use the project.\nThis project supports Python 3.12 and newer.\n\n### Web UI extension (`File -\u003e Save As Script`)\n\nFor ComfyUI to recognize this project as an extension, the repo must be discoverable through ComfyUI's `custom_nodes` search paths.\n\nUse one of these setups:\n\n1. Clone directly into `ComfyUI/custom_nodes`\n```bash\ncd /path/to/ComfyUI/custom_nodes\ngit clone https://github.com/pydn/ComfyUI-to-Python-Extension.git\ncd ComfyUI-to-Python-Extension\nuv sync\n```\n\n2. Keep the repo elsewhere, then either:\n- symlink it into `ComfyUI/custom_nodes`\n- add its parent directory to ComfyUI's `custom_nodes` search paths via `extra_model_paths.yaml`\n\nExample symlink setup:\n```bash\ngit clone https://github.com/pydn/ComfyUI-to-Python-Extension.git\ncd /path/to/ComfyUI/custom_nodes\nln -s /path/to/ComfyUI-to-Python-Extension ComfyUI-to-Python-Extension\ncd /path/to/ComfyUI-to-Python-Extension\nuv sync\n```\n\nAfter installation, restart ComfyUI.\n\n### CLI exporter / generated scripts\n\nYou can keep the repo anywhere for CLI usage and generated-script execution.\n\n```bash\ngit clone https://github.com/pydn/ComfyUI-to-Python-Extension.git\ncd ComfyUI-to-Python-Extension\nuv sync\nexport COMFYUI_PATH=/path/to/ComfyUI\n```\n\n`COMFYUI_PATH` helps the exporter and generated scripts find the ComfyUI codebase. It does not, by itself, register this repo as a ComfyUI extension for the Web UI.\n\n`COMFYUI_PATH` is checked first. If it is not set, the exporter falls back to searching parent directories for a folder named `ComfyUI`.\n\n## Web UI Export\n\nIn current ComfyUI builds, `Save As Script` is typically available under:\n\n`File -\u003e Save As Script`\n\nThe command downloads a generated `.py` file.\nThe current UI export uses the default filename `workflow_api.py` so it works in ComfyUI Desktop without relying on `prompt()`.\n\n![Save As Script](images/save_as_script.png)\n\nNotes:\n- menu placement can differ between frontend versions\n- the Web UI export uses a fixed default filename rather than asking for one interactively\n\n## CLI Export\n\n1. In ComfyUI, enable dev mode options if needed.\n2. Save the workflow in API format: `File -\u003e Export (API)`.\n3. Run the exporter:\n\n```bash\nuv run python -m comfyui_to_python\n```\n\nOptions:\n\n```bash\nuv run python -m comfyui_to_python \\\n  --input_file workflow_api.json \\\n  --output_file workflow_api.py \\\n  --queue_size 10\n```\n\nThe legacy wrapper still works if you prefer it:\n\n```bash\nuv run python comfyui_to_python.py\n```\n\nFlags:\n- `--input_file`: input workflow JSON, default `workflow_api.json`\n- `--output_file`: output Python file, default `workflow_api.py`\n- `--queue_size`: default execution count in the generated script, default `10`\n\n![Dev Mode Options](images/dev_mode_options.PNG)\n\n## Generated Scripts\n\nGenerated scripts depend on a working ComfyUI runtime.\n\nIf the repo is not inside ComfyUI, set:\n\n```bash\nexport COMFYUI_PATH=/path/to/ComfyUI\n```\n\nThe generated script is a workflow export. It does not automatically turn workflow inputs into command-line arguments.\n\nScripts exported directly from `File -\u003e Save As Script` in the ComfyUI UI already include the frontend workflow metadata needed for drag-and-drop reimport. Images saved by those scripts can be dropped back into ComfyUI and reopen with the original workflow metadata.\n\nGenerated scripts reuse ComfyUI's runtime argument parser during bootstrap, so common ComfyUI memory flags such as `--highvram`, `--normalvram`, `--lowvram`, `--novram`, `--cpu`, and `--disable-smart-memory` can be passed directly to the exported `.py` file.\n\nLifecycle notes:\n- exported scripts are single-shot workflow runners, not long-lived ComfyUI prompt servers\n- they do not implement Web UI prompt/result caching across repeated service calls\n- exported `main()` now performs best-effort ComfyUI model/cache cleanup in a `finally` block\n- set `COMFYUI_TOPYTHON_UNLOAD_MODELS=1` or call `main(unload_models=True)` if an embedded or repeated-call host should aggressively unload models after each run instead of preserving them for reuse\n\n## Troubleshooting\n\n- unsupported Python version:\n  use Python 3.12 or newer, then rerun `uv sync`\n- `Save As Script` not visible:\n  check your current ComfyUI menu/frontend version and look under `File`\n- `Save As Script` not visible after restart:\n  make sure this repo is discoverable by ComfyUI through `custom_nodes` by cloning it into `ComfyUI/custom_nodes`, symlinking it there, or adding an external `custom_nodes` path in `extra_model_paths.yaml`\n- save uses the default filename:\n  rename `workflow_api.py` after download if you want a different local filename\n- ComfyUI cannot be found:\n  set `COMFYUI_PATH`\n- models or paths are missing at runtime:\n  verify the target ComfyUI install and its `extra_model_paths.yaml`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpydn%2Fcomfyui-to-python-extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpydn%2Fcomfyui-to-python-extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpydn%2Fcomfyui-to-python-extension/lists"}