Skip to content

Runner API

api_create_runner(name, endpoints, description='', progress_callback_func=None)

Creates a new runner.

This function takes the name, endpoints, and an optional progress callback function to create a new Runner instance. The id of the runner is generated from the name of the runner using the slugify function, so it does not need to be provided.

Parameters:

Name Type Description Default
name str

The name of the runner.

required
endpoints list[str]

A list of endpoint identifiers for the runner.

required
description str

A brief description of the runner. Defaults to an empty string.

''
progress_callback_func Callable | None

An optional callback function for progress updates.

None

Returns:

Name Type Description
Runner Runner

A new Runner object.

Source code in moonshot/src/api/api_runner.py
@validate_call
def api_create_runner(
    name: str,
    endpoints: list[str],
    description: str = "",
    progress_callback_func: Callable | None = None,
) -> Runner:
    """
    Creates a new runner.

    This function takes the name, endpoints, and an optional progress callback function to create a new Runner instance.
    The id of the runner is generated from the name of the runner using the slugify function,
    so it does not need to be provided.

    Args:
        name (str): The name of the runner.
        endpoints (list[str]): A list of endpoint identifiers for the runner.
        description (str, optional): A brief description of the runner. Defaults to an empty string.
        progress_callback_func (Callable | None, optional): An optional callback function for progress updates.
        Defaults to None.

    Returns:
        Runner: A new Runner object.
    """
    # Create a new recipe runner
    # We do not need to provide the id.
    # This is because during creating:
    # 1. the id is slugify from the name and stored as id.
    runner_args = RunnerArguments(
        id="",
        name=name,
        endpoints=endpoints,
        description=description,
        progress_callback_func=progress_callback_func,
    )
    return Runner.create(runner_args)

api_delete_runner(runner_id)

Deletes a runner by its identifier.

This function takes a runner ID as input and calls the delete method from the Runner class to remove the specified runner from storage.

Parameters:

Name Type Description Default
runner_id str

The unique identifier of the runner to be deleted.

required

Returns:

Name Type Description
bool bool

True if the runner was successfully deleted.

Raises:

Type Description
Exception

If the deletion process encounters an error.

Source code in moonshot/src/api/api_runner.py
@validate_call
def api_delete_runner(runner_id: str) -> bool:
    """
    Deletes a runner by its identifier.

    This function takes a runner ID as input and calls the delete method from the Runner class
    to remove the specified runner from storage.

    Args:
        runner_id (str): The unique identifier of the runner to be deleted.

    Returns:
        bool: True if the runner was successfully deleted.

    Raises:
        Exception: If the deletion process encounters an error.
    """
    return Runner.delete(runner_id)

api_get_all_runner()

Retrieves all available runners.

This function calls the get_available_items method to retrieve all available runners. It then converts each runner into a dictionary using the to_dict method and returns a list of these dictionaries.

Returns:

Type Description
list[dict]

list[dict]: A list of dictionaries, each representing a runner.

Source code in moonshot/src/api/api_runner.py
def api_get_all_runner() -> list[dict]:
    """
    Retrieves all available runners.

    This function calls the get_available_items method to retrieve all available runners. It then converts each
    runner into a dictionary using the to_dict method and returns a list of these dictionaries.

    Returns:
        list[dict]: A list of dictionaries, each representing a runner.
    """
    _, runners = Runner.get_available_items()
    return [runner.to_dict() for runner in runners]

api_get_all_runner_name()

Retrieves all available runner names.

This function calls the get_available_items method to retrieve all available runners. It then extracts the names of each runner and returns a list of these names.

Returns:

Type Description
list[str]

list[str]: A list of runner names.

Source code in moonshot/src/api/api_runner.py
def api_get_all_runner_name() -> list[str]:
    """
    Retrieves all available runner names.

    This function calls the get_available_items method to retrieve all available runners. It then extracts the names of
    each runner and returns a list of these names.

    Returns:
        list[str]: A list of runner names.
    """
    runners_names, _ = Runner.get_available_items()
    return runners_names

api_load_runner(runner_id, progress_callback_func=None)

Loads a runner based on the provided runner ID.

This function retrieves the runner using the provided runner ID and then loads it. It utilizes the Runner's load method to fetch and return the runner.

Parameters:

Name Type Description Default
runner_id str

The ID of the runner to be loaded.

required
progress_callback_func Callable | None

The progress callback function to be used by the runner.

None

Returns:

Name Type Description
Runner Runner

An initialized Runner object.

Source code in moonshot/src/api/api_runner.py
@validate_call
def api_load_runner(
    runner_id: str, progress_callback_func: Callable | None = None
) -> Runner:
    """
    Loads a runner based on the provided runner ID.

    This function retrieves the runner using the provided runner ID and then loads it.
    It utilizes the Runner's load method to fetch and return the runner.

    Args:
        runner_id (str): The ID of the runner to be loaded.
        progress_callback_func (Callable | None): The progress callback function to be used by the runner.

    Returns:
        Runner: An initialized Runner object.
    """
    return Runner.load(runner_id, progress_callback_func)

api_read_runner(runner_id)

Reads a runner and returns its information.

This function takes a runner ID as input, reads the corresponding runner, and returns a dictionary containing the runner's information.

Parameters:

Name Type Description Default
runner_id str

The ID of the runner.

required

Returns:

Name Type Description
dict dict

A dictionary containing the runner's information.

Source code in moonshot/src/api/api_runner.py
@validate_call
def api_read_runner(runner_id: str) -> dict:
    """
    Reads a runner and returns its information.

    This function takes a runner ID as input, reads the corresponding runner,
    and returns a dictionary containing the runner's information.

    Args:
        runner_id (str): The ID of the runner.

    Returns:
        dict: A dictionary containing the runner's information.
    """
    return Runner.read(runner_id).to_dict()