> ## Documentation Index
> Fetch the complete documentation index at: https://docs.labelbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Task objects

> Summary of task objects

[`Task`](https://labelbox-python.readthedocs.io/en/latest/task.html) objects represent operations you performed using the SDK or the UI, such as importing and exporting annotations. The `Task` object can make your workflow synchronous, especially for longer operations.

`DataUpsertTask` is a subclass of `Task` that represents data row upsert operations.

## Methods

The main method associated with a task object is `wait_till_done`, which waits until the task is completed by periodically querying the server to update the task attributes. This method takes two parameters:

1. `timeout_seconds`: Represents the maximum time `wait_till_done` can block your code. The default value is five minutes, which should be increased for longer tasks.
2. `check_frequency`: Defines how often your task queries the server to update the task attributes, which defaults to two seconds. This is useful to limit the amount of API calls against our server in a given time frame.

<CodeGroup>
  ```python Python theme={null}
  dataset = client.get_dataset("<dataset id>")

  task = dataset.create_data_rows([{
    "row_data": item_url,
    "global_key": "<unique_global_key>"
  }])
  task.wait_till_done(timeout_seconds=5_000, check_frequency=10)
  ```
</CodeGroup>

### Task Results

The task result is a collection of details, typically information on the data rows associated with the task.

<CodeGroup>
  ```python Python theme={null}
  dataset = client.get_dataset("<dataset id>")

  task = dataset.create_data_rows([{
    "row_data": item_url,
    "global_key": "<unique_global_key>"
  }])
  task.wait_till_done()

  print(task.result) # prints the data rows associated with the create_data_rows operation
  ```
</CodeGroup>

<Warning>
  ### Warning

  Large results (over 150,000 data rows) can take up to 10 mins to process.
</Warning>

### Task Errors

The task errors work similarly to the task results but contain information on any associated errors.

<CodeGroup>
  ```python errors theme={null}
  dataset = client.get_dataset("<dataset id>")

  task = dataset.create_data_rows([{
    "row_data": item_url,
    "global_key": "<unique_global_key>"
  }])
  task.wait_till_done()

  print(task.errors) # prints the data rows associated with the create_data_rows operation
  ```
</CodeGroup>

## Get tasks

You can view tasks created in the past 30 days in the UI on the [Notifications](https://app.labelbox.com/notifications) page. You can also fetch a specific task by its ID using `client.get_task_by_id()`.

To retrieve tasks programmatically, you can query all tasks in an organization or filter them by status using the `where` parameter on `organization.tasks`. Task statuses are exposed via `Task.status_as_enum`.

Valid statuses are:

* `TaskStatus.In_Progress`
* `TaskStatus.Complete`
* `TaskStatus.Canceling`
* `TaskStatus.Canceled`
* `TaskStatus.Failed`

<CodeGroup>
  ```python Get task by ID theme={null}
  id = "" # Your task ID string
  client.get_task_by_id(id)
  ```

  ```python Get tasks by status theme={null}
  # All tasks
  tasks = organization.tasks()

  # Tasks in progress
  org_tasks_in_progress = organization.tasks(
      where=Task.status_as_enum == TaskStatus.In_Progress
  )

  # Failed tasks
  org_task_failed = organization.tasks(
      where=Task.status_as_enum == TaskStatus.Failed
  )
  ```
</CodeGroup>

<Warning>
  ### Export tasks are not supported

  Currently, you can't retrieve export tasks using this method.
</Warning>

## Cancel tasks

You can cancel the following types of tasks before they complete using their task id strings:

* [Streamable export tasks](/reference/export-overview#cancel-export-tasks)
* [Sending to annotate](/reference/foundry-app-developer-guide#step-7-send-annotations-from-catalog-to-annotate)
* [Sending to experiment](/reference/model#add-data-rows-to-a-model-run)
* Bulk-updating queue priority
* Classification creation
* Agreement backfill for benchmark and consensus

<CodeGroup>
  ```python Python theme={null}
  # Cancel the task before it completes
  success = client.cancel_task(id)
  assert success is True

  # Verify the task was cancelled
  cancelled_task = client.get_task_by_id(id)
  assert cancelled_task.status in ["CANCELING", "CANCELED"]
  ```
</CodeGroup>
