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.
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.
# Import dependenciesfrom encord.user_client import EncordUserClient#Authenticate using the path to your private keyuser_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path="<private_key_path>" )# Create a project. Substitute a project title, and dataset hashes of the datasets you'd like to attach, as well as the has of the template you want to useproject = user_client.create_project( project_title="<project_title>", dataset_hashes=["<dataset_hash_1>", "<dataset_hash_2>"], workflow_template_hash="<template_hash>")# Prints the hash of the project you've just createdprint(project)
You can query and list all the available Projects for a given user. In the following example a user fetches all Projects available using the get_projects() method.
# Import dependenciesfrom encord.user_client import EncordUserClient#Authenticate using the path to your private keyuser_client = EncordUserClient.create_with_ssh_private_key(ssh_private_key_path="<private_key_path>")# List existing projectsprojects = user_client.get_projects()print(projects)
The get_projects() method has multiple optional arguments that allow you to perform a filtered search when querying projects. For example, if you only want projects with titles starting with “Validation”, you could use user_client.get_project(title_like=“Validation%”). Other keyword arguments such as created_before or edited_after may also be of interest.
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 dependenciesfrom encord.user_client import EncordUserClient#Authenticate using the path to your private keyuser_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 hashproject = user_client.get_project( "<project-hash>")# Return all data units in the task back to the first Workflow stagefor 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 stagelabel_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 dependenciesfrom encord.user_client import EncordUserClient#Authenticate using the path to your private keyuser_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 hashproject = user_client.get_project( "<project-hash>")# Create a bundle and automatically execute everything attached to the bundlewith 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)
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 dependenciesfrom encord.user_client import EncordUserClient#Authenticate using the path to your private keyuser_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 hashproject = user_client.get_project( "<project-hash>")# Create a bundlewith 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)
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 dependenciesfrom encord.user_client import EncordUserClient#Authenticate using the path to your private keyuser_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 hashproject = user_client.get_project( "<project-hash>")# Move all tasks from <review_stage_2> into the final stage of the Workflow projectfor label_row in project.list_label_rows_v2(): if label_row.workflow_graph_node.title == "<review_stage_2>": label_row.workflow_complete()
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 dependenciesfrom encord.user_client import EncordUserClient#Authenticate using the path to your private keyuser_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 hashproject = user_client.get_project( "<project-hash>")# Reading the priority of the first label rowlabel_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.2label_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 dependenciesfrom encord.user_client import EncordUserClient#Authenticate using the path to your private keyuser_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 hashproject = user_client.get_project( "<project-hash>")# Create a bundlewith 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)