Follow our quickstart guide below or use an interactive notebook.

Installation

To connect to your Kolena Agents using Python, install the kolena-agents client from PyPI using any Python package manager such as pip or poetry:
pip install kolena-agents

Initialization

An API Key is required to use the python client. Generate a key from your user profile within the web UI. Copy the created key and store in a KOLENA_API_KEY environment variable:
export KOLENA_API_KEY="your-api-key"

Usage

Here’s an example of how to use the client to add, download and delete agent runs:
from kolena_agents import Client

client = Client()

# add new agent run
new_run = client.agent_run.add(agent_id=1, files=["path/to/file1", "path/to/file2"])

# download agent run
run = client.agent_run.get(agent_id=1, run_id=2)

# alternatively, list all agent runs
all_runs = client.agent_run.list(agent_id=1)

# delete agent run
client.agent_run.delete(agent_id=1, run_id=2)

# list all agents
all_agents = client.agent.list()

# get an agent
agent = client.agent.get(agent_id=1)

Serializing to JSON

All kolena-agents objects are standard Pydantic data objects and can be easily converted to and from JSON:
from kolena_agents import Client
from kolena_agents.types.agent_run import AgentRun

client = Client()
run = client.agent_run.get(agent_id=1, run_id=2)

run_dict = run.model_dump(mode="json")  # get the AgentRun as a dictionary
run = AgentRun.model_validate(run_dict)  # deserialize an AgentRun

Webhook

Kolena provides a helper function to handle signature verification and parsing. See Webhook Connection for more information.
from kolena_agents import webhook

result = webhook.construct_event(request_body, secret, request_headers)

Supported Python Versions

Python versions 3.8 and later are supported.