Python SDK

Installation

python3 is required for the installation. Either setup python3 as the default or use virtualenv.

Use pip to install the taskmonk SDK

pip3 install taskmonk-sdk

QuickStart

The quickest way to get started with Taskmonk is use the upload file and download of output features as shown below. The projectId will be provided by the annotation partner

 1 from taskmonk import TaskMonkClient
 2 import json
 3 import logging
 4 from time import sleep
 5
 6 level    = logging.DEBUG
 7 format   = '  %(message)s'
 8 handlers = [logging.FileHandler('logger.log'), logging.StreamHandler()]
 9
10 logging.basicConfig(level = level, format = format, handlers = handlers)
11
12 project_id = "project_id"
13
14 client = TaskMonkClient("https://preprod.taskmonk.io",
15     project_id = project_id,
16     client_id = 'client_id',
17     client_secret= 'client_secret')
18
19
20 #
21 # Create the taxonomy
22 #
23 taxonomy_id = client.create_taxonomy('taxonomy_name')
24 logging.debug('Created taxonomy %s', taxonomy_id)
25
26 #
27 # Upload taxonomy categories
28 #
29 upload_result = client.import_taxonomy(taxonomy_id, '/Users/taskmonk/taxonomy.xlsx')
30 logging.debug('Import taxonomy result = %s', upload_result)
31
32 #
33 # Create the batch with the default parameters
34 #
35 batch_id = client.create_batch("batchname")
36 logging.debug('Created batch %s', batch_id)
37
38 #
39 # Upload the tasks from the csv file
40 #
41 upload_job_id = client.upload_tasks(batch_id, '/Users/taskmonk/tmp.csv', 'CSV')
42 logging.debug("upload job_id = %s", upload_job_id)
43
44 #
45 # Check the progress of the upload job
46 #
47 upload_job_progress = client.get_job_progress(upload_job_id)
48 logging.debug("Job Progess = %s", upload_job_progress)
49
50 #
51 # Wait till the upload job is complete
52 #
53 while (not client.is_job_complete(upload_job_id)):
54     logging.debug("waiting for job to complete")
55     sleep(1)
56 logging.debug("Upload tasks is complete")
57
58 #
59 # Check the status of the batch
60 #
61 batch_status = client.get_batch_status(batch_id)
62 logging.debug("Batch Status = %s", batch_status)
63
64 #
65 # Wait till the batch is completed by the annotation partners
66 #
67 while (not client.is_batch_complete(batch_id)):
68     logging.debug("waiting for batch to complete")
69     sleep(1)
70
71 logging.debug("Batch annotation is complete")
72
73 #
74 # Get batch output
75 #
76 batch_output = client.get_batch_output(batch_id, '/tmp/output.csv', output_format = 'CSV')
77 logging.debug('batch_output = %s', batch_output)

Documentation

SDK documentation is available at REST API.