TolokaClient

toloka.client.TolokaClient | Source code

TolokaClient(
self,
token: str,
environment: Union[Environment, str, None] = None,
retries: Union[int, Retry] = 3,
timeout: Union[float, Tuple[float, float]] = 10.0,
url: Optional[str] = None,
retry_quotas: Union[List[str], str, None] = 'MIN',
retryer_factory: Optional[Callable[[], Retry]] = None,
act_under_account_id: Optional[str] = None,
verify: Union[str, bool, SSLContext] = True
)

A class that implements interaction with Toloka API.

Objects of other classes are created and modified only in memory of your computer. You can transfer information about these objects to Toloka only by calling one of the TolokaClient methods.

For example, creating an instance of Project class will not add a project to Toloka right away. It will create a Project instance in your local memory. You need to call the TolokaClient.create_project method and pass the created project instance to it. Likewise, if you read a project using the TolokaClient.get_project method, you will get an instance of Project class. But if you change some parameters in this object manually in your code, it will not affect the existing project in Toloka. Call TolokaClient.update_project and pass the Project to apply your changes.

Alert

Starting July 1, 2024 Sandbox environment is unavailable.

Parameters description

ParametersTypeDescription
tokenstr

Your OAuth token for Toloka. You can learn more about how to get it here

environmentUnion[Environment, str, None]

There are two environments in Toloka:

  • SANDBOXTesting environment for Toloka requesters. You can test complex projects before assigning tasks to Tolokers. Nobody will see your tasks, and it's free.
  • PRODUCTIONProduction environment for Toloka requesters. You spend money there and get the results.

You need to register in each environment separately. OAuth tokens are generated in each environment separately too.

Default value: None.

retriesUnion[int, Retry]

Retry policy for failed API requests. Possible values:

  • int – The number of retries for all requests. In this case, the retry policy is created automatically.
  • Retry object – Deprecated type. Use retryer_factory parameter instead.

Default value: 3.

timeoutUnion[float, Tuple[float, float]]

Number of seconds that Requests library will wait for your client to establish connection to a remote machine. Possible values:

  • float – Single value for both connect and read timeouts.
  • Tuple[float, float] – Tuple sets the values for connect and read timeouts separately.
  • None – Set the timeout to None only if you are willing to wait the Response for unlimited number of seconds.

Default value: 10.0.

urlOptional[str]

Set a specific URL instead of Toloka environment. May be useful for testing purposes. You can only set one parameter – either url or environment, not both of them.

Default value: None.

retry_quotasUnion[List[str], str, None]

List of quotas that must be retried. Set None or pass an empty list for not retrying any quotas. If you specified the retries as Retry instance, you must set this parameter to None. Possible values:

  • MIN - Retry minutes quotas.
  • HOUR - Retry hourly quotas. This means that the program just sleeps for an hour.
  • DAY - Retry daily quotas. We do not recommend retrying these quotas.

Default value: MIN.

retryer_factoryOptional[Callable[[], Retry]]

Factory that creates Retry object. Fully specified retry policy that will apply to all requests.

Default value: None.

act_under_account_idOptional[str]

ID of the requester that has been shared access with the current token owner account. All requests will be made using a specified account. See Shared access to the requester's account documentation page. ID of the requester can be retrieved using the get_requester method (this method should be called by the account owner using account's token).

verifyUnion[str, bool, SSLContext]

SSL certificates (a.k.a CA bundle) used to verify the identity of requested hosts. Either True (default CA bundle), a path to an SSL certificate file, an ssl.SSLContext, or False (which will disable verification).

Examples:

How to create TolokaClient instance and make your first request to Toloka.

import toloka
your_oauth_token = input('Enter your token:')
toloka_client = toloka.client.TolokaClient(your_oauth_token, 'PRODUCTION') # Or switch to 'SANDBOX' environment
Note

toloka_client instance will be used to pass all API calls later on.

Methods summary

