User groups

User groups support adding or removing users in bulk from Projects, Datasets, and Ontologies within your Organization.

ℹ️

Note

Create user groups using the Encord platform.

List user groups

Listing user groups returns a list of all user group names.

List all user groups in your Organization

You can list all users groups that currently exist within your Organization.

In the following script, ensure that you replace <private_key_path> with the path to your private key.

# Import dependencies
from encord.user_client import EncordUserClient

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

# List all groups for the Org your user belongs to
user_client.list_groups()

List user groups for Projects / Datasets / Ontologies

You can list all existing user groups for a specific Project. In the following script, ensure that you:

  • Replace <private_key_path> with the path to your private key.
  • If you are using the Project script, replace <project_hash> with the hash of the Project you want to list user groups for.
  • If you are using the Dataset script, replace <dataset_hash> with the hash of the Dataset you want to list user groups for.
  • If you are using the Ontology script, replace <ontology_hash> with the hash of the Ontology you want to list user groups for.
# 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>"
    )

# Specify the Project. Replace <project_hash> with the hash for your Project
project = user_client.get_project("<project_hash>")

# List Project Groups
for project_group in project.list_groups():
    print(project_group)
# 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>"
    )

# Specify the Dataset. Replace <dataset_hash> with the hash for your Dataset
dataset = user_client.get_dataset("<dataset_hash>")

# List Dataset Groups
for dataset_group in dataset.list_groups():
    print(dataset_group)
# 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>"
    )

# Specify the Ontology. Replace <ontology_hash> with the hash for your Ontology
ontology = user_client.get_ontology("<ontology_hash>")

# List Dataset Groups
for ontology_group in ontology.list_groups():
    print(ontology_group)
group_hash=UUID('fd299110-b10b-42c0-b014-8ffecb44ca6b') name='Annotators1' description='annotator_team_1' created_at=datetime.datetime(2022, 10, 28, 10, 1, 44, 664227)
group_hash=UUID('fe8ac5dc-6ac4-489c-a034-917752c341a4') name='Annotators2' description='annotator_team_2' created_at=datetime.datetime(2022, 10, 19, 16, 56, 13, 832372)

Add user groups

User groups can be added to Projects, Datasets, and Ontologies.

Add user group to Projects

Use the following scripts to add user groups to a Project.

In the following scripts, ensure that you:

  • Replace <private_key_path> with the path to your private key.
  • Replace <project_hash> with the hash of the Project you want to add a user group to.
  • Replace <group_name1> and <group_name2> with the name of the user group(s) you want to add to the Project. You can add one or multiple groups to a Project at once.

The different tabs show how to assign different user roles to the user group being added.

# Import dependencies
from encord import EncordUserClient
from encord.utilities.project_user import ProjectUserRole

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

# Add group to Project. Replace <project_hash> with the hash of the Project
project = user_client.get_project("<project_hash>")
groups = user_client.list_groups()

# Replace <group_name1> and <group_name2> with the name(s) of the group(s).
group_names = ["<group_name1>", "<group_name2>"]  # Add as many group names as needed.
group_hashes = [group.group_hash for group in groups if group.name in group_names]
project.add_group(group_hashes, ProjectUserRole.ADMIN)
# Import dependencies
from encord import EncordUserClient
from encord.utilities.project_user import ProjectUserRole

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

# Add group to Project. Replace <project_hash> with the hash of the Project.
project = user_client.get_project("<project_hash>")
groups = user_client.list_groups()

# Replace <group_name1> and <group_name2> with the name(s) of the group(s).
group_names = ["<group_name1>", "<group_name2>"]  # Add as many group names as needed.
group_hashes = [group.group_hash for group in groups if group.name in group_names]
project.add_group(group_hashes, ProjectUserRole.TEAM_MANAGER)

# Import dependencies
from encord import EncordUserClient
from encord.utilities.project_user import ProjectUserRole

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

# Add group to Project. Replace <project_hash> with the hash of the Project.
project = user_client.get_project("<project_hash>")
groups = user_client.list_groups()

# Replace <group_name1> and <group_name2> with the name(s) of the group(s).
group_names = ["<group_name1>", "<group_name2>"]  # Add as many group names as needed.
group_hashes = [group.group_hash for group in groups if group.name in group_names]
project.add_group(group_hashes, ProjectUserRole.ANNOTATOR_REVIEWER)
# Import dependencies
from encord import EncordUserClient
from encord.utilities.project_user import ProjectUserRole

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

# Add group to Project. Replace <project_hash> with the hash of the Project.
project = user_client.get_project("<project_hash>")
groups = user_client.list_groups()

# Replace <group_name1> and <group_name2> with the name(s) of the group(s).
group_names = ["<group_name1>", "<group_name2>"]  # Add as many group names as needed.
group_hashes = [group.group_hash for group in groups if group.name in group_names]
project.add_group(group_hashes, ProjectUserRole.ANNOTATOR)
# Import dependencies
from encord import EncordUserClient
from encord.utilities.project_user import ProjectUserRole

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

# Add group to Project. Replace <project_hash> with the hash of the Project.
project = user_client.get_project("<project_hash>")
groups = user_client.list_groups()

# Replace <group_name1> and <group_name2> with the name(s) of the group(s).
group_names = ["<group_name1>", "<group_name2>"]  # Add as many group names as needed.
group_hashes = [group.group_hash for group in groups if group.name in group_names]
project.add_group(group_hashes, ProjectUserRole.REVIEWER)

Add user group to Datasets

