Skip to main content

iFlow Python SDK

Python Version License WebSocket Protocol

A powerful Python SDK for interacting with iFlow CLI using the Agent Communication Protocol (ACP). Build AI-powered applications with full control over conversations, tool execution, and SubAgent orchestration.

✨ Key Feature: The SDK automatically manages the iFlow process - no manual setup required!

Features

  • 🚀 Automatic Process Management - Zero-config setup! SDK auto-starts and manages iFlow CLI
  • 🔌 Smart Port Detection - Automatically finds available ports, no conflicts
  • 🔄 Bidirectional Communication - Real-time streaming of messages and responses
  • 🛠️ Tool Call Management - Handle and control tool executions with fine-grained permissions
  • 🤖 SubAgent Support - Track and manage multiple AI agents with agent_id propagation
  • 📋 Task Planning - Receive and process structured task plans
  • 🔍 Raw Data Access - Debug and inspect protocol-level messages
  • ⚡ Async/Await Support - Modern asynchronous Python with full type hints
  • 🎯 Simple & Advanced APIs - From one-line queries to complex conversation management
  • 📦 Full ACP v1 Protocol - Complete implementation of the Agent Communication Protocol

Installation

1. Install iFlow CLI

If you haven't installed iFlow CLI yet:

Mac/Linux/Ubuntu:

bash -c "$(curl -fsSL https://gitee.com/iflow-ai/iflow-cli/raw/main/install.sh)"

Windows:

npm install -g @iflow-ai/iflow-cli@latest

2. Install the SDK

From source (currently the only method):

git clone https://github.com/yourusername/iflow-cli-sdk-python.git
cd iflow-cli-sdk-python
pip install -e .

Coming soon to PyPI:

# Will be available after publishing to PyPI
pip install iflow-cli-sdk

Quick Start

The SDK automatically manages the iFlow process - no manual setup required!

Default Usage (Automatic Process Management)

import asyncio
from src.iflow_sdk import IFlowClient

async def main():
    # SDK automatically:
    # 1. Detects if iFlow is installed
    # 2. Starts iFlow process if not running
    # 3. Finds an available port
    # 4. Cleans up on exit
    async with IFlowClient() as client:
        await client.send_message("Hello, iFlow!")
        
        async for message in client.receive_messages():
            print(message)
            # Process messages...

asyncio.run(main())

No need to manually start iFlow! The SDK handles everything for you.

Advanced: Manual Process Control

If you need to manage iFlow yourself (rare cases):

import asyncio
from src.iflow_sdk import IFlowClient, IFlowOptions

async def main():
    # Disable automatic process management
    options = IFlowOptions(
        auto_start_process=False,
        url="ws://localhost:8090/acp"  # Connect to existing iFlow
    )
    
    async with IFlowClient(options) as client:
        await client.send_message("Hello, iFlow!")

asyncio.run(main())

Note: Manual mode requires you to start iFlow separately:

iflow --experimental-acp --port 8090

Simple Examples

Simple Query

import asyncio
from src.iflow_sdk import query

async def main():
    response = await query("What is the capital of France?")
    print(response)  # "The capital of France is Paris."

asyncio.run(main())

Interactive Conversation

import asyncio
from src.iflow_sdk import IFlowClient, AssistantMessage, TaskFinishMessage

async def chat():
    async with IFlowClient() as client:
        await client.send_message("Explain quantum computing")
        
        async for message in client.receive_messages():
            if isinstance(message, AssistantMessage):
                print(message.chunk.text, end="", flush=True)
            elif isinstance(message, TaskFinishMessage):
                break

asyncio.run(chat())

Tool Call Control

import asyncio
from src.iflow_sdk import IFlowClient, IFlowOptions, PermissionMode, ToolCallMessage, TaskFinishMessage

