Benchling SDK for Python

1.24.1 · active · verified Thu Apr 16

The Benchling SDK for Python provides a robust interface for interacting with the Benchling Platform, enabling programmatic access to its various functionalities including entities, assays, results, and workflows. It simplifies API interactions, handles authentication, and supports common data structures. The current version is 1.24.1, with frequent releases to keep pace with platform updates.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the BenchlingClient using environment variables for authentication and fetches a list of entries as a basic connectivity test. Ensure `BENCHLING_API_KEY` and `BENCHLING_API_URL` are set.

import os
from benchling_sdk.benchling import BenchlingClient

# Ensure BENCHLING_API_KEY and BENCHLING_API_URL are set as environment variables
api_key = os.environ.get("BENCHLING_API_KEY", "")
api_url = os.environ.get("BENCHLING_API_URL", "")

if not api_key or not api_url:
    print("Please set BENCHLING_API_KEY and BENCHLING_API_URL environment variables.")
    # In a real application, you might raise an exception or configure differently.
    exit(1)

try:
    # Initialize the client. It automatically picks up BENCHLING_API_KEY and BENCHLING_API_URL.
    benchling_client = BenchlingClient()

    # Example: List up to 3 entries (requires appropriate permissions)
    entries = benchling_client.entries.list(page_size=3).items

    print(f"Successfully connected to Benchling. Found {len(entries)} entries.")
    for entry in entries:
        print(f"  - Entry ID: {entry.id}, Name: {entry.name}")

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

view raw JSON →