Labelbox

Data Export

Export the labels in a project

Get the projectId you want to export from.

Run this query

query MyProjects {
  user {
    projects {
      id
      name
    }
  }
}

Using the project ID from the above query you can pull all the labels created in that project.

Run this query

query {
  project(where:{id: "<INSERT_PROJECT_ID_HERE>"}) {
    labels(first: 5){
      id
      label
      createdBy{
        id
        email
      }
      type {
        id
        name
      }
      secondsToLabel
      agreement
      dataRow {
        id
        rowData
      }
    }
  }
}

In order to get all label pages you can use the below code.

import json
from graphqlclient import GraphQLClient
client = GraphQLClient('https://api.labelbox.com/graphql')
client.inject_token('Bearer <API_KEY_HERE>')

def get_page_of_labels(project_id, skip, page_size):
  page_query = '''
    query GetPageOfLabels($projectId: ID!, $skip: Int!, $first: PageSize!) {
      project(where:{id: $projectId}) {
        labels(skip: $skip, first: $first){
          id
          label
          createdBy{
            id
            email
          }
          type {
            id
            name
          }
          secondsToLabel
          agreement
          dataRow {
            id
            rowData
          }
        }
      }
    }
  '''
  res = client.execute(page_query, {'projectId': project_id, 'skip': skip, 'first': page_size})
  data = json.loads(res)['data']
  return data['project']['labels'] or []

def get_all_labels(project_id, skip = 0, page_size = 100, all_labels = []):
  new_labels = get_page_of_labels(project_id, skip, page_size)
  if len(new_labels) == page_size:
    return get_all_labels(project_id, skip + page_size, page_size, all_labels + new_labels)
  else:
    return all_labels + new_labels

project_id = '<PROJECT_ID_HERE>'
all_labels = get_all_labels(project_id)
print(len(all_labels))

Here are some common filter you might want to apply to your export

Run this query

query {
  project(where:{id: "<INSERT_PROJECT_ID_HERE>"}) {
    labels(
      first: 5,
      where: {
        createdBy:{id:"USER_ID"},
        createdAt_lt:"2018-04-24T22:09:21.753Z",
        createdAt_gt:"2018-04-01T22:09:21.753Z",
        type:{id:"TYPE_ID"}, # Skipped vs Submitted
        agreement_gt:0,
        agreement_lt:0.5,
        dataRow:{
          dataset:{
            id:"SOME_DATASET_ID"
          }
        }
      }
    ){
      id
      label
    }
  }
}