async def main():
    options = IFlowOptions(permission_mode=PermissionMode.CONFIRM)
    
    async with IFlowClient(options) as client:
        await client.send_message("Create a file called test.txt")
        
        async for message in client.receive_messages():
            if isinstance(message, ToolCallMessage):
                print(f"Tool requested: {message.label}")
                # Tool calls are handled automatically based on permission_mode
            elif isinstance(message, TaskFinishMessage):
                break

asyncio.run(main())

API Reference

Core Classes

  • IFlowClient: Main client for bidirectional communication
  • IFlowOptions: Configuration options
  • RawDataClient: Access to raw protocol data

Message Types

  • AssistantMessage: AI assistant responses
  • ToolCallMessage: Tool execution requests
  • PlanMessage: Structured task plans
  • TaskFinishMessage: Task completion signal

Convenience Functions

  • query(prompt): Simple synchronous query
  • query_stream(prompt): Streaming responses
  • query_sync(prompt): Synchronous with timeout

Project Structure

iflow-sdk-python/
├── src/iflow_sdk/
│   ├── __init__.py          # Public API exports
│   ├── client.py            # Main IFlowClient implementation
│   ├── query.py             # Simple query functions
│   ├── types.py             # Type definitions and messages
│   ├── raw_client.py        # Raw protocol access
│   └── _internal/
│       ├── protocol.py      # ACP protocol handler
│       ├── transport.py     # WebSocket transport layer
│       └── launcher.py      # iFlow process management
├── tests/                   # Test suite
│   ├── test_basic.py        # Basic functionality tests
│   └── test_protocol.py     # Protocol compliance tests
├── examples/                # Usage examples
│   ├── comprehensive_demo.py
│   ├── quick_start.py
│   └── advanced_client.py
└── docs/                    # Documentation

Development

Running Tests

# Run all tests
pytest tests/

# Run with coverage
pytest tests/ --cov=src/iflow_sdk

# Run specific test
pytest tests/test_basic.py

Code Quality

# Format code
black src/ tests/

# Sort imports
isort src/ tests/

# Check style
flake8 src/ tests/

Protocol Support

The SDK implements the Agent Communication Protocol (ACP) v1, supporting:

  • Session Management: Create, load, and manage conversation sessions
  • Message Types:
    • agent_message_chunk - Assistant responses
    • agent_thought_chunk - Internal reasoning
    • tool_call / tool_call_update - Tool execution lifecycle
    • plan - Structured task planning
    • user_message_chunk - User message echoing
  • Authentication: Built-in iFlow authentication
  • File System Access: Read/write file permissions
  • SubAgent Support: Full agent_id tracking and management

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support


Built with ❤️ for the AI development community

Metadata

Release files for iflow-sdk 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 iflow-sdk 0.1.0
File Size Uploaded Provenance Actions
iflow_sdk-0.1.0.tar.gz 34.3 kB Without provenance Details for iflow_sdk-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for iflow-sdk 0.1.0
File Interpreter ABI Platform Actions
iflow_sdk-0.1.0-py3-none-any.whl Python 3 none any Details for iflow_sdk-0.1.0-py3-none-any.whl

Total release size: 67.5 kB

Release files / iflow_sdk-0.1.0.tar.gz

Download URL iflow_sdk-0.1.0.tar.gz
Size 34.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8691b8a0333b022289744f7cdf4bcfeb5a3adcf6f3fb8abe29a7e0dc5f799107
BLAKE2b-256 checksum
How to use checksums
ac189b2dd24011268d390f70de1db3d31ee53399b6d3b2f03ae772a264371cb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

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

Download URL iflow_sdk-0.1.0-py3-none-any.whl
Size 33.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b7b23fc448c38fb42b425ed382e13ae2df12b7b1105790518780ddc4085b698
BLAKE2b-256 checksum
How to use checksums
abb1595a6d5dc4ac3957fb375a1a886f4efae4531dd433aa72f4c19d39d8813a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Security for iflow-sdk 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