Skip to content

Rapidata order

RapidataOrder #

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

Represents a Rapidata order.

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

dataset property #

dataset: RapidataDataset | None

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

submit #

submit()

Submits the order for processing.

Source code in src/rapidata/rapidata_client/order/rapidata_order.py
def submit(self):
    """
    Submits the order for processing.
    """
    self.openapi_service.order_api.order_submit_post(self.order_id)

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=5)

Displays a progress bar for the order processing using tqdm.

Prameter

How often to refresh the progress bar, in seconds.

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

    Prameter: 
        How often to refresh the progress bar, in seconds.
    """
    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