Ban Tolokers

Restrict the access to tasks for Tolokers.

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. Restrict access to Toloker

Restrict access to specific pool

Find out the ID of the pool to which you want to restrict access for a Toloker. Use the set_user_restriction() method with the pool ID as an argument to the PoolUserRestriction collector class to restrict access to it to the Toloker with the ID specified in the request.

pool_restriction = toloka_client.
set_user_restriction
(

toloka.user_restriction.
PoolUserRestriction
(

user_id='1a5d5299e5a1d0a47605f51191e09ffc',

private_comment='Banning Toloker access to pool',

pool_id='38955320'

)

)

Restrict access to specific project

Find out the ID of the project to which you want to restrict access for a Toloker. Use the set_user_restriction() method with the project ID as an argument to the ProjectUserRestriction collector class to restrict access to it to the Toloker with the ID specified in the request.

project_restriction = toloka_client.
set_user_restriction
(

toloka.user_restriction.
ProjectUserRestriction
(

user_id='1f66ac40c616b717bbffce2a70dfe1f2',

private_comment='Banning Toloker access to project',

project_id='120798'

)

)

Restrict access to all projects

Use the set_user_restriction() method with the AllProjectsUserRestriction collector class to restrict access to all your projects to the Toloker with the ID specified in the request.

all_projects_restriction = toloka_client.
set_user_restriction
(

toloka.user_restriction.
AllProjectsUserRestriction
(

user_id='240d5b7897f98c119cd892e34295587e',

private_comment='Banning Toloker access to all projects'

)

)
Note

You can specify the will_expire argument for all the collector classes above (PoolUserRestriction, ProjectUserRestriction, or AllProjectsUserRestriction). It defines the date when the ban will be removed from the Toloker. If you don't set it, the ban will be permanent.

4. Print created ban information

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

print(pool_restriction.id, pool_restriction.created)
print(project_restriction.id, project_restriction.created)
print(all_projects_restriction.id, all_projects_restriction.created)

You should get an output with the IDs of the bans and the ban creation date and time which looks like this.

163294517 2023-07-18 15:31:27.945000+00:00
163294518 2023-07-18 15:31:28.459000+00:00
163294519 2023-07-18 15:31:29.992000+00:00

Complete code: Ban Tolokers

import toloka.client as toloka
toloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION')
pool_restriction = toloka_client.set_user_restriction(
toloka.user_restriction.PoolUserRestriction(
user_id='1a5d5299e5a1d0a47605f51191e09ffc',
private_comment='Banning Toloker access to pool',
pool_id='38955320'
)
)
project_restriction = toloka_client.set_user_restriction(
toloka.user_restriction.ProjectUserRestriction(
user_id='1f66ac40c616b717bbffce2a70dfe1f2',
private_comment='Banning Toloker access to project',
project_id='120798'
)
)
all_projects_restriction = toloka_client.set_user_restriction(
toloka.user_restriction.AllProjectsUserRestriction(
user_id='240d5b7897f98c119cd892e34295587e',
private_comment='Banning Toloker access to all projects'
)
)
print(pool_restriction.id, pool_restriction.created)
print(project_restriction.id, project_restriction.created)
print(all_projects_restriction.id, all_projects_restriction.created)
List of classes and methods used in this recipe

See also

Last updated: July 19, 2023

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