Kubiya SDK
Project description
Kubiya SDK
Kubiya SDK is a powerful Python library for creating, managing, and executing workflows and tools. It provides a flexible and intuitive interface for defining complex workflows, integrating various tools, and managing their execution.
Table of Contents
- Installation
- Quick Start
- Key Concepts
- Creating Workflows
- Defining Tools
- Executing Workflows
- Visualization
- API Reference
- Examples
- Contributing
- License
Key Concepts
- Teammates: AI-powered virtual workers to whom you can delegate technical operations tasks.
- Tools: Reusable functions that can be integrated into workflows and teammate agents.
- Workflows: Sequences of steps that process and transform data.
- Steps: Individual units of work within a workflow.
- State: The data passed between steps in a workflow.
Installation
To install the Kubiya SDK, use pip:
pip install kubiya-sdk
if you want you can install with extra server command to set up an API server for the SDK
pip install kubiya-sdk[server]
Quick Start
Creates a tool
Here's a simple example how to create a new tool.
Use kubiya cli init
command and create a basic template.
kubiya init
It creates a new folder with the following structure needed for the tool.
/my-new-amazing-tool
│
├── /tools
│ ├── /function_tool
│ │ ├── main.py # example for function tool
│ │
│ ├── /hello_world_tool # example for basic tool
│ │ ├── main.py
│ │ └── tool_def
│ └──
│
After you finish editing your tools you can use bundle
command to scan and bundle yours Kubiya's tools in the project
kubiya bundle
The command will scan for tools in the project, check if there are some errors and create an kubiya_bundle.json
file in the root folder.
example of the output:
Python Version: 3.11.10
Tools Discovered: 2
Tools Summary
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━┓
┃ Tool Name ┃ Args ┃ Env Vars ┃ Secrets ┃ Files ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━┩
│ test_123 │ 3 │ 0 │ 0 │ 1 │
│ say_hello │ 1 │ 0 │ 0 │ 1 │
└────────────────────────────────┴──────┴──────────┴─────────┴───────┘
No Errors
Now you can create a new resource via https://kubiya.ai and integrate them with your teammate agent :)
API Reference
For detailed API documentation, please refer to our API Reference.
Examples
Complex Workflow Example
Here's an example of a more complex workflow that demonstrates various features of the Kubiya SDK:
from kubiya_sdk.workflows import StatefulWorkflow
from kubiya_sdk.tools import register_tool
@register_tool(name="DataFetcher", description="Fetches data from an API")
async def fetch_data(api_url: str) -> dict:
# Simulated API call
return {"data": f"Data from {api_url}"}
@register_tool(name="DataProcessor", description="Processes fetched data")
def process_data(data: str) -> dict:
return {"processed_data": f"Processed: {data}"}
workflow = StatefulWorkflow("ComplexWorkflow")
@workflow.step("fetch_step")
async def fetch_step(state):
tool = workflow.get_tool("DataFetcher")
result = await tool.execute(api_url=state["api_url"])
return {"fetched_data": result["data"]}
@workflow.step("process_step")
def process_step(state):
tool = workflow.get_tool("DataProcessor")
result = tool.execute(data=state["fetched_data"])
return {"processed_data": result["processed_data"]}
@workflow.step("decision_step")
def decision_step(state):
data_length = len(state["processed_data"])
return {"data_length": data_length}
@workflow.step("short_data_step")
def short_data_step(state):
return {"result": f"Short data: {state['processed_data']}"}
@workflow.step("long_data_step")
def long_data_step(state):
return {"result": f"Long data: {state['processed_data'][:50]}..."}
workflow.add_edge("fetch_step", "process_step")
workflow.add_edge("process_step", "decision_step")
workflow.add_condition("decision_step", "state['data_length'] < 50", "short_data_step")
workflow.add_condition("decision_step", "state['data_length'] >= 50", "long_data_step")
# Execution
result = await workflow.run({"api_url": "https://api.example.com/data"})
print(result)
This example demonstrates:
- Tool registration and usage
- Multiple workflow steps
- Conditional branching based on state
- Asynchronous operations
Contributing
We welcome contributions to the Kubiya SDK! Please see our Contributing Guidelines for more information on how to get started.
License
Kubiya SDK is released under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file kubiya_sdk-0.1.12.tar.gz
.
File metadata
- Download URL: kubiya_sdk-0.1.12.tar.gz
- Upload date:
- Size: 60.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.4.28
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d55be52ccb584e6df762f273caf784052b0b9508c20c218b842e08fb6de9fd3 |
|
MD5 | f70f6f4f98517e7965c591b400c56497 |
|
BLAKE2b-256 | 851104bf63cf2027a8a518fe72f6dc304c1d916f84afe9bbff190487ca3c5e7e |
File details
Details for the file kubiya_sdk-0.1.12-py3-none-any.whl
.
File metadata
- Download URL: kubiya_sdk-0.1.12-py3-none-any.whl
- Upload date:
- Size: 41.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.4.28
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e000b1f192f7f13484fc323a72e8747e2f478b43e283a2451b45f9177f08cb82 |
|
MD5 | 2f46d92be8f5b7ebbf73bafcaf6f9df7 |
|
BLAKE2b-256 | e23421a5d88db6d7c2682225d4533f9e6435e7aeeb65010e1bce57f272c88d97 |