Skip to content

Open In Colab

How to export a Kili project


This tutorial explains the multiple ways to export a Kili project. It describes:

  • Methods to export the labels one by one, after filtering
  • The solutions for performing a full-project export

The methods are illustrated with code snippets.

Export methods

With Kili, once you have annotated enough assets, you can export the data programmatically to train a machine learning algorithm with it. There are several ways to do it:

  • Fetch the assets and/or the labels one by one using .assets or .labels, perform the data transformation yourself and then write the data to one or several output files.
  • Export the whole project as a dataset. To do that, use the .export_labels method that creates an archive containing the labels in your chosen format.

Preliminary steps

1) Fetch the project ID from the Kili UI (in Settings / Admin):


2) Ensure that your Kili API key has been set as an environment variable:


3) If Kili has not been installed yet, install Kili.

!pip install --upgrade kili

4) Import packages and instantiate Kili:

from kili.client import Kili
from pathlib import Path

kili = Kili()

Exporting assets and labels one by one

To retrieve all assets of a project one by one, perform the following steps:

Exporting the latest labels per asset

First, fetch the assets:

assets = kili.assets(your_project_id, fields=["externalId", "latestLabel.jsonResponse"])

Now if you print an asset, you will see that you can access its latestLabel:

{'latestLabel': {'jsonResponse': {'JOB_0': {'annotations': [{'categories': [{'name': 'OBJECT_A'}], 'mid': '20230111125258113-44528', 'type': 'rectangle', 'boundingPoly': [{'normalizedVertices': [{'x': 0.6101435505380516, 'y': 0.7689773770786136}, {'x': 0.6101435505380516, 'y': 0.39426226491370664}, {'x': 0.8962087421313937, 'y': 0.39426226491370664}, {'x': 0.8962087421313937, 'y': 0.7689773770786136}]}], 'polyline': [], 'children': {}}]}}}, 'externalId': 'car_1'}

You can now get your label, and write the category name into a text file for example:

