Giter Site home page Giter Site logo

mturk-crowd-beta-client-python's Introduction

Prerequisites

To use this library, you'll need first follow our account set-up instructions to set up your Mechanical Turk and AWS accounts to call the API.

Instantiating the client requires using a Session object from boto3 to authenticate. The boto3 docs describe how to manage your credentials in more detail.

Quick Start

First, install the library:

$ pip install mturk-crowd-beta-client

Then, from a Python interpreter or script, create your first task:

from mturk_crowd_beta_client import MTurkCrowdClient
from boto3.session import Session
import uuid

# 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 client
crowd_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().hex
function_name = 'sentiment-analysis-test'

# Create the task
put_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'}
#   }

Further Reading

Check out our usage instructions and API documentation for more details about how to use the API and this client.

mturk-crowd-beta-client-python's People

Contributors

samhenryaws avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.