Skip to content

Programs

programs

Programs module for interacting with Kaleidoscope programs/experiments.

The service allows users to retrieve all available programs in a workspace and filter programs by specific IDs.

Classes:

Name Description
Program

Data model for a Kaleidoscope program/experiment.

ProgramsService

Service for managing program retrieval operations.

Example
# get all programs in the workspace
programs = client.programs.get_programs()

# get several programs by their ids
filtered = client.programs.get_program_by_ids(['prog1_uuid', 'prog2_uuid'])

Program

Bases: _KaleidoscopeBaseModel

Represents a program in the Kaleidoscope system.

A Program is a base model that contains identifying information about a program, including its title and ID.

Attributes:

Name Type Description
title str

The title/name of the program.

ProgramsService

ProgramsService(client: KaleidoscopeClient)

Service class for managing and retrieving programs (experiments) from Kaleidoscope.

This service provides methods to interact with the programs API endpoint, allowing users to fetch all available programs or filter programs by their IDs.

Example
# get all programs in the workspace
programs = client.programs.get_programs()

# get several programs by their ids
filtered = client.programs.get_program_by_ids(['prog1_uuid', 'prog2_uuid'])

Methods:

Name Description
get_programs

Retrieve all programs (experiments) available in the workspace.

get_programs_by_ids

Retrieve a list of Program objects whose IDs match the provided list.

Source code in kalpy/programs.py
62
63
def __init__(self, client: KaleidoscopeClient):
    self._client = client

get_programs cached

get_programs() -> list[Program]

Retrieve all programs (experiments) available in the workspace.

This method caches its values.

Returns:

Type Description
list[Program]

List[Program]: A list of Program objects representing the experiments in the workspace.

Note

If an exception occurs during the API request, it logs the error, clears the cache, and returns an empty list.

Source code in kalpy/programs.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
@lru_cache
def get_programs(self) -> List[Program]:
    """Retrieve all programs (experiments) available in the workspace.

    This method caches its values.

    Returns:
        List[Program]: A list of Program objects representing the experiments in the workspace.

    Note:
        If an exception occurs during the API request, it logs the error,
        clears the cache, and returns an empty list.
    """
    try:
        resp = self._client._get("/programs")
        return TypeAdapter(List[Program]).validate_python(resp)
    except Exception as e:
        _logger.error(f"Error fetching programs: {e}")
        self.get_programs.cache_clear()
        return []

get_programs_by_ids

get_programs_by_ids(ids: list[str]) -> list[Program]

Retrieve a list of Program objects whose IDs match the provided list.

Parameters:

Name Type Description Default
ids list[str]

A list of program IDs to filter by.

required

Returns:

Type Description
list[Program]

List[Program]: A list of Program instances with IDs found in ids.

Source code in kalpy/programs.py
86
87
88
89
90
91
92
93
94
95
96
def get_programs_by_ids(self, ids: List[str]) -> List[Program]:
    """Retrieve a list of Program objects whose IDs match the provided list.

    Args:
        ids (List[str]): A list of program IDs to filter by.

    Returns:
        List[Program]: A list of Program instances with IDs found in ids.
    """
    programs = self.get_programs()
    return [program for program in programs if program.id in ids]