Skip to main content

comfyui_rs/
lib.rs

1//! # comfyui-rs
2//!
3//! Async Rust client for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) —
4//! the node-based Stable Diffusion GUI/backend.
5//!
6//! Provides a typed client for REST operations, WebSocket-based real-time
7//! progress tracking with automatic polling fallback, model discovery, and
8//! a workflow builder for common generation patterns.
9//!
10//! ## Quick Start
11//!
12//! ```no_run
13//! use comfyui_rs::{ComfyClient, Txt2ImgRequest, GenerationOutcome};
14//! use std::time::Duration;
15//!
16//! # async fn example() -> comfyui_rs::Result<()> {
17//! let client = ComfyClient::new("http://127.0.0.1:8188");
18//!
19//! // Discover models
20//! let checkpoints = client.checkpoints().await?;
21//! let checkpoint = &checkpoints[0];
22//!
23//! // Build a workflow
24//! let (workflow, seed) = Txt2ImgRequest::new("a sunset over mountains", checkpoint)
25//!     .negative("lowres, blurry")
26//!     .steps(25)
27//!     .build();
28//!
29//! // Queue and wait with real-time progress
30//! let prompt_id = client.queue_prompt(&workflow).await?;
31//! let result = client.wait_for_completion_ws(
32//!     &prompt_id,
33//!     Duration::from_secs(120),
34//!     |p| println!("Step {}/{}", p.current_step, p.total_steps),
35//! ).await?;
36//!
37//! if let GenerationOutcome::Completed { images } = result {
38//!     for img in &images {
39//!         let bytes = client.image(img).await?;
40//!         std::fs::write(&img.filename, &bytes).unwrap();
41//!     }
42//! }
43//! # Ok(())
44//! # }
45//! ```
46
47pub mod client;
48pub mod error;
49pub mod types;
50pub mod workflow;
51
52pub use client::ComfyClient;
53pub use error::{ComfyError, Result};
54pub use types::{
55    ComfyProgress, ComfyStatus, DownloadLimits, GenerationOutcome, ImageRef, ProgressUpdate,
56    PromptHistory, QueueStatus, WsConfig,
57};
58pub use workflow::Txt2ImgRequest;