Global keys

View global key in the UI

To view the global key in the UI, select the data row from Catalog to open the data row detail view. Under Data, you will see Global key.

Filter by global key in the UI

In Catalog, you can filter data rows by the global key. To do this, filter by Data row > Global key > and paste the global key in the search bar.

Global keys are cleared after deleting Data Rows

Global keys will be automatically deleted after the deletion of Data Rows. For example,

global_key = 'example_global_key'
new_data_row = {
    "row_data": "https://storage.googleapis.com/labelbox-sample-datasets/Docs/basic.jpg", 
    "external_id": str(uuid.uuid4()),
    "global_key": global_key
}
# This task should succeed
task = dataset.create_data_rows([new_data_row])
task.wait_till_done()
print(task.errors) # None

# This task should fail
task = dataset.create_data_rows([new_data_row])
task.wait_till_done()
task.errors, task.result
# WARNING:labelbox.client:There are errors present. Please look at 'errors' in the returned dict for more details
# WARNING:labelbox.schema.task:There are errors present. Please look at `task.errors` for more details
---------------------------------------------------------------------------
#ValueError: Job failed. Errors : Duplicate global keys found: example_global_key

Since global keys are deleted upon data row deletion, you can check whether a global key is attached to a deleted data row and it will show up in the "errors" field.

# delete data row by global key
duplicated_data_row = client.get_data_row(client.get_data_row_ids_for_global_keys([global_key])['results'][0])
duplicated_data_row.delete()
print('deleted')

# Should not have results
result = client.get_data_row_ids_for_global_keys(['example_global_key'])
print(result)
# WARNING:labelbox.client:There are errors present. Please look at 'errors' in the returned dict for more details
#{'status': 'FAILURE', 'results': [''], 'errors': [{'global_key': 'example_global_key', 'error': 'Data Row deleted'}]}

# You can now upload a Data Row with same global key again 
# This should succeed
task = dataset.create_data_rows([new_data_row])
task.wait_till_done()
print(task.errors)