{"id":"benchling-integration","name":"benchling-integration","summary":"レジストリエンティティ、インベントリ、ELNエントリー、ワークフロー、Benchlingアプリ、データウェアハウスクエリのためのBenchling Python SDKとREST API連携。","body":"# Benchling Integration\n\n## Overview\n\nBenchling is a cloud platform for life sciences R&D. Access registry entities (DNA, RNA, proteins), inventory, electronic lab notebooks, and workflows programmatically via the Python SDK and REST API.\n\n**Version note:** Examples target **benchling-sdk 1.25.0** (latest stable on PyPI). Docs: [benchling.com/sdk-docs](https://benchling.com/sdk-docs/). Platform guide: [docs.benchling.com](https://docs.benchling.com/).\n\n## When to Use This Skill\n\nThis skill should be used when:\n- Working with Benchling's Python SDK or REST API\n- Managing biological sequences (DNA, RNA, proteins) and registry entities\n- Automating inventory operations (samples, containers, locations, transfers)\n- Creating or querying electronic lab notebook entries\n- Building workflow automations or Benchling Apps\n- Syncing data between Benchling and external systems\n- Querying the Benchling Data Warehouse for analytics\n- Setting up event-driven integrations with AWS EventBridge\n\n## Core Capabilities\n\nSeven capability areas, each with code, are in\n[references/core_capabilities.md](references/core_capabilities.md):\n\n1. **Authentication and setup** — API key and OAuth app auth; see\n   [references/authentication.md](references/authentication.md).\n2. **Registry and entity management** — DNA and AA sequences, custom entities, schemas,\n   and registration.\n3. **Inventory management** — containers, boxes, plates, locations, and transfers.\n4. **Notebook and documentation** — entries, day-to-day notes, and structured tables.\n5. **Workflows and automation** — tasks, flowcharts, and assay runs.\n6. **Events and integration** — EventBridge subscriptions; see\n   [references/eventbridge.md](references/eventbridge.md).\n7. **Data warehouse and analytics** — SQL access to the warehouse.\n\nEndpoint and SDK detail is in\n[references/api_endpoints.md](references/api_endpoints.md) and\n[references/sdk_reference.md](references/sdk_reference.md).\n\n## Best Practices\n\n### Error Handling\n\nThe SDK automatically retries failed requests:\n```python\n# Automatic retry for 429, 502, 503, 504 status codes\n# Up to 5 retries with exponential backoff\n# Customize retry behavior if needed\nfrom benchling_sdk.retry import RetryStrategy\n\nbenchling = Benchling(\n    url=tenant_url,\n    auth_method=ApiKeyAuth(api_key),\n    retry_strategy=RetryStrategy(max_retries=3),\n)\n```\n\n### Pagination Efficiency\n\nUse generators for memory-efficient pagination:\n```python\n# Generator-based iteration\nfor page in benchling.dna_sequences.list():\n    for sequence in page:\n        process(sequence)\n\n# Check estimated count without loading all pages\ntotal = benchling.dna_sequences.list().estimated_count()\n```\n\n### Schema Fields Helper\n\nUse the `fields()` helper for custom schema fields:\n```python\n# Convert dict to Fields object\ncustom_fields = benchling.models.fields({\n    \"concentration\": \"100 ng/μL\",\n    \"date_prepared\": \"2025-10-20\",\n    \"notes\": \"High quality prep\"\n})\n```\n\n### Forward Compatibility\n\nThe SDK handles unknown enum values and types gracefully:\n- Unknown enum values are preserved\n- Unrecognized polymorphic types return `UnknownType`\n- Allows working with newer API versions\n\n### Security Considerations\n\n- Never commit API keys or OAuth secrets to version control\n- Read only named environment variables (`BENCHLING_TENANT_URL`, `BENCHLING_API_KEY`, etc.)\n- Route network calls exclusively to your tenant URL\n- Rotate keys if compromised; use OAuth for multi-user production apps\n- Grant minimal necessary permissions for apps in the Developer Console\n\n## Resources\n\n### references/\n\nDetailed reference documentation for in-depth information:\n\n- **authentication.md** - Comprehensive authentication guide including OIDC, security best practices, and credential management\n- **sdk_reference.md** - Detailed Python SDK reference with advanced patterns, examples, and all entity types\n- **api_endpoints.md** - REST API endpoint reference for direct HTTP calls without the SDK\n- **eventbridge.md** - EventBridge setup, event payload schema, rule examples, Lambda handler, validation, and recovery\n\nLoad these references as needed for specific integration requirements.\n\n## Common Use Cases\n\n**1. Bulk Entity Import:**\n```python\n# Import multiple sequences from FASTA file\nfrom Bio import SeqIO\n\nfor record in SeqIO.parse(\"sequences.fasta\", \"fasta\"):\n    benchling.dna_sequences.create(\n        DnaSequenceCreate(\n            name=record.id,\n            bases=str(record.seq),\n            is_circular=False,\n            folder_id=\"fld_abc123\"\n        )\n    )\n```\n\n**2. Inventory Audit:**\n```python\n# List all containers in a specific location\ncontainers = benchling.containers.list(\n    parent_storage_id=\"box_abc123\"\n)\n\nfor page in containers:\n    for container in page:\n        print(f\"{container.name}: {container.barcode}\")\n```\n\n**3. Workflow Automation:**\n```python\n# Update all pending tasks for a workflow\ntasks = benchling.workflow_tasks.list(\n    workflow_id=\"wf_abc123\",\n    status=\"pending\"\n)\n\nfor page in tasks:\n    for task in page:\n        # Perform automated checks\n        if auto_validate(task):\n            benchling.workflow_tasks.update(\n                task_id=task.id,\n                workflow_task=WorkflowTaskUpdate(\n                    status_id=\"status_complete\"\n                )\n            )\n```\n\n**4. Data Export:**\n```python\n# Export all sequences with specific properties\nsequences = benchling.dna_sequences.list()\nexport_data = []\n\nfor page in sequences:\n    for seq in page:\n        if seq.schema_id == \"target_schema_id\":\n            export_data.append({\n                \"id\": seq.id,\n                \"name\": seq.name,\n                \"bases\": seq.bases,\n                \"length\": len(seq.bases)\n            })\n\n# Save to CSV or database\nimport csv\nwith open(\"sequences.csv\", \"w\") as f:\n    writer = csv.DictWriter(f, fieldnames=export_data[0].keys())\n    writer.writeheader()\n    writer.writerows(export_data)\n```\n\n## Additional Resources\n\n- **Official Documentation:** https://docs.benchling.com\n- **Python SDK Reference:** https://benchling.com/sdk-docs/\n- **API Reference:** https://benchling.com/api/reference\n- **Support:** [email protected]","author":"@K-Dense-AI","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/K-Dense-AI/scientific-agent-skills/tree/main/skills/benchling-integration","license":"MIT","category":"document","lang":"en","tokens":1349,"stars":0,"calls30d":1,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"references/api_endpoints.md","size":14308,"sha256":"4a5c8565551089485ea6033554b8c8427766b752bf987cafc8d3582c19c47808"},{"path":"references/authentication.md","size":10780,"sha256":"277a3fffdd9ec7e5c767168ef6b2af040229015f451895e96f57cfa4d2493d39"},{"path":"references/core_capabilities.md","size":10214,"sha256":"87d3c9d4e4fe7c137954fe79d1e3ce18f302f5a0c016f5a82d1089fc790bee72"},{"path":"references/eventbridge.md","size":8647,"sha256":"6e89cfdcc0c150a0bf466630f7d0ea7da3e1734607afdb08f9df5bf00b774606"},{"path":"references/sdk_reference.md","size":17778,"sha256":"8c382608201505fd448d4cabfc2541a662f892a53e3f78a9de9440d4d7c6a026"}],"requires":{"mcp":[],"tools":["Read Write Edit Bash"]},"safety":{"flags":[],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":["benchling.com","docs.benchling.com","tenant.benchling.com","your-tenant.benchling.com"]}}