Improved
SDK Version 1.19.0 Release Notes
about 1 year ago by Eli Bishop
Version 1.19.0 of the Benchling SDK adds a more convenient way to get the results of an asynchronous task, adds missing API parameters, and fixes a dependency problem.
What’s Changing?
Added
- In
benchling.v2.stable.apps, the methodsget_canvas_by_idandget_session_by_idnow have an optionalreturningparameter. This already existed in the API, but had not been available in the SDK. - Added the class
benchling.helpers.task_helpers.TaskHelper[T]. This generic class is now returned by most API methods that previously returnedAsyncTaskLink. More about this feature:TaskHelperis defined as a subclass ofAsyncTaskLink, so any existing code that expected anAsyncTaskLinkwill still work.- The type parameter
Tis the type that the response will eventually be, once the task is completed. For instance, the API methodDnaSequenceService.bulk_createreturnsTaskHelper[class BulkCreateDnaSequencesAsyncTaskResponse]. - You can retrieve this object by calling the
wait_for_responsemethod of theTaskHelper. This is similar to the previous mechanism of callingbenchling.tasks.wait_for_task, except that instead of returning anAsyncTaskwhoseresponseproperty is a plain dict, it returns the appropriate response class for the API method. If the task fails,wait_for_responsethrows aTaskFailureExceptioninstead of returning. - Some methods return
TaskHelper[EmptyTaskResponse]because the task does not return any specific results. - A few methods still return
AsyncTaskLinkinstead ofTaskHelper, because the API specification does not yet have a named schema for the shape of their results. You can continue to use the oldwait_for_taskandAsyncTaskin these cases.
Here is an example of using the old method versus the new method for getting the result of DnaSequenceService.bulk_create. The old method parses the response as arbitrary JSON; the new method lets you use the appropriate model classes.
# OLD
task = benchling.dna_sequences.bulk_create(my_dna_sequences)
completed_task = benchling.tasks.wait_for_task(task.task_id, max_wait_seconds=30)
result_sequences = completed_task.response["dnaSequences"]
# type of result_sequences is list[dict]
# NEW
task = benchling.dna_sequences.bulk_create(my_dna_sequences)
response = task.wait_for_response(max_wait_seconds=30)
result_sequences = response.dna_sequences
# type of result_sequences is list[DnaSequence]Fixed
- The SDK had an undeclared and unnecessary dependency on
pkg_resources, causing an error if that package was not present (which would most likely meansetuptoolswas not being used, sincepkg_resourcesis a dependency ofsetuptools). This has been fixed.
Version 1.19.0 of the Benchling SDK is now live! Find the SDK in PyPI .
