comfy-api-client
A Python client for the ComfyUI API, providing:
⚡ Full API coverage
⚡ Asynchronous execution
⚡ WebSocket support
⚡ Workflow templating
⚡ WebSocket or HTTP-based polling
Installation
Install the package using pip:
pip install comfy-api-client
Usage
Create a Client
Use the create_client context manager to create a ComfyUI client. This will set up the underlying HTTP client and a WebSocket or HTTP-based state tracker to poll results from the server:
from comfy_api_client import create_client
# Protocol is omitted as the URL may be used for both HTTP and WebSocket requests
comfyui_server = "localhost:8188"
async with create_client(comfyui_server) as client:
print(await client.get_system_stats())
Submit Workflows
To submit a workflow, read the workflow configuration file and pass it to the client:
from comfy_api_client import utils
workflow = utils.read_json("workflow.json")
async with create_client(comfyui_server) as client:
prompt = await client.submit_workflow(workflow)
result = await prompt.future
image_items = result.output_images
image = image_items[0].image
Result polling
HTTP-based polling
By default, the execution state of a prompt is tracked via a WebSocket connection. In cases where a WebSocket connection cannot be established, e.g. if the ComfyUI server is behind a proxy or firewall, HTTP-based polling can be used instead.
Simply provide start_state_tracker="http" to the create_client function:
async with create_client(comfyui_server, start_state_tracker="http") as client:
# Submit and await results as before
prompt = await client.submit_workflow(workflow)
result = await prompt.future
Note, that HTTP polling relies on frequent querying of the prompt status from the ComfyUI server and will thus create more traffic while being less responsive.
Manual polling
The prompt status and results can also be queried manually. In this case, start_state_tracker=None can be passed to create_client and return_future=False to the submit_workflow() method.
import time
async with create_client(comfyui_server, start_state_tracker=None) as client:
# Submit and await result as before
prompt = await client.submit_workflow(workflow, return_future=False)
# Will be None; the status needs to be checked manually
prompt.future
# Wait for the prompt to finish
time.sleep(20)
result = await client.fetch_results(prompt)
image_items = result.output_images
image = image_items[0].image
Tests
Run tests:
pytest tests
This will set up a local ComfyUI instance to test against.
TODOs
- Add logging support
- Improve error handling and messages
- Implement a synchronous client
Metadata
Release files for comfy-api-client 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| comfy_api_client-0.1.0.tar.gz | 9.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| comfy_api_client-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.2 kB
Release files / comfy_api_client-0.1.0.tar.gz
| Download URL | comfy_api_client-0.1.0.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
52d2bcc43809c9774751ddb6cda91a662458b5f45c1eed51175c2c3752912d22
|
|
BLAKE2b-256 checksum How to use checksums |
99d156e737b837d88906e8d25c1ade8d86e8a63c684f0d62dc26e4bc030331eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.11.9 Darwin/24.0.0
|
Release files / comfy_api_client-0.1.0-py3-none-any.whl
| Download URL | comfy_api_client-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01be45a33c90c65930ee1f662b207c1827b0392b1d55b9554d840904727f526e
|
|
BLAKE2b-256 checksum How to use checksums |
1ec5c5500819a8c28e610dce0a061fd1a5801f14b3a42eba9cce12e856ae9de8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.11.9 Darwin/24.0.0
|