Create project

Create a minimal working project using Toloka-Kit.

Note

Normally, it's more convenient to create a project using Toloka interface. Nevertheless, it's still possible to create a project, write instructions, set up input and output data fields, and configure the task interface via Toloka-Kit.

Steps to follow

1. Import Toloka-Kit

Connect the Toloka-Kit library to your script.

import toloka.client as toloka

2. Instantiate TolokaClient

Replace the sample API key with your own one.

toloka_client = toloka.
TolokaClient
('PlaceYourRealApiKey_Here', 'PRODUCTION');

3. Configure task interface

Configure the task interface using the view_spec parameter of the TaskSpec class, define input and output data. See comments in the code below and the Task interface section for more information.

  • The image input field contains URLs of images that need to be labeled.
  • The result output field will receive color values.
task_spec = toloka.project.task_spec.
TaskSpec
(
# The input data contains URLs to the images you want to label.
input_spec = {'image': toloka.project.field_spec.
UrlSpec
()},
# The output data contains the 'result' filled with received color values.
output_spec = {'result': toloka.project.field_spec.
StringSpec
()},
# The task interface is created using the HTML/JS/CSS editor. You can select Toloka Template Builder instead if you want.
view_spec = toloka.project.
ClassicViewSpec
(
# Define the external assets that the interface requires.
assets = {
'script_urls': ['library1.js', 'library2.js']
},
# Specify the interface markup: image src and dimensions, title text, and input field.
markup = '''{{img src=image width="400px" height="300px"}}
<p class="headerClass">Elephant color:</p>
{{field type="input" name="result"}}
''',
# Add scripts and styles.
script = '',
styles = '.headerClass { font-size: 22px; };',
# Configure additional settings.
settings = {
'showSkip': True,
'showTimer': True,
'showTitle': True,
'showSubmit': True,
'showFullscreen': True,
'showInstructions': True,
'showFinish': True,
'showMessage': True,
'showReward': True
}
)
)
Important

All the code manipulations at steps 3–4 occur in your device memory. The data will only be sent to the server after calling the create_project() method at step 5.

4. Create project object

Specify a public name, description, and instructions that the Tolokers will see.

new_project = toloka.
Project
(

public_name = '<your_project_public_name>',

public_description = '<your_project_public_description>',

public_instructions = '<your_project_instructions_for_Tolokers>',

task_spec = task_spec

)

5. Create project on platform

This actually creates a project in Toloka.

new_project = toloka_client.
create_project
(new_project)

6. Print created project ID

The create_project() request will return the Project class object. You can use its attributes to print the information you need.

print(new_project.id)

You should get an output with the created project ID which looks like this.

120798

Complete code: Create project

import toloka.client as toloka
toloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION')
task_spec = toloka.project.task_spec.TaskSpec(
input_spec={'image': toloka.project.field_spec.UrlSpec()},
output_spec={'result': toloka.project.field_spec.StringSpec()},
view_spec=toloka.project.ClassicViewSpec(
assets={
'script_urls': ['library1.js', 'library2.js']
},
markup='''{{img src=image width="400px" height="300px"}}
<p class="headerClass">Elephant color:</p>
{{field type="input" name="result"}}
''',
script='',
styles='.headerClass {font-size: 22px;};',
settings={
'showSkip': True,
'showTimer': True,
'showTitle': True,
'showSubmit': True,
'showFullscreen': True,
'showInstructions': True,
'showFinish': True,
'showMessage': True,
'showReward': True
}
)
)
new_project = toloka.project.Project(
public_name = '<your_project_public_name>',
public_description = '<your_project_public_description>',
public_instructions = '<your_project_instructions_for_Tolokers>',
task_spec = task_spec
)
new_project = toloka_client.create_project(new_project)
print(new_project.id)
List of classes and methods used in this recipe

See also

Last updated: February 7, 2023

Toloka-Kit
OverviewGetting API keyQuick start
Recipes
Reference
toloka.client
toloka.async_client
toloka.autoquality [autoquality]
toloka.metrics
toloka.streaming