Skip to main content
Your ComfyUI workflows are deployed as APIs—now let’s integrate them into Python applications. This SDK transforms your creative AI work into application features that users can access through web services, data pipelines, automation systems, and interactive tools.
What you’re building: Instead of asking users to understand ComfyUI or API endpoints, you’re creating seamless experiences where AI capabilities feel like native Python functions. Your workflows become the invisible intelligence powering data processing, web applications, and automated systems.
🚀 What’s New in v1.1.4
  • 🔄 Updated Response Format: Both execute_workflow and execute_workflow_async now return workflow_id alongside run_id
  • ✨ Enhanced Polling: Improved execute_workflow_async with better run status detection and failure handling
  • 📚 Comprehensive Documentation: Advanced usage examples for FastAPI, Django, Flask, and Jupyter integration
  • 🖼️ Dynamic Parameters: Full support for dynamic parameter names matching your ComfyUI workflow structure
  • 📤 Multiple File Support: Handle multiple images, videos, and files in single workflow execution
  • 📊 Pagination & Filtering: Enhanced get_runs() with sorting, filtering, and pagination capabilities

Installation: Adding AI Power to Your Python Projects

Ready to bring your AI workflows into your Python applications? Install the FlowScale SDK to start integrating your deployed ComfyUI workflows into any Python project.
What this enables: Your users won’t interact with ComfyUI or see API endpoints—they’ll experience AI capabilities as seamless Python functions. Image generation, style transfer, content creation, and other AI workflows become as simple as calling a method.

Quick Start: From Deployment to Integration

Prerequisites: You should have already deployed your ComfyUI workflow as an API through the FlowScale AI platform. If you haven’t, complete the Deploy Workflows guide first.

Connecting Your Python Application to Your AI Infrastructure

This is where your deployed AI workflows become Python application features. Import the SDK and connect to the production APIs you’ve already created:

Environment Variables

Add the following to your .env file:

Integration Patterns for Production Applications

Choose the integration pattern that matches your application’s needs:
Best for: API endpoints, web applications, microservicesBenefits:
  • Production-ready web framework integration
  • Built-in authentication and validation
  • Scalable request handling
  • Easy deployment and monitoring
Use cases: REST APIs, web applications, background job processing

Configuration

Client Options

Logging Configuration

The SDK includes configurable logging to help with debugging and monitoring:
  • debug: Most verbose, includes detailed operation information
  • info: General information about operations (default)
  • warn: Warning messages for potential issues
  • error: Only error messages
All logs are prefixed with timestamp and level:

Core Methods

Platform Health and Status

Check Health Status

Monitor the health of the FlowScale platform, including container status:

Get Queue Status

Retrieve the current workflow queue status:

Workflow Execution

Execute Workflow (Synchronous)

Trigger a workflow execution and get immediate response:

Execute Workflow (Asynchronous with Auto-Polling)

Execute a workflow and automatically poll for its output until completion:
If the workflow doesn’t complete within the timeout period, a FlowScaleTimeoutError exception will be raised.

Dynamic Parameter Support

The SDK supports dynamic parameter names that match your workflow’s requirements:

Managing Workflow Runs

Get Run Details

Retrieve detailed information about a specific workflow run:

Get Multiple Runs with Pagination ✨

Retrieve workflow runs with advanced pagination, sorting, and filtering capabilities:
Parameters:
  • group_id (string, optional): Filter runs by group identifier
  • sort_by (string, optional): Field to sort by - "created_at", "started_at", or "completed_at" (default: "created_at")
  • sort_order (string, optional): Sort order - "asc" or "desc" (default: "desc")
  • page (int, optional): Page number starting from 1 (default: 1)
  • page_size (int, optional): Number of items per page, 1-100 (default: 10)

Cancel Running Workflow

Cancel a workflow execution using its run ID:

Retrieving Outputs

Get Workflow Output

Fetch the output of a completed workflow using its filename:

Advanced Usage Examples

Batch Processing with Groups

Error Handling and Retries

Pagination Helper

Framework Integration

FastAPI Integration

The SDK works seamlessly with FastAPI for building API endpoints:

Django Integration

Flask Integration

Jupyter Notebook Integration

File Handling

Working with Different File Types

Downloading and Saving Results

Error Handling

Exception Types

Comprehensive Error Handling Pattern

Best Practices

Environment Configuration

Always store sensitive information such as API keys in environment variables:

Performance Optimization

Input Validation

Logging and Monitoring

Testing and Debugging

Unit Testing

Debug Mode Usage

Examples & Recipes

Text to Image Generation

Complete Python examples for text-to-image generation workflows

Image Processing Pipeline

Transform and enhance images using AI-powered workflows

Batch Processing

Process multiple files efficiently with concurrent execution

FastAPI Integration

Build API endpoints with FastAPI and FlowScale workflows

Jupyter Notebooks

Interactive workflow execution in Jupyter environments

Error Handling & Retry Logic

Robust error handling and automatic retry mechanisms

Support

Need help with the Python SDK?

API Reference

Complete API documentation and endpoint reference

PyPI Package

Official PyPI package with installation instructions

Discord Community

Chat with other developers and get community support

Support Team

Direct support for technical issues and questions

Documentation

Complete guides and tutorials for getting started