User groups can be added to Datasets.

In the following scripts, ensure that you:

  • Replace <private_key_path> with the path to your private key.
  • Replace <dataset_hash> with the hash of the Dataset you want to add a user group to.
  • Replace <group_name1> and <group_name2> with the name of the user group(s) you want to add to the Dataset. You can add one or multiple groups to a Dataset at once.

The different tabs show how to assign different roles to the user group being added to the Dataset.

# Import dependencies
from encord import EncordUserClient
from encord.orm.dataset import DatasetUserRole

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

# Add group to Dataset. Replace <dataset_hash> with the hash of the Dataset.
dataset = user_client.get_dataset("<dataset_hash>")
groups = user_client.list_groups()

# Replace <group_name1> and <group_name2> with the name(s) of the group(s).
group_names = ["<group_name1>", "<group_name2>"]  # Add as many group names as needed.
group_hashes = [group.group_hash for group in groups if group.name in group_names]
dataset.add_group(group_hashes, DatasetUserRole.ADMIN)
# Import dependencies
from encord import EncordUserClient
from encord.orm.dataset import DatasetUserRole

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

# Add group to Dataset. Replace <dataset_hash> with the hash of the Dataset.
dataset = user_client.get_dataset("dataset_hash>")
groups = user_client.list_groups()

# Replace <group_name1> and <group_name2> with the name(s) of the group(s).
group_names = ["<group_name1>", "<group_name2>"]  # Add as many group names as needed.
group_hashes = [group.group_hash for group in groups if group.name in group_names]
dataset.add_group(group_hashes, DatasetUserRole.USER)

Add user group to Ontologies

Use the following scripts to add user groups to Ontologies.

In the following scripts, ensure that you:

  • Replace <private_key_path> with the path to your private key.
  • Replace <ontology_hash> with the hash of the Ontology you want to add a user group to.
  • Replace <group_name1> and <group_name2> with the name of the user group(s) you want to add to the Ontology. You can add one, or multiple groups to an Ontology at once.

The different tabs show how to assign different roles to the user group being added to the Ontology.


# Import dependencies
from encord import EncordUserClient
from encord.utilities.ontology_user import OntologyUserRole

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

# Add group to Ontology. Replace <ontology_hash> with the hash of the Ontology.
ontology = user_client.get_ontology("<ontology_hash>")
groups = user_client.list_groups()

# Replace <group_name1> and <group_name2> with the name(s) of the group(s).
group_names = ["<group_name1>", "<group_name2>"]  # Add as many group names as needed.
group_hashes = [group.group_hash for group in groups if group.name in group_names]
dataset.add_group(group_hashes, OntologyUserRole.ADMIN)
# Import dependencies
from encord import EncordUserClient
from encord.utilities.ontology_user import OntologyUserRole

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

# Add group to Ontology. Replace <ontology_hash> with the hash of the Ontology.
ontology = user_client.get_ontology("<ontology_hash>")
groups = user_client.list_groups()

# Replace <group_name1> and <group_name2> with the name(s) of the group(s).
group_names = ["<group_name1>", "<group_name2>"]  # Add as many group names as needed.
group_hashes = [group.group_hash for group in groups if group.name in group_names]
dataset.add_group(group_hashes, OntologyUserRole.USER)

Remove user groups from Projects / Datasets / Ontologies

User groups can be removed from Projects, Datasets, and Ontologies individually, or in bulk.

ℹ️

Note

Admins can not be removed from Projects, Datasets, or Ontologies. To remove an Admin, contact [email protected]

In the following scripts, ensure that you:

  • Replace <private_key_path> with the path to your private key.
  • If using the Project script, replace <project_hash> with the hash of the Project you want to remove user groups from.
  • If using the Dataset script, replace <dataset_hash> with the hash of the Dataset you want to remove user groups from.
  • If using the Ontology script, replace <ontology_hash> with the hash of the Ontology you want to remove user groups from.
  • Replace <group_name1> and <group_name2> with the name of the user group(s) you want to remove from the Project. You can remove one, or multiple groups from a Project at once.
# Import dependencies
from encord 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>"
    )

# Remove group from Project. Replace <project_hash> with the hash of the Project
project = user_client.get_project("<project_hash>")
groups = user_client.list_groups()

# Replace <group_name1> and <group_name2> with the name(s) of the group(s).
group_names = ["<group_name1>", "<group_name2>"]  # Include as many group names as needed.
group_hashes = [group.group_hash for group in groups if group.name in group_names]
project.remove_group(group_hashes)
# Import dependencies
from encord 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>"
    )

# Remove group from Dataset. Replace <dataset_hash> with the hash of the Dataset.
dataset = user_client.get_dataset("<dataset_hash>")
groups = user_client.list_groups()

# Replace <group_name1> and <group_name2> with the name(s) of the group(s).
group_names = ["<group_name1>", "<group_name2>"]  # Include as many group names as needed.
group_hashes = [group.group_hash for group in groups if group.name in group_names]
dataset.remove_group(group_hashes)
# Import dependencies
from encord 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>"
    )

# Remove group from Ontology. Replace <ontology_hash> with the hash of the Ontology.
ontology = user_client.get_ontology("<ontology_hash>")
groups = user_client.list_groups()

# Replace <group_name1> and <group_name2> with the name(s) of the group(s).
group_names = ["<group_name1>", "<group_name2>"]  # Include as many group names as needed.
group_hashes = [group.group_hash for group in groups if group.name in group_names]
ontology.remove_group(group_hashes)