Skip to main content

Kubiya SDK

Project description

Kubiya SDK

Kubiya SDK is a powerful Python library designed for creating, managing, and executing tools. It offers a flexible and intuitive interface, facilitating the integration of various tools and the efficient management of their execution.

Table of Contents

Installation

To install the Kubiya SDK, use pip:

pip install kubiya-sdk

Key Concepts

  • Teammates: AI-powered virtual assistants capable of managing technical operations tasks.
  • Tools: Reusable functions that can be integrated into workflows and teammate agents.
  • Steps: Individual units of work within a workflow.
  • State: The data passed between steps in a workflow.

For setting up an API server for the SDK, you may install with additional server support:

pip install kubiya-sdk[server]

Quick Start

Creating a Tool

Here’s a basic example of how to create a new tool.

Use the Kubiya CLI init command to generate a foundational template:

kubiya init

This creates a new folder with the following structure 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 editing your tools, you need to use the bundle command to scan and package your Kubiya tools within the project:

kubiya bundle

The command scans for tools in the project, verifies for any errors, and generates a kubiya_bundle.json file in the root folder. An example 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

You can now create a new resource via https://kubiya.ai and integrate it with your teammate agent.

Examples

Example for function tool (Recommended)

@function_tool(
    description="Prints pandas {name}!",
    requirements=["pandas==2.2.3"],
)
def test_123(
        name: str,
        boolean_val: bool,  # This will validate that the input is a boolean
        optional_str: Annotated[
            str, typer.Argument()
        ] = "sheeesh",  # This is how to add a default value
):
    import pandas as pd

    print(f"Hello {name}! {boolean_val} {optional_str}")
    df = pd.DataFrame(
        {"name": [name], "boolean_val": [boolean_val], "test": [optional_str]}
    )

    print(df)

Example for basic tool

Simple main.py file for a tool that prints hello {name}!

def hello_world(name: str):
    print(f"Hello, {name}!")


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Print hello {name}!")
    parser.add_argument("name", help="Name to say hello to")

    # Parse command-line arguments
    args = parser.parse_args()

    # Get coordinates for the given city
    name = args.name

    hello_world(name)
import inspect

from kubiya_sdk.tools.models import Arg, Tool, FileSpec
from kubiya_sdk.tools.registry import tool_registry

from . import main

hello_tool = Tool(
    name="say_hello",
    type="docker",
    image="python:3.12",
    description="Prints hello {name}!",
    args=[Arg(name="name", description="name to say hello to", required=True)],
    on_build="""  # Optimizes build by cache to reduce execution time
curl -LsSf https://astral.sh/uv/install.sh | sh > /dev/null 2>&1
. $HOME/.cargo/env

uv venv > /dev/null 2>&1
. .venv/bin/activate > /dev/null 2>&1

if [ -f /tmp/requirements.txt ]; then
    uv pip install -r /tmp/requirements.txt > /dev/null 2>&1
fi
""",
    content="""
python /tmp/main.py "{{ .name }}"
""",
    with_files=[
        FileSpec(
            destination="/tmp/main.py",
            content=inspect.getsource(main),
        ),
        # Add any requirements here if needed
        # FileSpec(
        #     destination="/tmp/requirements.txt",
        #     content="",
        # ),
    ],
)

Contributing

We welcome contributions to the Kubiya SDK! Please refer to our Contributing Guidelines for more information on how to get started.

License

Kubiya SDK is released under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kubiya_sdk-0.1.13.tar.gz (60.3 kB view details)

Uploaded Source

Built Distribution

kubiya_sdk-0.1.13-py3-none-any.whl (41.7 kB view details)

Uploaded Python 3

File details

Details for the file kubiya_sdk-0.1.13.tar.gz.

File metadata

  • Download URL: kubiya_sdk-0.1.13.tar.gz
  • Upload date:
  • Size: 60.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.4.28

File hashes

Hashes for kubiya_sdk-0.1.13.tar.gz
Algorithm Hash digest
SHA256 7dcc00bd1bdd22d74f9c534ce14b3c396020ee86aac9f32856ed31813db3a751
MD5 88730fe0ae93f29c67349cd221c28626
BLAKE2b-256 e04cf40e5bf8bfe6d66968315461f02a34357cccb1f46cc438846d6be8770249

See more details on using hashes here.

File details

Details for the file kubiya_sdk-0.1.13-py3-none-any.whl.

File metadata

File hashes

Hashes for kubiya_sdk-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 a008461e4d7ce08cfe90d89c2e81dacf327221ba752cbec7dc670abfbe05ea4c
MD5 2073c8916cdc42013518d9f1244c80aa
BLAKE2b-256 ec2f68095208e6c1a5d421140b6bd17170e4d58890aefeefe2e3b54a475da2fe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page