Getting Started

Updated 1 week ago by Florijan Stamenkovic

The Python Labelbox package is a utility that helps you interact with your Labelbox data using a Python API. It provides data structures and functionalities that transparently map to your online data.

Installation and launch

Install the Python client API using pip:

pip install labelbox

To use the Labelbox client API you will need a Labelbox account. You will need an API key for that account. See API Keys for information on how to generate a key.

Your API key can be passed to the Python client API as an environment variable LABELBOX_API_KEY .

user@machine:~$ export LABELBOX_API_KEY="<your api key here>"
user@machine:~$ python3

>>> from labelbox import Client
>>> client = Client()

You can also pass the API key explicitly when initialising a Client object.

>>> from labelbox import Client
>>> client = Client("<your api key here>")

First Steps

Here's a brief introduction on often used Labelbox functionalities. A new user will often create a Project and a Dataset object.

>>> project = client.create_project(name="MyProject")
>>> dataset = client.create_dataset(name="MyDataset")

You can connect and disconnect objects using the object.relationship.connect and object.relationship.disconnect methods.

>>> project.datasets.connect(dataset)

You can upload your data (create DataRow objects) in bulk to the dataset. For more information about this method see Creating Objects.

>>> task = dataset.create_data_rows(["path/to/file1.jpg", "path/to/file2.png"])
>>> task.wait_till_done()

Besides interacting with Labelbox using premade classes in an object-oriented manner, you can also execute custom GraphQL queries.

>>> response = c.execute("query Project($id_param: ID!) {project(where: {id: $id_param}) {name id}}",
{"id_param": "cjzuavmjthgpr07945tc30jq4"})
>>> print(response)
{'data': {'project': {'name': 'Demo ', 'id': 'cjzuavmjthgpr07945tc30jq4'}}}

Notice that, when executing a custom GraphQL query, the response consists of plain Python objects and not Labelbox objects.

What Next


How did we do?