|
| 1 | +=================== |
| 2 | +ScaleAPI for Python |
| 3 | +=================== |
| 4 | + |
| 5 | + |
| 6 | +Installation |
| 7 | +============ |
| 8 | +.. code-block:: bash |
| 9 | +
|
| 10 | + $ pip install scaleapi |
| 11 | +
|
| 12 | +Usage |
| 13 | +===== |
| 14 | +.. code-block:: python |
| 15 | +
|
| 16 | + import scale |
| 17 | + client = scale.ScaleClient('YOUR_API_KEY_HERE') |
| 18 | +
|
| 19 | +Tasks |
| 20 | +===== |
| 21 | + |
| 22 | +Most of these methods will return a ``scaleapi.Task`` object, which will contain information |
| 23 | +about the json response (task_id, status...). |
| 24 | + |
| 25 | +Any parameter available in the documentation_ can be passed as an argument option with the corresponding type. |
| 26 | + |
| 27 | +.. _documentation: https://docs.scaleapi.com |
| 28 | + |
| 29 | +The following endpoints for tasks are available: |
| 30 | + |
| 31 | +Create categorization task |
| 32 | +========================== |
| 33 | + |
| 34 | +Check `this`__ for further information. |
| 35 | + |
| 36 | +__ https://docs.scaleapi.com/#create-categorization-task |
| 37 | + |
| 38 | +.. code-block:: python |
| 39 | +
|
| 40 | + task = client.create_categorization_task( |
| 41 | + callback_url='http://www.example.com/callback', |
| 42 | + instruction='Is this company public or private?', |
| 43 | + attachment_type='website', |
| 44 | + attachment='http://www.google.com/', |
| 45 | + categories=['public', 'private'] |
| 46 | + ) |
| 47 | +
|
| 48 | +Create transcription task |
| 49 | +========================= |
| 50 | + |
| 51 | +Check `this`__ for further information. |
| 52 | + |
| 53 | +__ https://docs.scaleapi.com/#create-transcription-task |
| 54 | + |
| 55 | +.. code-block:: python |
| 56 | +
|
| 57 | + task = client.create_transcription_task( |
| 58 | + callback_url='http://www.example.com/callback', |
| 59 | + instruction='Transcribe the given fields. Then for each news item on the page, transcribe the information for the row.', |
| 60 | + attachment_type='website', |
| 61 | + attachment='http://www.google.com/', |
| 62 | + fields={ 'title': 'Title of Webpage', 'top_result': 'Title of the top result' }, |
| 63 | + row_fields={ 'username': 'Username of submitter', 'comment_count': 'Number of comments' } |
| 64 | + ) |
| 65 | +
|
| 66 | +Create phone call task |
| 67 | +====================== |
| 68 | + |
| 69 | +Check `this`__ for further information. |
| 70 | + |
| 71 | +__ https://docs.scaleapi.com/#create-phone-call-task |
| 72 | + |
| 73 | +.. code-block:: python |
| 74 | +
|
| 75 | + client.create_phonecall_task( |
| 76 | + callback_url='http://www.example.com/callback', |
| 77 | + instruction="Call this person and tell me his email address. Ask if he's happy too.", |
| 78 | + phone_number='5055006865', |
| 79 | + entity_name='Alexandr Wang', |
| 80 | + fields={ 'email': 'Email Address' }, |
| 81 | + choices=['He is happy', 'He is not happy'] |
| 82 | + ) |
| 83 | +
|
| 84 | +Create comparison task |
| 85 | +====================== |
| 86 | + |
| 87 | +Check `this`__ for further information. |
| 88 | + |
| 89 | +__ https://docs.scaleapi.com/#create-comparison-task |
| 90 | + |
| 91 | +.. code-block:: python |
| 92 | +
|
| 93 | + client.create_comparison_task( |
| 94 | + callback_url='http://www.example.com/callback', |
| 95 | + instruction='Do the objects in these images have the same pattern?', |
| 96 | + attachment_type='image', |
| 97 | + choices=['yes', 'no'], |
| 98 | + attachments=[ |
| 99 | + 'http://i.ebayimg.com/00/$T2eC16dHJGwFFZKjy5ZjBRfNyMC4Ig~~_32.JPG', |
| 100 | + 'http://images.wisegeek.com/checkered-tablecloth.jpg' |
| 101 | + ] |
| 102 | + ) |
| 103 | +
|
| 104 | +Create annotation task |
| 105 | +====================== |
| 106 | + |
| 107 | +Check `this`__ for further information. |
| 108 | + |
| 109 | +__ https://docs.scaleapi.com/#create-annotation-task-bounding-box |
| 110 | + |
| 111 | +.. code-block:: python |
| 112 | +
|
| 113 | + client.create_annotation_task( |
| 114 | + callback_url='http://www.example.com/callback', |
| 115 | + instruction='Draw a box around each baby cow and big cow.', |
| 116 | + attachment_type="image", |
| 117 | + attachment="http://i.imgur.com/v4cBreD.jpg", |
| 118 | + objects_to_annotate=["baby cow", "big cow"] |
| 119 | + ) |
| 120 | +
|
| 121 | +Retrieve task |
| 122 | +============= |
| 123 | + |
| 124 | +Check `this`__ for further information. |
| 125 | + |
| 126 | +__ https://docs.scaleapi.com/#retrieve-a-task |
| 127 | + |
| 128 | +Retrieve a task given its id. |
| 129 | + |
| 130 | +.. code-block :: python |
| 131 | +
|
| 132 | + task = client.retrieve_task('asdfasdfasdfasdfasdfasdf') |
| 133 | + task.id == 'asdfasdfasdfasdfasdfasdf' # true |
| 134 | +
|
| 135 | +Cancel task |
| 136 | +=========== |
| 137 | + |
| 138 | +Check `this`__ for further information. |
| 139 | + |
| 140 | +__ https://docs.scaleapi.com/#cancel-a-task |
| 141 | + |
| 142 | +Cancel a task given its id, only if it's not completed. |
| 143 | + |
| 144 | +.. code-block :: python |
| 145 | +
|
| 146 | + task = client.cancel_task('asdfasdfasdfasdfasdfasdf') |
| 147 | +
|
| 148 | +List tasks |
| 149 | +========== |
| 150 | + |
| 151 | +Check `this`__ for further information. |
| 152 | + |
| 153 | +__ https://docs.scaleapi.com/#list-all-tasks |
| 154 | + |
| 155 | +Retrieve a list of tasks, with optional filter by date/type. Paginated with limit/offset. |
| 156 | + |
| 157 | +.. code-block :: python |
| 158 | +
|
| 159 | + tasks = client.tasks( |
| 160 | + start_time='2015-10-13T22:38:42Z', |
| 161 | + end_time='2016-10-13T22:38:42Z', |
| 162 | + type='categorization', |
| 163 | + limit=100, |
| 164 | + offset=200) |
| 165 | +
|
| 166 | +Error handling |
| 167 | +============== |
| 168 | + |
| 169 | +If something went wrong while making API calls, then exceptions will be raised automatically |
| 170 | +as a ``scale.ScaleException`` or ``scale.ScaleInvalidRequest`` runtime error. For example: |
| 171 | + |
| 172 | +.. code-block:: python |
| 173 | +
|
| 174 | + try |
| 175 | + scale.create_categorization_task('Some parameters are missing.') |
| 176 | + except scale.ValidationError as e: |
| 177 | + print(e.code) # 400 |
| 178 | + print(e.message) # missing param X |
| 179 | +
|
0 commit comments