1
- ===================
1
+ =====================
2
2
Scale AI | Python SDK
3
- ===================
4
-
3
+ =====================
5
4
6
5
Installation
7
- ============
6
+ ____________
7
+
8
8
.. code-block :: bash
9
9
10
10
$ pip install --upgrade scaleapi
11
-
11
+
12
12
Note: We strongly suggest using `scaleapi ` with Python version 2.7.9 or greater due to SSL issues with prior versions.
13
13
14
14
Usage
15
- =====
15
+ _____
16
+
16
17
.. code-block :: python
17
18
18
19
import scaleapi
19
20
client = scaleapi.ScaleClient(' YOUR_API_KEY_HERE' )
20
21
21
22
Tasks
22
- =====
23
+ _____
23
24
24
- Most of these methods will return a `` scaleapi.Task ` ` object, which will contain information
25
+ Most of these methods will return a `scaleapi.Task ` object, which will contain information
25
26
about the json response (task_id, status...).
26
27
27
- Any parameter available in the documentation _ can be passed as an argument option with the corresponding type.
28
+ Any parameter available in the documentation \_ can be passed as an argument option with the corresponding type.
28
29
29
- .. _documentation : https://scale.com/docs
30
+ .. \ _documentation: https://docs. scale.com/reference#task-object
30
31
31
32
The following endpoints for tasks are available:
32
33
33
- Create Categorization Task
34
- ==========================
34
+ Create Task
35
+ ^^^^^^^^^^^
35
36
36
- Check `this `__ for further information.
37
+ This method can be used for any Scale supported task type using the following format:
38
+ `client.create_{{Task Type}}_task(...) ` and passing the applicable values into the function definition. The applicable fields and further information for each task type can be found in scales API docs `here `\_\_ for further information.
37
39
38
- __ https://scale.com/docs/#create-categorization-task
39
-
40
- .. code-block :: python
41
-
42
- task = client.create_categorization_task(
43
- callback_url = ' http://www.example.com/callback' ,
44
- instruction = ' Is this company public or private?' ,
45
- attachment_type = ' website' ,
46
- attachment = ' http://www.google.com/' ,
47
- categories = [' public' , ' private' ]
48
- )
49
-
50
- Create Image Annotation Task
51
- ======================
52
-
53
- Check `this `__ for further information.
54
-
55
- __ https://docs.scale.com/reference#general-image-annotation
40
+ \_\_ hhttps://docs.scale.com/reference#general-image-annotation
56
41
57
42
.. code-block :: python
58
43
59
44
client.create_imageannotation_task(
60
- callback_url = ' http://www.example.com/callback' ,
61
- instruction = ' Draw a box around each baby cow and big cow.' ,
62
- attachment_type = " image" ,
63
- attachment = " http://i.imgur.com/v4cBreD.jpg" ,
64
- geometries = {
65
- " box" : {
66
- " objects_to_annotate: [" Baby Cow" , " Big Cow" ],
67
- " min_height" : 10 ,
68
- " min_width" : 10
45
+ project = ' test_project' ,
46
+ callback_url = " http://www.example.com/callback" ,
47
+ instruction = " Draw a box around each baby cow and big cow." ,
48
+ attachment_type = " image" ,
49
+ attachment = " http://i.imgur.com/v4cBreD.jpg" ,
50
+ geometries = {
51
+ " box" : {
52
+ " objects_to_annotate" : [" Baby Cow" , " Big Cow" ],
53
+ " min_height" : 10 ,
54
+ " min_width" : 10
55
+ }
69
56
}
70
- }
71
57
)
72
58
73
59
Retrieve task
74
- =============
60
+ ^^^^^^^^^^^^^
75
61
76
- Check `this `__ for further information.
62
+ Check `this `\_\_ for further information.
77
63
78
- __ https://docs.scale.com/reference#retrieve-tasks
64
+ \_\_ https://docs.scale.com/reference#retrieve-tasks
79
65
80
66
Retrieve a task given its id.
81
67
82
68
.. code-block :: python
83
69
84
70
task = client.fetch_task('asdfasdfasdfasdfasdfasdf')
85
- task.id == 'asdfasdfasdfasdfasdfasdf' # true
71
+ print(task.status) // Task status ('pending', 'completed', 'error', 'canceled')
72
+ print(task.response) // If task is complete
86
73
87
- Cancel task
88
- ===========
74
+ List Tasks
75
+ ^^^^^^^^^^
89
76
90
- Check `this `__ for further information.
77
+ Check `this `\_\_ for further information.
91
78
92
- __ https://docs.scale.com/reference#cancel-task
79
+ \_\_ https://docs.scale.com/reference#list-multiple-tasks
93
80
94
- Cancel a task given its id, only if it's not completed.
95
-
96
- .. code-block :: python
97
-
98
- task = client.cancel_task('asdfasdfasdfasdfasdfasdf')
99
-
100
- List tasks
101
- ==========
102
-
103
- Check `this `__ for further information.
104
-
105
- __ https://docs.scale.com/reference#list-multiple-tasks
106
-
107
- Retrieve a list of tasks, with optional filter by date/type. Paginated with limit/offset.
108
- The return value is a ``scaleapi.Tasklist ``, which acts as a list, but also has fields
109
- for the total number of tasks, the limit and offset, and whether or not there's more.
81
+ Retrieve a list of tasks, with optional filter by stand and end date/type. Paginated with `next_token `. The return value is a `scaleapi.Tasklist `, which acts as a list, but also has fields for the total number of tasks, the limit and offset, and whether or not there's more.
110
82
111
83
.. code-block :: python
112
84
@@ -122,18 +94,174 @@ for the total number of tasks, the limit and offset, and whether or not there's
122
94
)
123
95
for task in tasks:
124
96
counter += 1
125
- print(f 'Downloading Task {counter} | { task.task_id}' )
97
+ print('Downloading Task %s | %s' % (counter, task.task_id) )
126
98
all_tasks.append(task.__dict__['param_dict'])
127
99
next_token = tasks.next_token
128
100
if next_token is None:
129
101
break
130
102
print(all_tasks)
131
103
104
+ Cancel Task
105
+ ^^^^^^^^^^^
106
+
107
+ Check `this `\_\_ for further information.
108
+
109
+ \_\_ https://docs.scale.com/reference#cancel-task
110
+
111
+ Cancel a task given its id if work has not stared on the task (task status is "que).
112
+
113
+ .. code-block :: python
114
+
115
+ task = client.cancel_task('asdfasdfasdfasdfasdfasdf')
116
+
117
+ Batches
118
+ _______
119
+
120
+ Create Batch
121
+ ^^^^^^^^^^^^
122
+
123
+ Check `this `\_\_ for further information.
124
+
125
+ \_\_ https://docs.scale.com/reference#batch-creation
126
+
127
+ .. code-block :: python
128
+
129
+ client.create_batch(
130
+ project = ' test_project' ,
131
+ callback = " http://www.example.com/callback" ,
132
+ name = ' batch_name_01_07_2021'
133
+ )
134
+
135
+ Finalize Batceh
136
+ ^^^^^^^^^^^^^^^
137
+
138
+ Check `this `\_\_ for further information.
139
+
140
+ \_\_ https://docs.scale.com/reference#batch-finalization
141
+
142
+ .. code-block :: python
143
+
144
+ client.create_batch(batch_name = ' batch_name_01_07_2021' )
145
+
146
+ Check Batch Status
147
+ ^^^^^^^^^^^^^^^^^^
148
+
149
+ Check `this `\_\_ for further information.
150
+
151
+ \_\_ https://docs.scale.com/reference#batch-status
152
+
153
+ .. code-block :: python
154
+
155
+ client.batch_status(batch_name = ' batch_name_01_07_2021' )
156
+
157
+ Retrieve Batch
158
+ ^^^^^^^^^^^^^^
159
+
160
+ Check `this `\_\_ for further information.
161
+
162
+ \_\_ https://docs.scale.com/reference#batch-retrieval
163
+
164
+ .. code-block :: python
165
+
166
+ client.get_batch( batch_name = " batch_name_01_07_2021" )
167
+
168
+ List Batches
169
+ ^^^^^^^^^^^^
170
+
171
+ Check `this `\_\_ for further information.
172
+
173
+ \_\_ https://docs.scale.com/reference#batch-list
174
+
175
+ Retrieve a list of batches
176
+
177
+ .. code-block :: python
178
+
179
+ next_token = None;
180
+ counter = 0
181
+ all_batchs =[]
182
+ while True:
183
+ batches = client.list_batches(
184
+ status = "completed"
185
+ )
186
+ for batch in batches:
187
+ counter += 1
188
+ print('Downloading Batch %s | %s | %s' % (counter, batch.name, batch.param_dict['status']))
189
+ all_batchs.append(batch.__dict__['param_dict'])
190
+ next_token = batches.next_token
191
+ if next_token is None:
192
+ break
193
+ print(all_batchs)
194
+
195
+ Projects
196
+ ________
197
+
198
+ Create Project
199
+ ^^^^^^^^^^^^^^
200
+
201
+ Check `this `\_\_ for further information.
202
+
203
+ \_\_ https://docs.scale.com/reference#project-creation
204
+
205
+ .. code-block :: python
206
+
207
+ client.create_project(
208
+ project_name = ' test_project' ,
209
+ type = ' imageannotation,
210
+ params = {' instruction' :' Please label the kittens' }
211
+ )
212
+
213
+ Retrieve Project
214
+ ^^^^^^^^^^^^^^^^
215
+
216
+ Check `this `\_\_ for further information.
217
+
218
+ \_\_ https://docs.scale.com/reference#project-retrieval
219
+
220
+ .. code-block :: python
221
+
222
+ client.get_projet(project_name = ' test_project' )
223
+
224
+ List Projects
225
+ ^^^^^^^^^^^^^
226
+
227
+ This function does not take any arguments. It will return information for every project.
228
+ Check `this `\_\_ for further information.
229
+
230
+ \_\_ https://docs.scale.com/reference#batch-list
231
+
232
+ Retrieve a list of batches
233
+
234
+ .. code-block :: python
235
+
236
+ counter = 0
237
+ projects = client.projects()
238
+ for project in projects:
239
+ counter += 1
240
+ print('Downloading project %s | %s | %s' % (counter, project['name'], project['type']))
241
+
242
+ Update Project
243
+ ^^^^^^^^^^^^^^
244
+
245
+ Check `this `\_\_ for further information.
246
+
247
+ \_\_ https://docs.scale.com/reference#project-update-parameters
248
+
249
+ Retrieve a list of batches
250
+
251
+ .. code-block :: python
252
+
253
+ data = client.update_project(
254
+ project_name='test_project',
255
+ pathc = false,
256
+ instruction='update: Please label all the stuff',
257
+
258
+ )
259
+
132
260
Error handling
133
- ==============
261
+ ______________
134
262
135
263
If something went wrong while making API calls, then exceptions will be raised automatically
136
- as a `` scaleapi.ScaleException `` or `` scaleapi.ScaleInvalidRequest ` ` runtime error. For example:
264
+ as a `scaleapi.ScaleException ` or `scaleapi.ScaleInvalidRequest ` runtime error. For example:
137
265
138
266
.. code-block :: python
139
267
@@ -144,6 +272,6 @@ as a ``scaleapi.ScaleException`` or ``scaleapi.ScaleInvalidRequest`` runtime er
144
272
print (e.message) # missing param X
145
273
146
274
Troubleshooting
147
- ===============
275
+ _______________
148
276
149
277
If you notice any problems, please email us at support@scale.com.
0 commit comments