Skip to main content

comfyui-reflex

零三方依赖 (Zero Dependencies) 的纯 Python 标准库,专用于高效改写、解析、检查与重构 ComfyUI API 工作流。

Python License Dependencies


🌟 核心特性

  • 纯标准库实现:零外部依赖,极速安装,可无缝嵌入任何 Web 框架(FastAPI、Flask、Django)、云函数或脚本工具。
  • 面向对象流式操作 (ComfyWorkflow):通过直观的链式调用轻松修改提示词、负向词、采样参数、随机种子、图像分辨率与模型。
  • PNG 图像工作流提取:内置纯标准库解析器,支持直接从 ComfyUI 输出的 PNG 图像中无损提取 Prompt API JSON 和 WebUI 工作流。
  • 自动 LoRA 图拓扑重构:内置 LoRA 语法解析器与节点链重构器,自动识别下游节点并串联 LoraLoader。
  • 声明式 Reflex 规则引擎:支持基于映射配置改写工作流,提供 randint、upscale、append_prompt、replace_prompt、value、image 等高级动作及多后端动态适配。
  • 高阶分辨率计算:支持预设形制 (p/l/s)、WxH 字符串与宽高比算力基准换算。
  • 完整类型提示:配备 PEP 561 py.typed,支持 mypy 与 pyright 静态检查。

📦 安装

pip install comfyui-reflex

🚀 快速上手

1. 链式改写 ComfyUI 工作流

from comfyui_reflex import ComfyWorkflow

# 从 JSON 文件或 ComfyUI 生成的 PNG 图片加载
wf = ComfyWorkflow.load("workflow.json")
# 或者直接从图片反解:
# wf = ComfyWorkflow.from_image("ComfyUI_00001_.png")

# 链式改写常用参数
wf.set_prompt("1girl, cyber city, neon lighting, 8k masterpiece") \
  .set_negative_prompt("blurry, low quality, bad anatomy") \
  .set_seed(123456) \
  .set_dimensions(width=832, height=1216) \
  .set_sampler(steps=28, cfg=7.0, sampler_name="Euler a", scheduler="karras") \
  .inject_lora("detail_slider.safetensors", strength_model=0.8)

# 构造直接发送至 ComfyUI HTTP /prompt 接口的 payload
payload = wf.to_prompt_payload(client_id="my_client_123")

# 保存修改后的工作流
wf.save("workflow_modified.json")

2. 纯标准库 PNG 元数据提取

from comfyui_reflex import extract_prompt_from_png, extract_comfyui_metadata_from_png

# 提取 ComfyUI API Prompt (可直接转为 ComfyWorkflow)
prompt_dict = extract_prompt_from_png("output.png")

# 提取全部元数据 (包含 prompt 与 webui workflow)
metadata = extract_comfyui_metadata_from_png("output.png")
print("Prompt 节点数:", len(metadata.get("prompt", {})))

3. LoRA 提取与节点链自动注入

from comfyui_reflex import extract_loras_from_prompt, ComfyWorkflow

raw_prompt = "1girl, <lora:add_detail:0.8>, solo, <lora:flat_color:0.5>"
clean_prompt, loras = extract_loras_from_prompt(raw_prompt)
# clean_prompt: "1girl, solo"
# loras: [("add_detail", 0.8), ("flat_color", 0.5)]

wf = ComfyWorkflow.load("workflow.json")
wf.set_prompt(clean_prompt).inject_loras(loras)

4. 声明式 Reflex 规则改写

from comfyui_reflex import ComfyWorkflow, ReflexConfig

wf = ComfyWorkflow.load("workflow.json")
reflex = ReflexConfig.from_file("workflow_reflex.json")

wf.apply_reflex(
    reflex=reflex,
    params={
        "prompt": "masterpiece, 1girl",
        "negative_prompt": "low quality",
        "width": 1024,
        "height": 1024,
        "seed": 42,
        "sampler": "Euler a",
        "scheduler": "karras",
        "steps": 30,
        "cfg_scale": 6.5
    }
)

🛠️ 模块体系

模块 核心导出 功能简述
comfyui_reflex.workflow ComfyWorkflow 面向对象的工作流容器,支持流式改写、节点查找、连线与序列化
comfyui_reflex.models ComfyNode, ReflexConfig 节点对象封装与 Reflex 映射规则协议模型
comfyui_reflex.png extract_prompt_from_png 等 纯标准库读取 PNG 图像中的 tEXt / iTXt 块提取工作流
comfyui_reflex.lora extract_loras_from_prompt 等 提示词 LoRA 标记提取与图内动态拓扑链式插入
comfyui_reflex.dimensions calculate_dimensions 形制与比例分辨率自适应运算
comfyui_reflex.engine ReflexEngine 声明式规则应用与高级动作执行(randint、upscale、reg_args 等)
comfyui_reflex.loader WorkflowLoader 同步与异步工作流文件成对扫描与加载

📄 License

MIT

Metadata

Release files for comfyui-reflex 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for comfyui-reflex 0.1.0
File Size Uploaded Provenance Actions
comfyui_reflex-0.1.0.tar.gz 18.8 kB Without provenance Details for comfyui_reflex-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for comfyui-reflex 0.1.0
File Interpreter ABI Platform Actions
comfyui_reflex-0.1.0-py3-none-any.whl Python 3 none any Details for comfyui_reflex-0.1.0-py3-none-any.whl

Total release size: 43.4 kB

Release files / comfyui_reflex-0.1.0.tar.gz

Download URL comfyui_reflex-0.1.0.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
441ce3c2f052f3d4adc5688f03847f6f9a7588d241e6bdeb78c4e1e0f37f37ee
BLAKE2b-256 checksum
How to use checksums
b036455c17f89b94f6aa90c8faa41e64888c794fd2b8e9bd76d898237f44005e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / comfyui_reflex-0.1.0-py3-none-any.whl

Download URL comfyui_reflex-0.1.0-py3-none-any.whl
Size 24.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
91c64a9a9d094abf984f53bbad406cd6b5f3628a558d28fae2a42002a2a967f1
BLAKE2b-256 checksum
How to use checksums
139c24376b37a82965ccf15c01e36a093f1a062680b4649fd5bb11bd43f6da73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for comfyui-reflex 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page