improved
SDK Version 1.19.0 Release Notes
about 1 month 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_id
andget_session_by_id
now have an optionalreturning
parameter. 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:TaskHelper
is defined as a subclass ofAsyncTaskLink
, so any existing code that expected anAsyncTaskLink
will still work.- The type parameter
T
is the type that the response will eventually be, once the task is completed. For instance, the API methodDnaSequenceService.bulk_create
returnsTaskHelper[class BulkCreateDnaSequencesAsyncTaskResponse]
. - You can retrieve this object by calling the
wait_for_response
method of theTaskHelper
. This is similar to the previous mechanism of callingbenchling.tasks.wait_for_task
, except that instead of returning anAsyncTask
whoseresponse
property is a plain dict, it returns the appropriate response class for the API method. If the task fails,wait_for_response
throws aTaskFailureException
instead of returning. - Some methods return
TaskHelper[EmptyTaskResponse]
because the task does not return any specific results. - A few methods still return
AsyncTaskLink
instead 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_task
andAsyncTask
in 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_task(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 meansetuptools
was not being used, sincepkg_resources
is a dependency ofsetuptools
). This has been fixed.
Version 1.19.0 of the Benchling SDK is now live! Find the SDK in PyPI .