1- ===================
1+ =====================
22Scale AI | Python SDK
3- ===================
4-
3+ =====================
54
65Installation
7- ============
6+ ____________
7+
88.. code-block :: bash
99
1010 $ pip install --upgrade scaleapi
11-
11+
1212 Note: We strongly suggest using `scaleapi ` with Python version 2.7.9 or greater due to SSL issues with prior versions.
1313
1414Usage
15- =====
15+ _____
16+
1617.. code-block :: python
1718
1819 import scaleapi
1920 client = scaleapi.ScaleClient(' YOUR_API_KEY_HERE' )
2021
2122 Tasks
22- =====
23+ _____
2324
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
2526about the json response (task_id, status...).
2627
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.
2829
29- .. _documentation : https://scale.com/docs
30+ .. \ _documentation: https://docs. scale.com/reference#task-object
3031
3132 The following endpoints for tasks are available:
3233
33- Create Categorization Task
34- ==========================
34+ Create Task
35+ ^^^^^^^^^^^
3536
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.
3739
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
5641
5742.. code-block :: python
5843
5944 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+ }
6956 }
70- }
7157 )
7258
7359 Retrieve task
74- =============
60+ ^^^^^^^^^^^^^
7561
76- Check `this `__ for further information.
62+ Check `this `\_\_ for further information.
7763
78- __ https://docs.scale.com/reference#retrieve-tasks
64+ \_\_ https://docs.scale.com/reference#retrieve-tasks
7965
8066Retrieve a task given its id.
8167
8268.. code-block :: python
8369
8470 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
8673
87- Cancel task
88- ===========
74+ List Tasks
75+ ^^^^^^^^^^
8976
90- Check `this `__ for further information.
77+ Check `this `\_\_ for further information.
9178
92- __ https://docs.scale.com/reference#cancel-task
79+ \_\_ https://docs.scale.com/reference#list-multiple-tasks
9380
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.
11082
11183.. code-block :: python
11284
@@ -122,18 +94,174 @@ for the total number of tasks, the limit and offset, and whether or not there's
12294 )
12395 for task in tasks:
12496 counter += 1
125- print(f 'Downloading Task {counter} | { task.task_id}' )
97+ print('Downloading Task %s | %s' % (counter, task.task_id) )
12698 all_tasks.append(task.__dict__['param_dict'])
12799 next_token = tasks.next_token
128100 if next_token is None:
129101 break
130102 print(all_tasks)
131103
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+
132260Error handling
133- ==============
261+ ______________
134262
135263If 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:
137265
138266.. code-block :: python
139267
@@ -144,6 +272,6 @@ as a ``scaleapi.ScaleException`` or ``scaleapi.ScaleInvalidRequest`` runtime er
144272 print (e.message) # missing param X
145273
146274 Troubleshooting
147- ===============
275+ _______________
148276
149277If you notice any problems, please email us at
[email protected] .
0 commit comments