MethodDescription
accept_assignmentAccepts an assignment.
add_message_thread_to_foldersAdds a message thread to folders.
aggregate_solutions_by_poolStarts aggregation of responses in all completed tasks in a pool.
aggregate_solutions_by_taskAggregates responses to a single task on the Toloka server.
archive_app_projectArchives an App project.
archive_poolArchives a pool.
archive_pool_asyncArchives a pool. Sends an asynchronous request to Toloka.
archive_projectArchives a project.
archive_project_asyncArchives a project. Sends an asynchronous request to Toloka.
archive_trainingArchives a training.
archive_training_asyncArchives a training. Sends an asynchronous request to Toloka.
clone_poolClones an existing pool.
clone_pool_asyncClones an existing pool. Sends an asynchronous request to Toloka.
clone_projectClones a project and all pools and trainings inside it.
clone_trainingClones an existing training.
clone_training_asyncClones an existing training. Sends an asynchronous request to Toloka.
close_poolCloses a pool.
close_pool_asyncCloses a pool. Sends an asynchronous request to Toloka.
close_pool_for_updateCloses a pool that is to be updated.
close_pool_for_update_asyncCloses a pool that is to be updated. Sends an asynchronous request to Toloka.
close_trainingCloses a training.
close_training_asyncCloses a training. Sends an asynchronous request to Toloka.
compose_message_threadCreates a message thread and sends the first thread message to Tolokers.
create_app_batchCreates a batch with task items in an App project in Toloka.
create_app_itemCreates an App task item in Toloka.
create_app_itemsCreates task items in an App project in Toloka and adds them to an existing batch.
create_app_projectCreates an App project in Toloka.
create_poolCreates a new pool in Toloka.
create_projectCreates a new project in Toloka.
create_skillCreates a new skill.
create_taskCreates a new task in Toloka.
create_task_suiteCreates a task suite in Toloka.
create_task_suitesCreates several task suites in Toloka.
create_task_suites_asyncCreates several task suites in Toloka asynchronously.
create_tasksCreates several tasks in Toloka.
create_tasks_asyncCreates tasks in Toloka asynchronously.
create_trainingCreates a new training in Toloka.
create_user_bonusIssues a bonus payment to a Toloker.
create_user_bonusesIssues several bonus payments to Tolokers.
create_user_bonuses_asyncIssues bonus payments to Tolokers asynchronously.
delete_user_restrictionRemoves existing restriction.
delete_user_skillRemoves a skill from a Toloker.
delete_webhook_subscriptionDeletes a subscription.
download_attachmentDownloads an attachment.
find_aggregated_solutionsFinds aggregated responses that match certain criteria.
find_app_batchesFinds batches that match certain criteria in an App project.
find_app_itemsFinds task items that match certain criteria in an App project.
find_app_projectsFinds App projects that match certain criteria.
find_appsFinds App solutions that match certain criteria.
find_assignmentsFinds assignments that match certain criteria.
find_attachmentsFinds attachments that match certain criteria and returns their metadata.
find_message_threadsFinds message threads that match certain criteria.
find_operationsFinds operations that match certain criteria.
find_poolsFinds pools that match certain criteria.
find_projectsFinds projects that match certain criteria.
find_skillsFinds skills that match certain criteria.
find_task_suitesFinds task suites that match certain criteria.
find_tasksFinds tasks that match certain criteria.
find_trainingsFinds trainings that match certain criteria.
find_user_bonusesFinds Tolokers' bonuses that match certain criteria.
find_user_restrictionsFinds Toloker restrictions that match certain criteria.
find_user_skillsFinds Toloker's skills that match certain criteria.
find_webhook_subscriptionsFinds webhook subscriptions that match certain criteria.
get_aggregated_solutionsFinds all aggregated responses that match certain criteria.
get_analyticsSends analytics requests to Toloka.
get_appGets information from Toloka about an App solution.
get_app_batchGets information from Toloka about a batch in an App project.
get_app_batchesFinds all batches that match certain criteria in an App project.
get_app_itemGets information from Toloka about an App task item.
get_app_itemsFinds all App task items that match certain criteria in an App project.
get_app_projectGets information from Toloka about an App project.
get_app_projectsFinds all App projects that match certain criteria.
get_appsFinds all App solutions that match certain criteria.
get_assignmentGets an assignment from Toloka.
get_assignmentsFinds all assignments that match certain criteria.
get_assignments_dfDownloads assignments as pandas.DataFrame.
get_attachmentGets attachment metadata without downloading it.
get_attachmentsFinds all attachments that match certain criteria and returns their metadata.
get_message_threadsFinds all message threads that match certain criteria.
get_operationGets information about an operation from Toloka.
get_operation_logGets an operation log.
get_operationsFinds all operations that match certain criteria.
get_poolGets pool data from Toloka.
get_poolsFinds all pools that match certain criteria.
get_projectGets project data from Toloka.
get_projectsFinds all projects that match certain criteria.
get_requesterGets information about the requester and the account balance.
get_skillGets skill information from Toloka.
get_skillsFinds all skills that match certain criteria.
get_taskGets a task with specified ID from Toloka.
get_task_suiteGets task suite data from Toloka.
get_task_suitesFinds all task suites that match certain criteria.
get_tasksFinds all tasks that match certain criteria.
get_trainingGets information about a training from Toloka.
get_trainingsFinds all trainings that match certain criteria.
get_userGets information about a Toloker.
get_user_bonusGets information about a Toloker's bonus.
get_user_bonusesFinds all Tolokers' bonuses that match certain rules and returns them in an iterable object
get_user_restrictionGets information about a Toloker restriction.
get_user_restrictionsFinds all Toloker restrictions that match certain criteria.
get_user_skillGets the value of a Toloker's skill.
get_user_skillsFinds all Toloker's skills that match certain criteria.
get_webhook_subscriptionGets the properties of a subscription from Toloka.
get_webhook_subscriptionsFinds all webhook subscriptions that match certain criteria.
open_poolOpens a pool.
open_pool_asyncOpens a pool. Sends an asynchronous request to Toloka.
open_trainingOpens a training.
open_training_asyncOpens a training. Sends an asynchronous request to Toloka.
patch_app_batchUpdates an App batch.
patch_assignmentChanges an assignment status and associated public comment.
patch_poolChanges pool parameters in Toloka.
patch_taskChanges a task overlap value.
patch_task_overlap_or_minStops assigning a task to Tolokers.
patch_task_suiteChanges task suite parameter values in Toloka.
patch_task_suite_overlap_or_minStops assigning a task suite to Tolokers.
reject_assignmentRejects an assignment.
remove_message_thread_from_foldersRemoves a message thread from folders.
reply_message_threadSends a reply message in a thread.
resume_app_batchResumes annotation of a batch of task items in an App project.
set_user_restrictionRestricts access to projects or pools for a Toloker.
set_user_skillAssigns a skill to a Toloker.
start_app_batchLaunches annotation of a batch of task items in an App project.
stop_app_batchStops annotation of a batch of task items in an App project.
unarchive_app_projectUnarchives an App project.
update_poolUpdates all pool parameters in Toloka.
update_projectUpdates all project parameters in Toloka.
update_skillUpdates all skill parameters in Toloka.
update_trainingUpdates parameters of a training in Toloka.
upsert_webhook_subscriptionsCreates subscriptions.
wait_operationWaits for a Toloka operation to complete.

Last updated: August 28, 2023

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