Assign Users to Tasks

In this tutorial, you will assign a user to portion of tasks in a project filtered by Inner ID (0..100).

You can also find this as a Python script in the SDK repo.

This example only applies to Label Studio Enterprise and Starter Cloud. Label Studio Community does not have task assignments.

From the Label Studio UI

  1. Go to your project, select Settings > Annotation > Distribute Labeling Tasks and ensure your project is in Manual mode.

  2. From the Members page of your project or workspace, ensure that your user is added as a member.

  3. Run the script: python assign_users_to_tasks.py <PROJECT_ID> <USER_EMAIL> [AN|RE]

    • You can find your project ID in the URL when viewing a Label Studio project (e.g. https://app.humansignal.com/projects/<PROJECT_ID>) or you can use the API.
    • AN - annotator, RE - reviewer

In this example, you begin by setting your API key and Label Studio URL as environment variables:

$export LABEL_STUDIO_API_KEY="YOUR_TOKEN"
>export LABEL_STUDIO_URL="URL"

For information on finding your API key and base URL, see Authenticate and Connect to the API.

If you would prefer to set them directly in the script, see the other tutorials for an example.

Script

1import os
2import sys
3from label_studio_sdk import LabelStudio
4
5
6def main():
7 # Required: set env vars or pass args
8 base_url = os.getenv("LABEL_STUDIO_URL")
9 api_key = os.getenv("LABEL_STUDIO_API_KEY")
10 if not api_key or not base_url:
11 print("ERROR: set LABEL_STUDIO_API_KEY and LABEL_STUDIO_URL env var")
12 sys.exit(1)
13
14 if len(sys.argv) < 3:
15 print("Usage: script.py <PROJECT_ID> <USER_EMAIL> [AN|RE]")
16 sys.exit(1)
17
18 project_id = int(sys.argv[1])
19 user_email = sys.argv[2].strip()
20 assignment_type = (
21 sys.argv[3].strip().upper() if len(sys.argv) > 3 else "AN"
22 ) # AN=annotate, RE=review
23
24 client = LabelStudio(base_url=base_url, api_key=api_key)
25
26 # 1) Get project by ID
27 project = client.projects.get(id=project_id)
28 print(f"Project: {project.title} (id={project.id})")
29
30 # 2) Get user by email
31 users = list(client.users.list())
32 user = next(
33 (u for u in users if (u.email or "").lower() == user_email.lower()), None
34 )
35 if not user:
36 print(f"ERROR: user with email {user_email} not found")
37 sys.exit(1)
38 print(f"User: {user.email} (id={user.id})")
39
40 # 3) Assign this user to tasks filtered by Inner ID from 0 to 100 (portion of tasks)
41 # Use Data Manager-style filters and select all filtered tasks
42 filters = {
43 "conjunction": "and",
44 "items": [
45 {
46 "filter": "filter:tasks:inner_id",
47 "operator": "greater",
48 "value": 0,
49 "child_filter": None,
50 "type": "Number",
51 },
52 {
53 "filter": "filter:tasks:inner_id",
54 "operator": "less",
55 "value": 100,
56 "child_filter": None,
57 "type": "Number",
58 },
59 ],
60 }
61 selected_items = {"all": True}
62
63 resp = client.projects.assignments.bulk_assign(
64 id=project_id,
65 type=assignment_type, # 'AN' or 'RE'
66 users=[user.id], # list of user IDs
67 selected_items=selected_items, # apply to all tasks matching filters, or you can pass here specific task IDs
68 filters=filters, # Inner ID in (0, 100)
69 )
70
71 # Simple summary
72 print(f"Bulk assignment done: {resp}")
73
74
75if __name__ == "__main__":
76 main()