Skip to navigation

Getting Started with the V3 Python SDK

Install, authenticate, and make your first request with the Benchling V3 Python SDK.

The Benchling V3 Python SDK provides typed access to the Benchling V3 API from Python.

V3 SDK vs. V2 SDK

This is the SDK for Benchling’s V3 API. It is a separate package (benchling-v3-sdk-python) from the V2 benchling-sdk. Install the one that matches the API version you are calling.

Installation

pip install benchling-v3-sdk-python

Authenticate

You can authenticate with an API key, OAuth client credentials, or a bearer token you already have.

To use an API key, get one from your Benchling account settings:

from benchling_v3_sdk import Benchling
benchling = Benchling(
base_url="https://yourcompany.benchling.com",
api_key="<your-api-key>",
early_access="true",
)

To use OAuth client credentials, create an app to generate a client ID and secret:

from benchling_v3_sdk import Benchling
benchling = Benchling(
base_url="https://yourcompany.benchling.com",
client_id="<your-client-id>",
client_secret="<your-client-secret>",
early_access="true",
)

The SDK requests a new client-credentials token when the current one is close to expiring.

To pass a bearer token you already have, set token. The short-lived V3 API Explorer token from your user settings works here. It expires after 15 minutes.

A string is sent on every request and stops working when that token expires. When the script outlives the token, pass a function. The SDK calls it before each request and sends whatever it returns.

from benchling_v3_sdk import Benchling
def current_access_token() -> str:
# Called before each request. Return a token that is still valid.
return "<your-bearer-token>"
benchling = Benchling(
base_url="https://yourcompany.benchling.com",
token=current_access_token, # or token="<your-bearer-token>"
early_access="true",
)

Pass early_access="true" on any of these clients to enable beta endpoints.

Make a request

Now make a request. For example, to list DNA sequences:

for dna_sequence in benchling.dna_sequence.list():
print(dna_sequence.id, dna_sequence.name)

Next steps

  • For code walkthroughs of the interactions you’re most likely to need, including pagination, async tasks, error handling, and retries, see Common SDK Interactions and Examples.
  • For the full set of resources and methods that the SDK exposes, see the API reference.

Support

For questions or issues, contact Benchling support.