Workflows are a powerful tool to design and build your Projects - letting you control how an annotation task moves through different stages of the Project, and determining how different stages are structured and interact with one another.

Creating a Workflow Project

To create a Workflow Project using the SDK:

  1. First create a Workflow template in the Encord platform.
  2. Then use the Workflow template ID, highlighted in the screenshot below, as a parameters to the create_project() method.
To use an existing template when creating a Project, users must have Admin privileges on the template. We recommend creating a copy of the Workflow template before Project creation, to ensure you have Admin privileges.
Projects cannot be deleted using the SDK or the API. Use the Encord platform to delete Projects.

Moving tasks between Workflow stages

Moving tasks to the first Workflow stage

Use the workflow_reopen() method to reopen tasks. Reopening tasks moves tasks back to the first stage in your Workflow.

This example returns all tasks in the Project:

# Import dependencies
from encord.user_client import EncordUserClient

#Authenticate using the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path="<private_key_path>"
    )

# Open the project you want to work on by specifying the project hash
project = user_client.get_project(
    "<project-hash>"
)

# Return all data units in the task back to the first Workflow stage
for label_row in project.list_label_rows_v2():
    label_row.workflow_reopen()

The example returns all tasks in a Project back to the first Workflow stage. To reopen individual tasks, modify the final lines to specify the label row you want to reopen.

# Return the first label row to the first Workflow stage
label_row[0].workflow_reopen()

We recommend using Bundles when reopening many tasks. Bundles improve performance by reducing the number of networks calls to Encord’s servers.

# Import dependencies
from encord.user_client import EncordUserClient

#Authenticate using the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path="<private_key_path>"
    )

# Open the project you want to work on by specifying the project hash
project = user_client.get_project(
    "<project-hash>"
)

# Create a bundle and automatically execute everything attached to the bundle
with project.create_bundle() as bundle:
    # Return all data units in the task back to the first Workflow stage
    for label_row in project.list_label_rows_v2():
        label_row.workflow_reopen(bundle=bundle)

Moving tasks to the Complete stage

workflow_complete() moves Workflow tasks to the Complete stage.

When moving with many label rows at the same time, create a Bundle. Bundles improve performance by reducing the number of networks calls to Encord’s servers.

In Consensus Projects, tasks in the COMPLETE and ARCHIVE blocks CANNOT be reopened.
# Import dependencies
from encord.user_client import EncordUserClient

#Authenticate using the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path="<private_key_path>"
    )

# Open the project you want to work on by specifying the project hash
project = user_client.get_project(
    "<project-hash>"
)

# Create a bundle
with project.create_bundle() as bundle:
    # Move all tasks into the final stage of the Workflow
    for label_row in project.list_label_rows_v2():
        label_row.workflow_complete(bundle=bundle)

Referencing tasks in specific Workflow stages

The workflow_graph_node() method returns the location of a task within the workflow in the form of a uuid and a title. The title corresponds to the name of the current stage in the Workflow.

The workflow_complete() method moves a task to the final Workflow stage marking it as Complete.

The following example shows how the workflow_graph_node() method and the workflow_complete() method can be used together to move all tasks in a specified Workflow stage to Complete.

# Import dependencies
from encord.user_client import EncordUserClient

#Authenticate using the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(ssh_private_key_path='\<private_key_path>')

# Open the project you want to work on by specifying the project hash
project = user_client.get_project(
    "<project-hash>"
)

# Move all tasks from <review_stage_2> into the final stage of the Workflow project
for label_row in project.list_label_rows_v2():
    if label_row.workflow_graph_node.title == "<review_stage_2>":
        label_row.workflow_complete()

Priorities

You can read and assign task priorities using the SDK. Priorities in the SDK are represented by numbers ranging from 0 to 1, where 1 corresponds to 100 in the Encord platform, the highest priority value.

For more information, see our platform documentation for the Queue tab, and priorities.

The following example reads the priority of the first label row, and then changes it to 0.9.

Sample Code
# Import dependencies
from encord.user_client import EncordUserClient

#Authenticate using the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path="<private_key_path>"
    )

# Open the project you want to work on by specifying the project hash
project = user_client.get_project(
    "<project-hash>"
)

# Reading the priority of the first label row
label_row = project.list_label_rows_v2()[0]
label_row.initialise_labels()

print(f"Current priority: {label_row.priority}")

# Setting the priority of the first label row to 0.2
label_row.set_priority(0.2)
label_row = project.list_label_rows_v2()[0]
print(f"New priority: {label_row.priority}")
Example Output

"Current priority: 0.5"
"New priority: 0.2"

To change the priority of multiple label rows at the same time, create a Bundle. Bundles improve performance by reducing the number of networks calls to Encord’s servers.

You cannot set the priority for more than 100 tasks in a bundle.
# Import dependencies
from encord.user_client import EncordUserClient

#Authenticate using the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path="<private_key_path>"
    )

# Open the project you want to work on by specifying the project hash
project = user_client.get_project(
    "<project-hash>"
)

# Create a bundle
with project.create_bundle() as bundle:

# Set the priority of all tasks in the project to 0.5 
  for label_row in project.list_label_rows_v2():
    label_row.set_priority(0.5, bundle=bundle)