Skip to content

Red-Hat-AI-Innovation-Team/langflow_python_sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Langflow Python SDK

Thin Python SDK for programmatic Langflow flow manipulation. Designed for LLM agents to build and modify workflows.

Installation

pip install langflow-sdk

Or install from source:

cd langflow-python-sdk
pip install -e .

Quick Start

from langflow_sdk import FlowEditor

# Connect to Langflow
editor = FlowEditor(
    base_url="http://localhost:7860",
    api_key="your-api-key"  # optional
)

# Create a flow
flow_id = editor.create_flow("My Chatbot")

# Add nodes
chat_input = editor.add_node(flow_id, "inputs", "ChatInput", (100, 200))
llm = editor.add_node(
    flow_id, "models", "OpenAIModel", (400, 200),
    field_values={"model_name": "gpt-4o", "temperature": 0.7}
)
chat_output = editor.add_node(flow_id, "outputs", "ChatOutput", (700, 200))

# Connect nodes
editor.connect(flow_id, chat_input, "message", llm, "input_value")
editor.connect(flow_id, llm, "text_output", chat_output, "input_value")

# Save to server
editor.save_flow(flow_id)

API Reference

Component Discovery

# List component categories
types = editor.list_component_types()
# ['agents', 'models', 'prompts', 'inputs', 'outputs', ...]

# List components in a category
models = editor.list_components("models")
# ['OpenAIModel', 'AnthropicModel', 'OllamaModel', ...]

# Get component details
info = editor.get_component_info("models", "OpenAIModel")
for field in info.fields:
    print(f"{field.name}: {field.field_type} = {field.value}")

Flow Management

# Create
flow_id = editor.create_flow("Name", description="Optional description")

# Read
flow = editor.get_flow(flow_id)

# Save changes
editor.save_flow(flow_id)

# Delete
editor.delete_flow(flow_id)

Node Operations

# Add node
node_id = editor.add_node(
    flow_id,
    component_type="models",
    component_name="OpenAIModel",
    position=(400, 200),
    field_values={"temperature": 0.5}
)

# Update field
editor.update_field(flow_id, node_id, "temperature", 0.9)

# Get field values
fields = editor.get_node_fields(flow_id, node_id)

# List all nodes
nodes = editor.list_nodes(flow_id)

# Remove node
editor.remove_node(flow_id, node_id)

Edge Operations

# Connect nodes
edge_id = editor.connect(
    flow_id,
    source_node_id, "output_name",
    target_node_id, "input_field"
)

# List edges
edges = editor.list_edges(flow_id)

# Disconnect
count = editor.disconnect(flow_id, source_node_id, target_node_id)

For LLM Agents

See SKILL.md for:

  • System prompt for LLM agents
  • Workflow patterns
  • Common component reference
  • MCP tool definitions

Architecture

The SDK wraps Langflow's REST API:

FlowEditor (this SDK)
    │
    ├── GET /api/v1/all          → component templates
    ├── GET /api/v1/flows/{id}   → read flow
    ├── PATCH /api/v1/flows/{id} → update flow
    ├── POST /api/v1/flows/      → create flow
    └── DELETE /api/v1/flows/{id}→ delete flow

Changes are cached locally and persisted on save_flow().

License

MIT

About

LangFlow Python Client SDK for LLMs to interact with flows

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages