Create a Project

You can create a project in Label Studio using the SDK.

To start, you just need to specify:

  • Project title
  • Labeling configuration

Choose your labeling configuration based on the type of labeling that you wish to perform. See the available templates for Label Studio projects, or set a blank configuration with <View></View>.

For this example, we will use the following basic labeling config to perform sentiment analysis on text:

1<View>
2 <Header value="Choose text sentiment:"/>
3 <Text name="text" value="$text"/>
4 <Choices name="sentiment" toName="text" choice="single">
5 <Choice value="Positive"/>
6 <Choice value="Negative"/>
7 <Choice value="Neutral"/>
8 </Choices>
9</View>

Your Python will look like this. For information on finding your API key and base URL, see Authenticate and Connect to the API.

1# Define the URL where Label Studio is accessible
2LABEL_STUDIO_URL = 'YOUR_BASE_URL'
3# API key is available at the Account & Settings page in Label Studio UI
4LABEL_STUDIO_API_KEY = 'YOUR_API_KEY'
5
6# Import the SDK and the client module
7from label_studio_sdk import LabelStudio
8
9client = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=LABEL_STUDIO_API_KEY)
10
11label_config = """
12<View>
13 <Header value="Choose text sentiment:"/>
14 <Text name="text" value="$text"/>
15 <Choices name="sentiment" toName="text" choice="single">
16 <Choice value="Positive"/>
17 <Choice value="Negative"/>
18 <Choice value="Neutral"/>
19 </Choices>
20</View>
21"""
22
23project = client.projects.create(
24 title="Sentiment Classification",
25 label_config=label_config
26)
27
28print("Project ID:", project.id)
Take note of the project ID, as you will need it in several for other tutorials. You can also find the project ID in the URL when viewing the project in Label Studio.

Setting workspace in Label Studio Enterprise

The example above creates the project in your Sandbox workspace.

You can specify a different workspace using the workspace ID, which you can find in the URL when viewing the workspace in Label Studio or by using the API.

1# Define the URL where Label Studio is accessible
2LABEL_STUDIO_URL = 'YOUR_BASE_URL'
3# API key is available at the Account & Settings page in Label Studio UI
4LABEL_STUDIO_API_KEY = 'YOUR_API_KEY'
5
6# Import the SDK and the client module
7from label_studio_sdk import LabelStudio
8
9client = LabelStudio(base_url=LABEL_STUDIO_URL, api_key=LABEL_STUDIO_API_KEY)
10
11label_config = """
12<View>
13 <Header value="Choose text sentiment:"/>
14 <Text name="text" value="$text"/>
15 <Choices name="sentiment" toName="text" choice="single">
16 <Choice value="Positive"/>
17 <Choice value="Negative"/>
18 <Choice value="Neutral"/>
19 </Choices>
20</View>
21"""
22
23WORKSPACE_ID = 1 # replace with your workspace ID
24
25project = client.projects.create(
26 title="Sentiment Classification",
27 label_config=label_config,
28 workspace=WORKSPACE_ID,
29)
30print("Project ID:", project.id)