# import\_labels

`imerit_ango.sdk.SDK.`

## import\_labels(project\_id, labels)

Import pre-labels into existing project tasks.

{% hint style="danger" %}
You can only import annotations for tasks in the *Start* stage.

Please ensure the assets you are trying to annotate as in the *Start* stage of your project before continuing.
{% endhint %}

### Parameters

* **project\_id:** string
  * The unique identifier for the project. You can find the project ID in [the user interface](/sdk/sdk-documentation.md#project-ids) or retrieve it using the [`list_projects`](/sdk/sdk-documentation/project-level-sdk-functions/list_projects.md) function.
* **labels:** List\[dict]
  * List of labels to import. See more on our label format here: [Ango Annotation Format](/data/importing-and-exporting-annotations/importing-annotations/ango-import-format.md) and learn more about importing labels into Ango Hub [here](/data/importing-and-exporting-annotations/importing-annotations.md).

<details>

<summary>Example</summary>

```json
[
    {
        "externalId": "example.png",
        "objects": [
            {
                "schemaId": "09f90db83b842d7bf0c2225",
                "bounding-box": {
                    "x": 192,
                    "y": 166,
                    "width": 66,
                    "height": 61
                }
            },
            {
                "schemaId": "09f90db83b842d7bf0c2225",
                "bounding-box": {
                    "x": 56,
                    "y": 56,
                    "width": 67,
                    "height": 44
                }
            }
        ]
    }
]
```

</details>

Returns:

* **output:** dict
  * A dictionary containing the result of the operation.
  * Including a `status` field indicating whether the request was successful and a `data` field containing the response payload with updated resources produced by the operation.

{% hint style="warning" %}
When using the `import_labels` function, all existing annotations on the target task are overwritten by the imported annotations. Existing annotation data cannot be recovered after the operation.
{% endhint %}

<details open>

<summary><strong>How to verify in Ango Hub?</strong></summary>

After successfully executing the `import_labels` function, you can validate the changes directly in Ango Hub.

Navigate to: **Projects → \[Your Project] → Settings → Assets**

* Filter assets using their External ID.
* Confirm that the selected assets are pre-labeled correctly.

{% hint style="info" %}
Changes made via the SDK are reflected in Ango Hub in near real-time. If updates are not immediately visible, please refresh the page.
{% endhint %}

</details>

### Example

Import Bounding Box

{% tabs %}
{% tab title="python" %}

```python
import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK

load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')

ango_sdk = SDK(api_key)

schema_id = "8b9eacf582ebcf2f04fb832"

annotations = [
    {
        "externalId": "example.png",
        "objects": [
            {
                "schemaId": schema_id,
                "title": "Sample",
                "bounding-box": {
                    "x": 20,
                    "y": 30,
                    "width": 50,
                    "height": 60,
                },
            }
        ],
    }
]

ango_sdk.import_labels(project_id=project_id, labels=annotations)
```

{% endtab %}

{% tab title="curl" %}

```bash
curl -X POST "https://imeritapi.ango.ai/v2/import/labels" \
  -H "Content-Type: application/json" \
  -H "apikey: $ANGO_API_KEY" \
  -d '{
    "jsonContent": [
      {
        "externalId": "example.png",
        "objects": [
          {
            "bounding-box": {
              "height": 60,
              "width": 50,
              "x": 20,
              "y": 30
            },
            "schemaId": "8b9eacf582ebcf2f04fb832",
            "title": "Sample"
          }
        ]
      }
    ],
    "project": "$PROJECT_ID"
  }'
```

{% endtab %}
{% endtabs %}

<details>

<summary>Sample Category Schema</summary>

```json
{
  "tools": [
    {
      "schemaId": "8b9eacf582ebcf2f04fb832",
      "tool": "bounding-box",
      "title": "Sample",
      "required": false,
      "classifications": [],
      "multiple": false,
      "color": "#f44336",
      "shortcutKey": "1",
      "ocrEnabled": false
    }
  ],
  "classifications": [],
  "relations": []
}
```

</details>

Import Brush

{% tabs %}
{% tab title="python" %}

```python
import os
import numpy as np
from dotenv import load_dotenv
from imerit_ango.sdk import SDK

load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')

ango_sdk = SDK(api_key)

external_id = "example.png"
schema_id = "41be4ae7b3ddad31b1c4650"

height, width = 512, 512
brush_mask = np.full((height, width, 4), [255, 255, 255, 0], dtype=np.uint8) # background pixels
brush_mask[100:500, 100:500, :] = [50, 15, 46, 255] # foreground pixels

brush_url = ango_sdk.upload_brush_array(project_id=project_id, arr=brush_mask, medical=False)

annotations = [{"externalId": external_id, "brushDataUrl": brush_url, "objects": [{"brush": [50, 15, 46], "schemaId": schema_id}]}]

ango_sdk.import_labels(project_id, annotations)
```

{% endtab %}
{% endtabs %}

<details>

<summary>Sample Category Schema</summary>

```json
{
  "tools": [
    {
      "schemaId": "41be4ae7b3ddad31b1c4650",
      "tool": "brush",
      "title": "Sample",
      "required": false,
      "classifications": [],
      "multiple": false,
      "color": "#f44336",
      "shortcutKey": "1"
    }
  ],
  "classifications": [],
  "relations": []
}
```

</details>

Import Medical Brush

{% tabs %}
{% tab title="python" %}

```python
import os
import numpy as np
from dotenv import load_dotenv
from imerit_ango.sdk import SDK

load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')

ango_sdk = SDK(api_key)

external_id = "example.nrrd"
schema_id = 1

Z, Y, X = 512, 512, 512
volume = np.zeros((Z, Y, X), dtype=np.uint8)
volume[10:50, 10:100, 10:100] = schema_id

medical_brush_url = ango_sdk.upload_brush_array(project_id=project_id, arr=volume, medical=True)

annotations = [{"externalId": external_id, "medicalBrushDataUrl": medical_brush_url}]

ango_sdk.import_labels(project_id, annotations)
```

{% endtab %}
{% endtabs %}

<details>

<summary>Sample Category Schema</summary>

```json
{
  "tools": [
    {
      "schemaId": "1",
      "tool": "medical-brush",
      "title": "Sample",
      "required": false,
      "classifications": [],
      "multiple": false,
      "color": "#f44336",
      "shortcutKey": "1"
    }
  ],
  "classifications": [],
  "relations": []
}
```

</details>

{% hint style="info" %}
**See also**

[Ango Import Format](/data/importing-and-exporting-annotations/importing-annotations/ango-import-format.md)
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.imerit.net/sdk/sdk-documentation/project-level-sdk-functions/import_labels.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
