3131.. code-block :: python
3232
3333 import scaleapi
34- client = scaleapi.ScaleClient(' YOUR_API_KEY_HERE' )
34+
35+ client = scaleapi.ScaleClient(" YOUR_API_KEY_HERE" )
3536
3637 Tasks
3738_____
@@ -62,22 +63,28 @@ __ https://docs.scale.com/reference
6263
6364 from scaleapi.tasks import TaskType
6465
65- client.create_task(
66- TaskType.ImageAnnotation,
67- project = ' test_project' ,
66+ payload = dict (
67+ project = " test_project" ,
6868 callback_url = " http://www.example.com/callback" ,
69- instruction = " Draw a box around each baby cow and big cow." ,
69+ instruction = " Draw a box around each baby cow and big cow." ,
7070 attachment_type = " image" ,
7171 attachment = " http://i.imgur.com/v4cBreD.jpg" ,
72+ unique_id = " c235d023af73" ,
7273 geometries = {
7374 " box" : {
74- " objects_to_annotate" : [" Baby Cow" , " Big Cow" ],
75- " min_height" : 10 ,
76- " min_width" : 10
75+ " objects_to_annotate" : [" Baby Cow" , " Big Cow" ],
76+ " min_height" : 10 ,
77+ " min_width" : 10 ,
7778 }
78- }
79+ },
7980 )
8081
82+ try :
83+ client.create_task(TaskType.ImageAnnotation, ** payload)
84+ except ScaleDuplicateTask as err:
85+ print (err.message) # If unique_id is already used for a different task
86+
87+
8188 Retrieve a task
8289^^^^^^^^^^^^^^^
8390
@@ -87,8 +94,8 @@ __ https://docs.scale.com/reference#retrieve-tasks
8794
8895.. code-block :: python
8996
90- task = client.get_task(' 30553edd0b6a93f8f05f0fee' )
91- print(task.status) # Task status (' pending', ' completed', ' error', ' canceled' )
97+ task = client.get_task(" 30553edd0b6a93f8f05f0fee" )
98+ print(task.status) # Task status (" pending", " completed", " error", " canceled" )
9299 print(task.response) # If task is complete
93100
94101 List Tasks
@@ -100,9 +107,9 @@ Retrieve a list of `Task` objects, with filters for: ``project_name``, ``batch_n
100107
101108``get_tasks() `` is a **generator ** method and yields ``Task `` objects.
102109
103- ` A generator is another type of function, returns an iterable that you can loop over like a list.
110+ * A generator is another type of function, returns an iterable that you can loop over like a list.
104111However, unlike lists, generators do not store the content in the memory.
105- That helps you to process a large number of objects without increasing memory usage. `
112+ That helps you to process a large number of objects without increasing memory usage. *
106113
107114If you will iterate through the tasks and process them once, using a generator is the most efficient method.
108115However, if you need to process the list of tasks multiple times, you can wrap the generator in a ``list(...) ``
@@ -157,9 +164,9 @@ __ https://docs.scale.com/reference#batch-creation
157164.. code-block :: python
158165
159166 client.create_batch(
160- project = ' test_project' ,
167+ project = " test_project" ,
161168 callback = " http://www.example.com/callback" ,
162- name = ' batch_name_01_07_2021'
169+ name = " batch_name_01_07_2021"
163170 )
164171
165172 Finalize Batch
@@ -171,7 +178,11 @@ __ https://docs.scale.com/reference#batch-finalization
171178
172179.. code-block :: python
173180
174- client.finalize_batch(batch_name = ' batch_name_01_07_2021' )
181+ client.finalize_batch(batch_name = " batch_name_01_07_2021" )
182+
183+ # Alternative method
184+ batch = client.get_batch(batch_name = " batch_name_01_07_2021" )
185+ batch.finalize()
175186
176187 Check Batch Status
177188^^^^^^^^^^^^^^^^^^
@@ -182,10 +193,10 @@ __ https://docs.scale.com/reference#batch-status
182193
183194.. code-block :: python
184195
185- client.batch_status(batch_name = ' batch_name_01_07_2021' )
196+ client.batch_status(batch_name = " batch_name_01_07_2021" )
186197
187198 # Alternative via Batch.get_status()
188- batch = client.get_batch(' batch_name_01_07_2021' )
199+ batch = client.get_batch(" batch_name_01_07_2021" )
189200 batch.get_status() # Refreshes tasks_{status} attributes of Batch
190201 print (batch.tasks_pending, batch.tasks_completed)
191202
@@ -198,7 +209,7 @@ __ https://docs.scale.com/reference#batch-retrieval
198209
199210.. code-block :: python
200211
201- client.get_batch(batch_name = ' batch_name_01_07_2021' )
212+ client.get_batch(batch_name = " batch_name_01_07_2021" )
202213
203214 List Batches
204215^^^^^^^^^^^^
@@ -207,9 +218,9 @@ Retrieve a list of Batches. Optional parameters are ``project_name``, ``batch_st
207218
208219``get_batches() `` is a **generator ** method and yields ``Batch `` objects.
209220
210- ` A generator is another type of function, returns an iterable that you can loop over like a list.
221+ * A generator is another type of function, returns an iterable that you can loop over like a list.
211222However, unlike lists, generators do not store the content in the memory.
212- That helps you to process a large number of objects without increasing memory usage. `
223+ That helps you to process a large number of objects without increasing memory usage. *
213224
214225When wrapped in a ``list(...) `` statement, it returns a list of Batches by loading them into the memory.
215226
@@ -229,7 +240,7 @@ __ https://docs.scale.com/reference#batch-list
229240 counter = 0
230241 for batch in batches:
231242 counter += 1
232- print(f' Downloading batch {counter} | {batch.name} | {batch.project}' )
243+ print(f" Downloading batch {counter} | {batch.name} | {batch.project}" )
233244
234245 # Alternative for accessing as a Batch list
235246 batch_list = list(batches)
@@ -247,12 +258,16 @@ __ https://docs.scale.com/reference#project-creation
247258
248259.. code-block :: python
249260
250- client.create_project(
251- project_name = ' test_project' ,
252- type = ' imageannotation,
253- params = {' instruction' :' Please label the kittens' }
261+ from scaleapi.tasks import TaskType
262+
263+ project = client.create_project(
264+ project_name = " Test_Project" ,
265+ task_type = TaskType.ImageAnnotation,
266+ params = {" instruction" : " Please label the kittens" },
254267 )
255268
269+ print (project.name) # Test_Project
270+
256271 Retrieve Project
257272^^^^^^^^^^^^^^^^
258273
@@ -262,7 +277,7 @@ __ https://docs.scale.com/reference#project-retrieval
262277
263278.. code-block :: python
264279
265- client.get_project(project_name = ' test_project' )
280+ client.get_project(project_name = " test_project" )
266281
267282 List Projects
268283^^^^^^^^^^^^^
@@ -290,9 +305,9 @@ __ https://docs.scale.com/reference#project-update-parameters
290305.. code-block :: python
291306
292307 data = client.update_project(
293- project_name=' test_project' ,
308+ project_name=" test_project" ,
294309 patch = false,
295- instruction=' update: Please label all the stuff' ,
310+ instruction=" update: Please label all the stuff" ,
296311 )
297312
298313 Error handling
@@ -319,7 +334,7 @@ For example:
319334 from scaleapi.exceptions import ScaleException
320335
321336 try :
322- client.create_task(TaskType.TextCollection, attachment = ' Some parameters are missing.' )
337+ client.create_task(TaskType.TextCollection, attachment = " Some parameters are missing." )
323338 except ScaleException as err:
324339 print (err.code) # 400
325340 print (err.message) # Parameter is invalid, reason: "attachments" is required
0 commit comments