Skip to content

Rapidata order

RapidataOrder #

RapidataOrder(
    name: str,
    order_id: str,
    openapi_service: OpenAPIService,
    dataset: Optional[RapidataDataset] = None,
)

An instance of a Rapidata order.

Used to interact with a specific order in the Rapidata system. Such as starting, pausing, and getting the results of the order.

Parameters:

Name Type Description Default
name str

The name of the order.

required
order_id str

The ID of the order.

required
openapi_service OpenAPIService

The OpenAPIService instance used to interact with the Rapidata API.

required
dataset Optional[RapidataDataset]

The optional Dataset associated with the order.

None
Source code in src/rapidata/rapidata_client/order/rapidata_order.py
def __init__(
    self,
    name: str,
    order_id: str,
    openapi_service: OpenAPIService,
    dataset: Optional[RapidataDataset]=None,
):
    self.order_id = order_id
    self.name = name
    self.__openapi_service = openapi_service
    self.__dataset = dataset
    self.__workflow_id = None

dataset property #

dataset: RapidataDataset | None

The dataset associated with the order. Returns: The RapidataDataset instance.

run #

run(print_link: bool = True)

Runs the order for to start collecting votes.

Source code in src/rapidata/rapidata_client/order/rapidata_order.py
def run(self, print_link: bool=True):
    """
    Runs the order for to start collecting votes.
    """
    self.__openapi_service.order_api.order_submit_post(self.order_id)

    if print_link:
        print(f"Order '{self.name}' is now viewable under: https://app.{self.__openapi_service.enviroment}/order/detail/{self.order_id}")

    return self

pause #

pause()

Pauses the order.

Source code in src/rapidata/rapidata_client/order/rapidata_order.py
def pause(self):
    """
    Pauses the order.
    """
    self.__openapi_service.order_api.order_pause_post(self.order_id)
    print(f"Order '{self}' has been paused.")

get_status #

get_status() -> str

Gets the status of the order.

Returns:

Type Description
str

The status of the order.

Source code in src/rapidata/rapidata_client/order/rapidata_order.py
def get_status(self) -> str:
    """
    Gets the status of the order.

    Returns: 
        The status of the order.
    """
    return self.__openapi_service.order_api.order_get_by_id_get(self.order_id).state

display_progress_bar #

display_progress_bar(refresh_rate: int = 5)

Displays a progress bar for the order processing using tqdm.

Parameters:

Name Type Description Default
refresh_rate int

How often to refresh the progress bar, in seconds.

5
Source code in src/rapidata/rapidata_client/order/rapidata_order.py
def display_progress_bar(self, refresh_rate: int=5):
    """
    Displays a progress bar for the order processing using tqdm.

    Args: 
        refresh_rate: How often to refresh the progress bar, in seconds.
    """
    if refresh_rate < 1:
        raise ValueError("refresh_rate must be at least 1")

    with tqdm(total=100, desc="Processing order", unit="%", bar_format="{desc}: {percentage:3.0f}%|{bar}| completed [{elapsed}<{remaining}, {rate_fmt}]") as pbar:
        last_percentage = 0
        while True:
            current_percentage = self.__get_workflow_progress().completion_percentage
            if current_percentage > last_percentage:
                pbar.update(current_percentage - last_percentage)
                last_percentage = current_percentage

            if current_percentage >= 100:
                break

            sleep(refresh_rate)

get_results #

get_results() -> dict[str, Any]

Gets the results of the order. If the order is still processing, this method will block until the order is completed and then return the results.

Returns:

Type Description
dict[str, Any]

The results of the order.

Source code in src/rapidata/rapidata_client/order/rapidata_order.py
def get_results(self) -> dict[str, Any]:
    """
    Gets the results of the order. 
    If the order is still processing, this method will block until the order is completed and then return the results.

    Returns: 
        The results of the order.
    """
    while self.get_status() not in ["Completed", "Paused", "ManuelReview", "Failed"]:
        sleep(5)

    try:
        # Get the raw result string
        result_str = self.__openapi_service.order_api.order_result_get(id=self.order_id)
        # Parse the result string as JSON
        return json.loads(result_str)
    except ApiException as e:
        # Handle API exceptions
        raise Exception(f"Failed to get order results: {str(e)}") from e
    except json.JSONDecodeError as e:
        # Handle JSON parsing errors
        raise Exception(f"Failed to parse order results: {str(e)}") from e