for asset in assets:
    if asset["latestLabel"]:  # check if asset has annotations
        class_ = asset["latestLabel"]["jsonResponse"]["JOB_0"]["annotations"][0]["categories"][0][
        with Path(asset["externalId"] + ".txt").open("w", encoding="utf-8") as f:

Filtering specific labels per asset through the method filters

You can specify label filters directly in the .assets and the .labels methods. The available filters are listed in the arguments list for each one of these methods.

When done, you can write the conversion code to get the data in the format that you need.

Get only the assets with a consensus mark above 0.5:

assets = kili.assets(
    your_project_id, fields=["externalId", "id", "consensusMark"], consensus_mark_gt=0.5
# + asset conversion code
[{'externalId': 'car_1', 'id': 'clcyuykzd0000bgvze2z3wk81', 'consensusMark': 0.6504290982818591}]

Get all the labels with a honeypot mark above 0.1:

labels = kili.labels(
    fields=["labelOf.externalId", "honeypotMark", "", "id"],
# + label conversion code
[{'labelOf': {'externalId': 'car_1'}, 'author': {'email': ''}, 'honeypotMark': 0.16527040499137607, 'id': 'clcyuynri2fnl0krf0d7pgabo'}, {'labelOf': {'externalId': 'car_1'}, 'author': {'email': ''}, 'honeypotMark': 0.20754115450190522, 'id': 'clcyuynri2fnm0krfhx934jee'}]

Get all the labels added by a specific project member:

labels = kili.labels(
    your_project_id, fields=["labelOf.externalId", "", "id"], user_id=john_doe_id
# + label conversion code
[{'labelOf': {'externalId': 'car_1'}, 'author': {'email': ''}, 'id': 'clcyuynri2fnl0krf0d7pgabo'}]

This code will return a list of labels authored by John Doe.

You can also use the author_in parameter to filter by name directly.

Filtering specific labels per asset through the label properties

You can also look for specific labels, for example the last "review" status label per user, and dump the result into a json file. You can use the field "labels.isLatestReviewLabelForUser" to check if the label is the latest per user.

import json

assets = kili.assets(
    fields=["externalId", "labels.jsonResponse", "labels.isLatestReviewLabelForUser"],

for asset in assets:
    if asset["labels"]:  # check if asset has annotations
        for label in asset["labels"]:
            if label["isLatestReviewLabelForUser"] and "JOB_0" in label["jsonResponse"]:
                annotation = label["jsonResponse"]["JOB_0"]
                with Path(asset["externalId"] + ".json").open("w", encoding="utf-8") as f:
                break  # once we find a latest label done by a reviewer, we move on to the next asset.

Filtering the latest label per annotator

When working on a project with consensus enabled, it can be useful to export the latest label made by each annotator:

from collections import defaultdict

assets = kili.assets(

for asset in assets:
    if asset["labels"]:
        latest_label_by_user = defaultdict(list)
        for label in asset["labels"]:
            if label["labelType"] == "DEFAULT":
        latest_label_per_user = {
            email: max(labels, key=lambda x: x["createdAt"])
            for email, labels in latest_label_by_user.items()
        with (Path("/tmp") / (asset["externalId"] + ".json")).open("w", encoding="utf-8") as f:

Exporting a whole project

Kili has a method to export the whole project into specific export formats. It can be useful when your goal is to use one of the standard output formats.

Available formats

Format UI Python Client Command Line Interface
Kili (raw)
Kili (simple)
Pascal VOC

The .export_labels method

The .export_labels method enables the export of a full project. It does the following preprocessing:

  • Only fetches the labels of types "DEFAULT" and "REVIEW" (see the label types explanations).
  • If specified, selects a subset of asset ids.
  • Exports labels to one of the standard formats (only available for a restricted set of ML tasks).
  • Using various method arguments, you can decide:
    • Whether or not to include the assets in the export
    • Whether to export just the latest label or all the labels
    • Whether to create one folder for all the jobs or one folder per job
    • Whether or not to export the label-related data into one single file

Note that some formats are by default single-file, while others use many files:

Format Single file Multiple files
Pascal VOC

For all the formats, in the output archive, a README.kili.txt file is also created. Here is an example of its contents:

Exported Labels from KILI

- Project name: Awesome annotation project
- Project identifier: abcdefghijklmnop
- Project description: This project contains labels, most of which are awesome.
- Export date: 20221125-093324
- Exported format: kili
- Exported labels: latest

Kili format, one file per asset

The following code snippet exports the whole asset payload and the associated labels, with one json file per asset, into the /tmp/ folder.

Fetching assets...

Kili format, one file for the whole project

This code snippet exports the whole asset payload and the associated labels as one file for the whole project, into the /tmp/ folder.

Fetching assets...

YOLO formats

When you have at least one Object Detection job with bounding boxes, you can also export to one of the YOLO formats. You can choose "yolo_v4", "yolo_v5" or "yolo_v7". The difference between each format is the structure of the metadata YAML file, which specifies the object classes. In all the cases, one file per asset is produced, containing the last created DEFAULT or REVIEW label. Each YOLO label has the following shape:

2        0.25 0.67 0.26 0.34
^        ^    ^    ^    ^
class    x    y    w    h

  • class is the class index in the classes list contained in the YOLO metadata file.
  • x is the x-coordinate relative to the image width (between 0.0 and 1.0) of the center of the bounding box.
  • y is the y-coordinate relative to the image height (between 0.0 and 1.0) of the center of the bounding box.
  • w is the width relative to the image width (between 0.0 and 1.0) of the bounding box.
  • h is the height relative to the image height (between 0.0 and 1.0) of the bounding box.

Here is an example of a YOLO annotation over an image:


Here is how to export to YOLO (in this example, YOLOv5):

Fetching assets...

Note that a standard YOLO file format must also include:

  • The path root to the assets
  • The train, val and test subfolders

Placing specific data in specific folders is the decision of an ML engineer or a Data scientist, so we are not providing a code snippet here.

COCO format

To export your data into the COCO format, run the following code:

Fetching assets...
Convert to coco format: 1it [00:00, 54.94it/s]

This will create an archive containing both:

  • The COCO annotation file
  • The data/ folder with all the assets


In this tutorial, we have seen several ways to export labels from a Kili project:

  • Using .assets and .labels and their filtering arguments, a subset of assets or labels can be selected and then exported.
  • Using .export_labels, the whole project can be exported into a standard output format.