improved

SDK Version 1.19.0 Release Notes

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 methods get_canvas_by_id and get_session_by_id now have an optional returning 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 returned AsyncTaskLink. More about this feature:
    • TaskHelper is defined as a subclass of AsyncTaskLink, so any existing code that expected an AsyncTaskLink 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 method DnaSequenceService.bulk_create returns TaskHelper[class BulkCreateDnaSequencesAsyncTaskResponse].
    • You can retrieve this object by calling the wait_for_response method of the TaskHelper. This is similar to the previous mechanism of calling benchling.tasks.wait_for_task, except that instead of returning an AsyncTask whose response property is a plain dict, it returns the appropriate response class for the API method. If the task fails, wait_for_response throws a TaskFailureException instead of returning.
    • Some methods return TaskHelper[EmptyTaskResponse] because the task does not return any specific results.
    • A few methods still return AsyncTaskLink instead of TaskHelper, because the API specification does not yet have a named schema for the shape of their results. You can continue to use the old wait_for_task and AsyncTask 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 mean setuptools was not being used, since pkg_resources is a dependency of setuptools). This has been fixed.

Version 1.19.0 of the Benchling SDK is now live! Find the SDK in PyPI .