---
updatedAt: 2025-06-17T21:08:37.000Z
agentTools:
  projectIndex: https://documentation.picsellia.com/llms.txt
---

# Import annotations to dataset

```python Python
from picsellia import Client
from picsellia.types.enums import ImportAnnotationMode, InferenceType


client = Client(
  api_token="YOUR API TOKEN",   # Can be retrieved from your profile on the platform.
	organization_name="YOUR ORGANIZATION NAME" # Default to your organization.
)


# Retrieve Datalake default to you organisation
datalake = client.get_datalake()

filepaths = ["file1.png", "file2.png"]
data = datalake.upload_data(filepaths=filepaths)


# This method creates a dataset placeholder. 
my_dataset = client.create_dataset(
    name="dataset-name",
    description="dataset description",
    private=True)

# Create a version of the dataset 
# The default dataset version is "initial"
my_dataset_version = my_dataset.create_version(version="dataset-version")


# Retrieve the default Datalake associated to the client`s organisation 
# Get data from the Datalake by specifying a list of tags
data = client.get_datalake().list_data(tags=["tag1","tag2"])

# Create a job to add the retrieved data to the dataset version. 
job = my_dataset_version.add_data(data)
# This insures that the job is done asynchronously.
job.wait_for_done()


# Import annotaions in COCO file format.

# The following are the possibilites for the import annotation mode: 
# REPLACE will delete worker annotation if exists and replace it.
# CONCATENATE will create shapes on existing annotation (it checks duplicates).
# SKIP will do nothing on existing annotation.
my_dataset_version.import_annotations_coco_file(
    file_path="path/to/coco/annotations/file.json",
    force_create_label=True, # Ensures labels are created if they don't exist
    mode=ImportAnnotationMode.CONCATENATE # Mode used to import, default is REPLACE.
)

# Import annotations in Pascal VOC file format.
#my_dataset_version.import_annotation_voc_file(
#    file_path="path/to/voc/annotations/file.xml",
#    force_create_label=True)


dataset_version = client.get_dataset(name="dataset-name").get_version(version="dataset-version")
# When the annotations are imported via the sdk, the inferenceType has to be set.
# As an example the InferenceType is set to OBJECT_DETECTION.
# Other possibilties are: CLASSIFICATION, LINE, MULTI, POINT, SEGMENTATION or NOT_CONFIGURED.
dataset_version.set_type(type=InferenceType.OBJECT_DETECTION)


```

```json Response Example
{"success":true}
```

# Initialize Picsellia Client

<!-- python@1-8 -->

Initialize the Client with your API Token, available on your profile page. Check out the organization you want to work with.

# Upload data to Datalake

<!-- python@11-15 -->



# Create a dataset

<!-- python@18-26 -->

Datasets are placeholders for all your DatasetVersions.
DatasetVersions are created from your Datasets and contain data from your Datalake.
Once Data is placed in a DatasetVersion, it becomes an Asset. An Asset can have Annotations attached to it.

To create a Dataset you start by giving a name to your dataset and a version.

# Add data to dataset

<!-- python@29-36 -->

Add data to the dataset from the Datalake.
Data-intensive tasks like adding a lot of data to a DatasetVersion can take time, that's why it's done asynchronously, if you want to be sure that the job is done, just call job.wait_for_done()

# Import annotations to the dataset

<!-- python@39-54 -->

Import annotations to the dataset. 
Annotations file types supported by Picsellia are either COCO or Pascal VOC.

# Set dataset type

<!-- python@57-61 -->

In order to set up the shapes of your labels you need to set the type of the dataset.
The dataset type could possibly be "CLASSIFICATION", "LINE", "MULTI", "POINT", "SEGMENTATION" or "NOT_CONFIGURED".