Benchling API Client

2.0.427 · active · verified Wed Apr 15

An autogenerated Python client library providing programmatic access to the Benchling API. It is generated from Benchling's OpenAPI specification, ensuring it stays up-to-date with the latest API changes. As an auto-generated client, its release cadence typically follows updates to the underlying API specification.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Benchling API client using environment variables for credentials and make a simple call to list users. It highlights the required host format and accessing specific API endpoints via the client instance. The code includes a check for unset environment variables.

import os
from benchling_api_client import BenchlingClient, Configuration

# Benchling API keys are typically associated with a specific tenant.
# Set these environment variables: BENCHLING_TENANT_NAME, BENCHLING_API_KEY
# Example host: https://my-org.benchling.com/api/v2

benchling_tenant = os.environ.get('BENCHLING_TENANT_NAME', 'YOUR_TENANT_NAME')
benchling_api_key = os.environ.get('BENCHLING_API_KEY', 'YOUR_API_KEY')

if benchling_tenant == 'YOUR_TENANT_NAME' or benchling_api_key == 'YOUR_API_KEY':
    print("Please set BENCHLING_TENANT_NAME and BENCHLING_API_KEY environment variables.")
else:
    try:
        configuration = Configuration(
            host=f"https://{benchling_tenant}.benchling.com/api/v2",
            api_key={'api_key': benchling_api_key}
        )

        with BenchlingClient(configuration=configuration) as client:
            # The client provides direct access to various API namespaces (e.g., users, aa_sequences)
            users_api = client.users
            # List users, retrieving only the first page for demonstration
            response = users_api.list_users(page_size=1)
            
            if response.users:
                print(f"Found user: {response.users[0].handle} (ID: {response.users[0].id})")
            else:
                print("No users found or accessible with this API key.")

    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →