Examples

This section contains examples demonstrating how to use the Kailash SDK with current API patterns.

Note

All code examples use os.environ for model names and API keys. Never hardcode model names like "gpt-4" – always read from .env.

Example Categories

Basic Examples

Simple workflows demonstrating WorkflowBuilder, node creation, and runtime execution.

Advanced Examples

Complex patterns including cyclic workflows, conditional execution, and parallel branches.

Integration Examples

External system integrations including APIs, databases, and AI providers.

Patterns

Production-ready workflow patterns for common use cases.

Quick Example

import os
from dotenv import load_dotenv
load_dotenv()

from kailash.workflow.builder import WorkflowBuilder
from kailash.runtime import LocalRuntime

workflow = WorkflowBuilder()
workflow.add_node("PythonCodeNode", "hello", {
    "code": "result = {'message': 'Hello from Kailash!'}"
})

with LocalRuntime() as runtime:
    results, run_id = runtime.execute(workflow.build())
    print(results["hello"]["result"]["message"])

For the complete collection of runnable examples, visit the examples directory in the GitHub repository.