<jupyter_start><jupyter_text>This tutorial describes the basics of assigning users to projects, workspaces, and specific tasks in Label Studio Enterprise using the Python SDK.  Connect to Label Studio Enterprise Start by connecting to Label Studio Enterprise using the `Client` module:<jupyter_code>import label_studio_sdk

ls = label_studio_sdk.Client('https://app.heartex.com', api_key='hea88r347t79e1x69c73cd52b4e1a9466d2dd836e')<jupyter_output><empty_output><jupyter_text>Add user as a project member To find out who is already part of your organization, you can list all users that are members of your current organization:<jupyter_code>users = ls.get_users()
user = users[0]
PROJECT_ID = 1 # change with your project id
project = ls.get_project(id=PROJECT_ID)
res = project.add_member(user)<jupyter_output><empty_output><jupyter_text>Change user role You can change the role of a user in the currently active organization.<jupyter_code>from label_studio_sdk.users import UserRole

user.set_role(UserRole.REVIEWER)
print(user)<jupyter_output><empty_output><jupyter_text>Assign tasks to annotators You can assign tasks to annotators so that they can work on specific tasks. You must be using manual task distribution in your project to assign tasks.<jupyter_code>tasks_ids = project.get_tasks(only_ids=True)
project.assign_annotators(users, tasks_ids)<jupyter_output><empty_output><jupyter_text>Assign tasks to reviewers You can assign tasks to reviewers so that they can review the annotations for specific tasks.<jupyter_code>project.assign_reviewers(users, tasks_ids)<jupyter_output><empty_output><jupyter_text>List all tasks assigned to specific annotators Before you assign new tasks to annotators, you might want to know which or how many tasks an annotator already has to work on. To list all the tasks already assigned to an annotator, run the following code:<jupyter_code>from label_studio_sdk.data_manager import Filters, Column, Operator, Type

filters = Filters.create(Filters.OR, [
    Filters.item(
        Column.annotators,
        Operator.CONTAINS,
        Type.List,
        Filters.value(user.id)
    )
])
tasks = project.get_tasks(filters=filters)
print(tasks)<jupyter_output><empty_output><jupyter_text>List all tasks assigned to specific reviewers Before you assign new tasks to reviewers, you might want to see which tasks or how many tasks a reviewer is assigned to already. To list all tasks already assigned to a reviewer, run the following code:<jupyter_code>from label_studio_sdk.data_manager import Filters, Column, Operator, Type

filters = Filters.create(Filters.OR, [
    Filters.item(
        Column.reviewers,
        Operator.CONTAINS,
        Type.List,
        Filters.value(user.id)
    )
])
tasks = project.get_tasks(filters=filters)
print(tasks)<jupyter_output><empty_output><jupyter_text>Remove annotators from tasks To remove annotators from a task, for example to change who is assigned to a specific task, or remove an annotator that no longer works on the project, run the following code:<jupyter_code>tasks_ids = project.get_tasks(only_ids=True)
project.delete_annotators_assignment(tasks_ids)<jupyter_output><empty_output><jupyter_text>Remove reviewers from tasks To remove reviewers from a task, run the following code:<jupyter_code>tasks_ids = project.get_tasks(only_ids=True)
project.delete_reviewers_assignment(tasks_ids)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06838861168183152, 'fraction_numerical': 0.007631347226298797, 'mean_word_length': 6.144654088050315, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '331736', 'license': 'Apache-2.0', 'n_tokens_mistral': 1045, 'n_tokens_neox': 996, 'n_words': 327, 'path': 'examples/label_studio_enterprise/assignment.ipynb', 'repo_name': 'denck007/label-studio-sdk', 'size': '3407'}