mturk crowd rest api的客户端
mturk-crowd-beta-client的Python项目详细描述
先决条件
要使用这个库,首先需要遵循我们的account set-up instructions 设置您的机械土库克和AWS帐户以调用API。
实例化客户端需要使用从boto3到 验证。boto3 docs描述了如何在 细节。
快速启动
首先,安装库:
$ pip install mturk-crowd-beta-client
然后,从python解释器或脚本创建第一个任务:
frommturk_crowd_beta_clientimportMTurkCrowdClientfromboto3.sessionimportSessionimportuuid# This examples assume you have a local AWS profile called# 'mturk-crowd-caller', but you can authenticate however you like,# including by directly passing in your access key and secret key.session=Session(profile_name='mturk-crowd-caller')# Create the clientcrowd_client=MTurkCrowdClient(session)# For this example, we'll give our task a random, unique name. For real# work, you'll probably want to pick a name based on your input source.task_name='my-test-task-'+uuid.uuid4().hexfunction_name='sentiment-analysis-test'# Create the taskput_result=crowd_client.put_task(function_name,task_name,{'text':'Everything is wonderful.'})print('PUT response: {}'.format({'status_code':put_result.status_code,'task':put_result.json()}))# => PUT response: {# 'status_code': 201,# 'task': {'input': {'text': 'Everything is wonderful.'},# 'problemDetails': None,# 'result': None,# 'state': 'processing',# 'taskName': 'my-test-task-73fbfb29f2bc451d9696d11103dcaf0e'}# }# Get the task we just created. Note that for a production (i.e., non-test)# task, we'd have to poll periodically until the task completed.get_result=crowd_client.get_task(function_name,task_name)print('GET response: {}'.format({'status_code':get_result.status_code,'task':get_result.json()}))# => GET response: {# 'status_code': 200,# 'task': {'input': {'text': 'Everything is wonderful.'},# 'problemDetails': None,# 'result': {'sentiment': 'positive'}# 'state': 'completed',# 'taskName': 'my-test-task-73fbfb29f2bc451d9696d11103dcaf0e'}# }
进一步阅读
查看我们的usage instructions和API documentation了解更多详细信息 关于如何使用api和这个客户机。