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

# Exporting Annotations

You can make use of RedBrick AI's Python SDK to export your annotations using a Python script.&#x20;

Within the Python SDK, annotations are exported in two ways:&#x20;

1. The `export_tasks` function **returns a Python object** containing metadata information and any vector annotations (measurements, landmarks, etc.). Please see the [format of the object here](https://docs.redbrickai.com/python-sdk/reference/export-annotation-format).&#x20;
2. By default, segmentation data is written to your disk **in NIfTI format**. Segmentation data can also be exported in PNG or RT Struct by manipulating the parameters of the `export_tasks` function. Please view the detailed [`export_tasks` reference here](https://sdk.redbrickai.com/sdk.html#redbrick.export.Export.export_tasks).&#x20;

<Note>
  If you're attempting a one-time export or don't have intensive requirements for your export, the
  [**CLI** ](https://docs.redbrickai.com/python-sdk/cli-overview/exporting-annotations)also provides
  a simple and optimized workflow for exporting a Project's annotations.&#x20;
</Note>

## Export Folder Structure

RedBrick AI exports annotations in a JSON structure, accompanied by [NIfTI-1 masks](https://nifti.nimh.nih.gov/nifti-1/) for segmentations. All data will be exported within a folder named after your `project_id`, with the following structure:

```
project_id/
├── segmentations
│   ├── study01
│   │   └── series1.nii
│   └── study02
│       ├── series1.nii
│       └── series2.nii
└── tasks.json
```

<Check>
  The above structure is for a standard export (i.e. not semantic, not binary mask, etc.) and
  assumes no [overlapping
  segmentations](/annotation-and-viewer/segmentation/overlapping-segmentations#exporting-overlapping-segmentations).&#x20;
</Check>

### Segmentations Subdirectory

The segmentation directory will contain a single sub-directory for each task in your export. The sub-directories will be named after the task [`name`](./exporting-annotations#name-string). A single task (depending on whether it was single series or multi-series) can have one or more segmentations.

The individual segmentation files will be in NIfTI-1 format and be [named after the user-defined series name](./exporting-annotations#name-string-1). If no series name is provided on upload, RedBrick will assign a unique name. Corresponding metadata, e.g. category names, will be provided in [tasks.json](./exporting-annotations#tasks-json).

***

## Code Examples

As always, you should first perform the [standard RedBrick AI SDK setup](./#initializing-the-redbrick-sdk-in-python) to create a Project object.

```python theme={null}
project = redbrick.get_project(org_id, project_id, api_key)
```

With a new Project object created, you can export your Project's Tasks in various ways. Please see some common examples below.

#### Export All Tasks

The `export_tasks()` function exports segmentation files for all Ground Truth Tasks by default. To export All Tasks, set the `only_ground_truth` parameter to `False`.

```python theme={null}
annotations = project.export.export_tasks(only_ground_truth=False)
```

#### Export Only Ground Truth

You can export only the Tasks in Ground Truth, i.e., Tasks that have successfully made it through all Label and Review Stages.&#x20;

```python theme={null}
gt_annotations = project.export.export_tasks(only_ground_truth=True)
```

#### **Export Specific Tasks**

Export selected Tasks by specifying Task IDs.&#x20;

```python theme={null}
specific_annotations = project.export.export_tasks(task_id="...")
```

***

## Generate an Audit Trail

An audit trail can be useful for regulators interested in your quality control processes, as well as for managing your internal QA processes.&#x20;

<Check>
  Please see a detailed reference for [`get_task_events`
  here](https://sdk.redbrickai.com/sdk.html#redbrick.export.Export.get_task_events).
</Check>

First, perform the [standard RedBrick AI SDK setup](./#initializing-the-redbrick-sdk-in-python) to create a Project object.&#x20;

#### Audit Trail - All Tasks

If you'd like to generate an audit trail for **all Tasks** (not only those in the Ground Truth Stage), be sure to include the `only_ground_truth=False` parameter.

```python theme={null}
---
title: Return an audit trail for all Tasks in all Stages
---
audit_trail = project.export.get_task_events(only_ground_truth=False)
```

#### Audit Trail - Ground Truth Tasks Only

Retrieve an audit trail for all Ground Truth Tasks**.** Please note that by default, `get_task_events` only returns audit information for Tasks in the Ground Truth Stage.&#x20;

```python theme={null}
project = redbrick.get_project(org_id, project_id, api_key)

---
title: Return an audit trail for all Tasks currently in the Ground Truth Stage
---
audit_trail = project.export.get_task_events()
```

The returned object will contain data similar to the code snippet below, where each entry will represent a single Task (uniquely identified by `taskId`). The `events` array contains all key events/actions performed on the Task, with `events[0]` being the first event.

```json theme={null}
[
  {
    "taskId": "...",
    "currentStageName": "Label",
    "events": [
      {
        "eventType": "TASK_CREATED",
        "createdAt": "...",
        "isGroundTruth": false,
        "createdBy": "..."
      },
      {
        "eventType": "TASK_ASSIGNED",
        "createdAt": "...",
        "assignee": "...",
        "stage": "Label"
      }
    ]
  }
]
```

## Advisory for Conda Environments

Conda environments often do not have the correct SSL credentials necessary to complete an export. As a result, exports may fail silently or fail to download segmentation masks.

If you are using Conda and experience issues with your exports, we advise pasting the following code immediately after your import statements:

```python theme={null}

redbrick.config.verify_ssl = False

# rest of your Python script
```

If the above does not resolve your problem, please reach out to us at [support@redbrickai.com](mailto:support@redbrickai.com).

***

## Additional Capabilities

The following is a non-exhaustive list of other available functionalities when using the [`Export` class](https://sdk.redbrickai.com/sdk.html#export). A full list of the capabilities of our `Export` class can be found [here](https://sdk.redbrickai.com/sdk.html#redbrick.export.Export).

* Track labeler or reviewer time spent on a Task with [`get_active_time()`](https://sdk.redbrickai.com/sdk.html#redbrick.export.Export.get_active_time);
* Fetch Task events from a specific timestamp to the present day using [`get_task_events()`](https://sdk.redbrickai.com/sdk.html#redbrick.export.Export.get_task_events) and the `from_timestamp` parameter;
* Easily search for Tasks based on a wide variety of criteria using [`list_tasks()`](https://sdk.redbrickai.com/sdk.html#redbrick.export.Export.list_tasks);
* Perform a semantic export (that exports a single file per category name) using [`export_tasks()`](https://sdk.redbrickai.com/sdk.html#redbrick.export.Export.export_tasks);
* Configure [Hanging Protocol](https://sdk.redbrickai.com/sdk.html#redbrick.settings.Settings.hanging_protocol)s;
* Upload a [script](https://sdk.redbrickai.com/sdk.html#redbrick.settings.Settings.label_validation) for [Custom Label Validation](../../project-pages/settings-page/custom-label-validation);
