Projects

Updated 1 week ago by Alex Cota

These are some common use cases people have when working with Projects in the Python API.

For the definition of a Project, see Overview & data types.

Before you start

Make sure the client is initialized.

from labelbox import Client
client = Client()

Create a Project

To learn how to create a Project, see Creating your first project.

Fetch a Project

Since a Project is a top-level object, you can get a specific Project by passing the unique ID of the Project to the client. The get_project method will only take a unique ID as an argument.

project = client.get_project("<project_id>")
print(project)

Fetch multiple Projects

Here are three ways to fetch multiple Projects.

a. Use the get_projects method to get a list of all Projects in your account. This sample code will return the name and uid for each Project.

for project in client.get_projects():
print(project.name, project.uid)

b. Specify a Project by passing a comparison as a where parameter. You can use any of the standard comparison operators (==, !=, >, >=, <, <=) to specify which Projects you want. Because the get_projects method can return any number of results, it will give you a PaginatedCollection object over which you can iterate to get your specified Project.

from labelbox import Project
projects_x = client.get_projects(where=Project.name == "MyProject")

Then, you can iterate over the PaginatedCollection object.

for x in projects_x:
print(x)

Or you can use the this code to get your desired object which will raise an error if there is not at least one item in the collection.

item = next(iter(projects_x))
print(item)

For more information on pagination, see General concepts.

c. Specify a Project by combining comparisons using logical expressions. Currently the where clause supports the logical AND operator.

from labelbox import Project
projects = client.get_projects(where=(Project.name == "X") & (Project.description == "Y"))
for x in projects:
print(x)

Update a Project field

Use the update method to target and modify any updatable value in the object’s type. The key value arguments define which fields should be updated with which values. For a complete list of fields within the Project object, see the API reference.

project = client.get_project("<projectID>")
project.update(name="Project Name")

Was this section helpful? Give your feedback below.


How did we do?