comfy-api-simplified


Namecomfy-api-simplified JSON
Version 1.2.1 PyPI version JSON
download
home_pageNone
SummaryA simple way to schedule ComfyUI prompts with different parameters
upload_time2024-11-11 07:47:30
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Comfy API Simplified

This is a small python wrapper over the [ComfyUI](https://github.com/comfyanonymous/ComfyUI) API. It allows you to edit API-format ComfyUI workflows and queue them programmaticaly to the already running ComfyUI.

I use it to iterate over multiple prompts and key parameters of workflow and get hundreds of images overnight to cherrypick from.

## Limitations

Only Basic auth and no auth (for local server) are supported.

## Install

`pip3 install comfy_api_simplified`

## Use prerequisits

### Prepare workflow

You would like to have your node titles unique. Usually both positive and negative prompts have title "CLIP Text Encode (Prompt)", you would like to at least give them different names in case you would like to change it's parameters from python.

### Enable "dev options"

In ComfyUI settings, check "Enable Dev mode Options":
![Alt text](misc/dev_opt.png)

### Download your workflow in API-format

<img src="misc/download.png" width="150">

### Have running ComfyUI server

## Use

```python
from comfy_api_simplified import ComfyApiWrapper, ComfyWorkflowWrapper

# create api wrapper using your ComfyUI url (add user and password params if needed)
api = ComfyApiWrapper("http://127.0.0.1:8188/")

# create workflow wrapper using your downloaded in api format workflow
wf = ComfyWorkflowWrapper("workflow_api.json")

# change anything you like in your workflow
# the syntax is "Node Title", then "Input param name", then value
wf.set_node_param("Empty Latent Image", "batch_size", 2)
wf.set_node_param("negative", "text", "embedding:EasyNegative")

# queue your workflow for completion
results = api.queue_and_wait_images(wf, "Save Image")
for filename, image_data in results.items():
    with open(f"{filename}", "wb+") as f:
        f.write(image_data)

```

More examples:

- Queue prompt and get result images [example](examples/queue_with_different_params.py).

- Queue many prompts and do not wait for completion [example](examples/queue_and_wait_result.py).

- Send input image and then call i2i workflow [example](examples/send_input_image.py).

## Additional info

There are some other approaches to use Python with ComfyUI out there.

If you are looking to conver your workflows to backend server code, check out [ComfyUI-to-Python-Extension](https://github.com/pydn/ComfyUI-to-Python-Extension)

If you are looking to use running ComfyUI as backend, but declare workflow in Python imperatively, check out [ComfyScript](https://github.com/Chaoses-Ib/ComfyScript/tree/main).

## Known issues

If you try to run queue_and_wait_images in async method, it may give you an error since there is already async code inside.
As a workaround, you can use

```python
import nest_asyncio
nest_asyncio.apply()
```

for now.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "comfy-api-simplified",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Deimos Deimos <deimos.double@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/29/08/10c08896e8b58eb1b8d51abb5dbf7927fac7cdb431f4b0e25c208ab68d01/comfy_api_simplified-1.2.1.tar.gz",
    "platform": null,
    "description": "# Comfy API Simplified\n\nThis is a small python wrapper over the [ComfyUI](https://github.com/comfyanonymous/ComfyUI) API. It allows you to edit API-format ComfyUI workflows and queue them programmaticaly to the already running ComfyUI.\n\nI use it to iterate over multiple prompts and key parameters of workflow and get hundreds of images overnight to cherrypick from.\n\n## Limitations\n\nOnly Basic auth and no auth (for local server) are supported.\n\n## Install\n\n`pip3 install comfy_api_simplified`\n\n## Use prerequisits\n\n### Prepare workflow\n\nYou would like to have your node titles unique. Usually both positive and negative prompts have title \"CLIP Text Encode (Prompt)\", you would like to at least give them different names in case you would like to change it's parameters from python.\n\n### Enable \"dev options\"\n\nIn ComfyUI settings, check \"Enable Dev mode Options\":\n![Alt text](misc/dev_opt.png)\n\n### Download your workflow in API-format\n\n<img src=\"misc/download.png\" width=\"150\">\n\n### Have running ComfyUI server\n\n## Use\n\n```python\nfrom comfy_api_simplified import ComfyApiWrapper, ComfyWorkflowWrapper\n\n# create api wrapper using your ComfyUI url (add user and password params if needed)\napi = ComfyApiWrapper(\"http://127.0.0.1:8188/\")\n\n# create workflow wrapper using your downloaded in api format workflow\nwf = ComfyWorkflowWrapper(\"workflow_api.json\")\n\n# change anything you like in your workflow\n# the syntax is \"Node Title\", then \"Input param name\", then value\nwf.set_node_param(\"Empty Latent Image\", \"batch_size\", 2)\nwf.set_node_param(\"negative\", \"text\", \"embedding:EasyNegative\")\n\n# queue your workflow for completion\nresults = api.queue_and_wait_images(wf, \"Save Image\")\nfor filename, image_data in results.items():\n    with open(f\"{filename}\", \"wb+\") as f:\n        f.write(image_data)\n\n```\n\nMore examples:\n\n- Queue prompt and get result images [example](examples/queue_with_different_params.py).\n\n- Queue many prompts and do not wait for completion [example](examples/queue_and_wait_result.py).\n\n- Send input image and then call i2i workflow [example](examples/send_input_image.py).\n\n## Additional info\n\nThere are some other approaches to use Python with ComfyUI out there.\n\nIf you are looking to conver your workflows to backend server code, check out [ComfyUI-to-Python-Extension](https://github.com/pydn/ComfyUI-to-Python-Extension)\n\nIf you are looking to use running ComfyUI as backend, but declare workflow in Python imperatively, check out [ComfyScript](https://github.com/Chaoses-Ib/ComfyScript/tree/main).\n\n## Known issues\n\nIf you try to run queue_and_wait_images in async method, it may give you an error since there is already async code inside.\nAs a workaround, you can use\n\n```python\nimport nest_asyncio\nnest_asyncio.apply()\n```\n\nfor now.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A simple way to schedule ComfyUI prompts with different parameters",
    "version": "1.2.1",
    "project_urls": {
        "Homepage": "https://github.com/deimos-deimos/comfy_api_simplified",
        "Issues": "https://github.com/deimos-deimos/comfy_api_simplified/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6697e034ac0648831d18a1e6e489322eed979ae07343d707f1d70f15ef5130bc",
                "md5": "39e9a7d70ad95410c721b16a57dfb126",
                "sha256": "1471ff22e64fe75e33716dcc8926c7fff419cb84cd43f4f0cbd14fbaaaa59529"
            },
            "downloads": -1,
            "filename": "comfy_api_simplified-1.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "39e9a7d70ad95410c721b16a57dfb126",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6822,
            "upload_time": "2024-11-11T07:47:27",
            "upload_time_iso_8601": "2024-11-11T07:47:27.762989Z",
            "url": "https://files.pythonhosted.org/packages/66/97/e034ac0648831d18a1e6e489322eed979ae07343d707f1d70f15ef5130bc/comfy_api_simplified-1.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "290810c08896e8b58eb1b8d51abb5dbf7927fac7cdb431f4b0e25c208ab68d01",
                "md5": "78a55a14a3a5b5c55e72cbdf12fce506",
                "sha256": "bf1eb0742636537198b684e673ae2f3e95d46808c877848e42fa9e1482d8331a"
            },
            "downloads": -1,
            "filename": "comfy_api_simplified-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "78a55a14a3a5b5c55e72cbdf12fce506",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 878452,
            "upload_time": "2024-11-11T07:47:30",
            "upload_time_iso_8601": "2024-11-11T07:47:30.504387Z",
            "url": "https://files.pythonhosted.org/packages/29/08/10c08896e8b58eb1b8d51abb5dbf7927fac7cdb431f4b0e25c208ab68d01/comfy_api_simplified-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-11 07:47:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "deimos-deimos",
    "github_project": "comfy_api_simplified",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "comfy-api-simplified"
}
        
Elapsed time: 0.31027s