involve-benchling 0.1.0a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- involve_benchling-0.1.0a1/.github/workflows/ci.yml +33 -0
- involve_benchling-0.1.0a1/.gitignore +18 -0
- involve_benchling-0.1.0a1/.pre-commit-config.yaml +14 -0
- involve_benchling-0.1.0a1/.test.env.template +7 -0
- involve_benchling-0.1.0a1/AGENTS.md +56 -0
- involve_benchling-0.1.0a1/CLAUDE.md +1 -0
- involve_benchling-0.1.0a1/CONTRIBUTING.md +75 -0
- involve_benchling-0.1.0a1/LICENSE +202 -0
- involve_benchling-0.1.0a1/Makefile +20 -0
- involve_benchling-0.1.0a1/PKG-INFO +192 -0
- involve_benchling-0.1.0a1/README.md +154 -0
- involve_benchling-0.1.0a1/SECURITY.md +17 -0
- involve_benchling-0.1.0a1/docs/CHANGELOG.md +28 -0
- involve_benchling-0.1.0a1/docs/design/config-as-code.md +334 -0
- involve_benchling-0.1.0a1/pyproject.toml +84 -0
- involve_benchling-0.1.0a1/src/involve_benchling/__init__.py +49 -0
- involve_benchling-0.1.0a1/src/involve_benchling/cache/__init__.py +160 -0
- involve_benchling-0.1.0a1/src/involve_benchling/cache/backends.py +164 -0
- involve_benchling-0.1.0a1/src/involve_benchling/cache/policy.py +39 -0
- involve_benchling-0.1.0a1/src/involve_benchling/core/__init__.py +6 -0
- involve_benchling-0.1.0a1/src/involve_benchling/core/client.py +78 -0
- involve_benchling-0.1.0a1/src/involve_benchling/core/config.py +80 -0
- involve_benchling-0.1.0a1/src/involve_benchling/core/readonly.py +106 -0
- involve_benchling-0.1.0a1/src/involve_benchling/dataframes.py +180 -0
- involve_benchling-0.1.0a1/src/involve_benchling/errors.py +48 -0
- involve_benchling-0.1.0a1/src/involve_benchling/py.typed +0 -0
- involve_benchling-0.1.0a1/src/involve_benchling/resolve/__init__.py +111 -0
- involve_benchling-0.1.0a1/src/involve_benchling/testing/__init__.py +14 -0
- involve_benchling-0.1.0a1/src/involve_benchling/testing/plugin.py +49 -0
- involve_benchling-0.1.0a1/src/involve_benchling/testing/tracker.py +59 -0
- involve_benchling-0.1.0a1/src/involve_benchling/tools/__init__.py +8 -0
- involve_benchling-0.1.0a1/src/involve_benchling/version.py +1 -0
- involve_benchling-0.1.0a1/tests/__init__.py +0 -0
- involve_benchling-0.1.0a1/tests/conftest.py +5 -0
- involve_benchling-0.1.0a1/tests/fixtures/__init__.py +13 -0
- involve_benchling-0.1.0a1/tests/fixtures/builders.py +139 -0
- involve_benchling-0.1.0a1/tests/fixtures/cache.py +63 -0
- involve_benchling-0.1.0a1/tests/fixtures/config.py +47 -0
- involve_benchling-0.1.0a1/tests/fixtures/fakes.py +110 -0
- involve_benchling-0.1.0a1/tests/fixtures/tenant.py +100 -0
- involve_benchling-0.1.0a1/tests/integration/__init__.py +0 -0
- involve_benchling-0.1.0a1/tests/integration/test_smoke.py +27 -0
- involve_benchling-0.1.0a1/tests/unit/__init__.py +0 -0
- involve_benchling-0.1.0a1/tests/unit/conftest.py +6 -0
- involve_benchling-0.1.0a1/tests/unit/test_cache.py +181 -0
- involve_benchling-0.1.0a1/tests/unit/test_config.py +51 -0
- involve_benchling-0.1.0a1/tests/unit/test_dataframes.py +87 -0
- involve_benchling-0.1.0a1/tests/unit/test_readonly.py +176 -0
- involve_benchling-0.1.0a1/tests/unit/test_resolve.py +53 -0
- involve_benchling-0.1.0a1/tests/unit/test_tracker.py +26 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
cache: pip
|
|
24
|
+
- name: Install
|
|
25
|
+
run: pip install -e ".[dev]"
|
|
26
|
+
- name: Lint
|
|
27
|
+
run: |
|
|
28
|
+
ruff check src tests
|
|
29
|
+
ruff format --check src tests
|
|
30
|
+
- name: Type check
|
|
31
|
+
run: mypy
|
|
32
|
+
- name: Unit tests
|
|
33
|
+
run: pytest --cov --cov-report=term-missing
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*.egg-info/
|
|
4
|
+
dist/
|
|
5
|
+
build/
|
|
6
|
+
venv/
|
|
7
|
+
.venv/
|
|
8
|
+
.mypy_cache/
|
|
9
|
+
.ruff_cache/
|
|
10
|
+
.pytest_cache/
|
|
11
|
+
.coverage
|
|
12
|
+
htmlcov/
|
|
13
|
+
.test.env
|
|
14
|
+
.env
|
|
15
|
+
.DS_Store
|
|
16
|
+
.benchling-cache/
|
|
17
|
+
CLAUDE.local.md
|
|
18
|
+
.claude/settings.local.json
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
rev: v0.8.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: ruff
|
|
6
|
+
args: [--fix]
|
|
7
|
+
- id: ruff-format
|
|
8
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
9
|
+
rev: v5.0.0
|
|
10
|
+
hooks:
|
|
11
|
+
- id: end-of-file-fixer
|
|
12
|
+
- id: trailing-whitespace
|
|
13
|
+
- id: check-added-large-files
|
|
14
|
+
- id: detect-private-key
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Agent guide
|
|
2
|
+
|
|
3
|
+
Instructions for AI coding agents working in this repository. Human
|
|
4
|
+
contributors should read [CONTRIBUTING.md](CONTRIBUTING.md), which this file
|
|
5
|
+
follows.
|
|
6
|
+
|
|
7
|
+
## Project
|
|
8
|
+
|
|
9
|
+
involve-benchling is a typed Python library over `benchling-v3-sdk-python`.
|
|
10
|
+
It adds caching, name resolution, dataframes, read-only clients and pytest
|
|
11
|
+
utilities, and it never hides the SDK. Functions accept and return SDK
|
|
12
|
+
objects.
|
|
13
|
+
|
|
14
|
+
| Path | Contents |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `src/involve_benchling/core/` | `BenchlingConfig`, `connect()`, the read-only `httpx` transport |
|
|
17
|
+
| `src/involve_benchling/cache/` | Cache facade, policy, memory and disk backends |
|
|
18
|
+
| `src/involve_benchling/resolve/` | Generic lookups over any `list` resource |
|
|
19
|
+
| `src/involve_benchling/dataframes.py` | pandas adapters (optional extra) |
|
|
20
|
+
| `src/involve_benchling/testing/` | pytest plugin and `ResourceTracker` |
|
|
21
|
+
| `tests/fixtures/` | Shared fakes, builders and a canned tenant |
|
|
22
|
+
| `docs/design/` | Design documents for planned modules |
|
|
23
|
+
|
|
24
|
+
## Commands
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
make install # editable install with dev extras
|
|
28
|
+
make lint # ruff
|
|
29
|
+
make type # mypy --strict
|
|
30
|
+
make test # unit tests; no credentials
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Run `make lint type test` before you finish. All three must pass.
|
|
34
|
+
|
|
35
|
+
## Rules
|
|
36
|
+
|
|
37
|
+
- Pass SDK models through. Don't add wrapper dataclasses for Benchling
|
|
38
|
+
resources.
|
|
39
|
+
- Keep helpers generic over resources rather than writing one per resource.
|
|
40
|
+
- Type and document every public function. mypy runs in strict mode.
|
|
41
|
+
- Never use pickle. Cached values are JSON.
|
|
42
|
+
- Core depends only on the SDK, `httpx` and `pydantic`. Anything else is an
|
|
43
|
+
optional extra imported inside the function that needs it.
|
|
44
|
+
- Unit tests must not touch the network or need credentials. Use the
|
|
45
|
+
fixtures in `tests/fixtures/` instead of new fakes.
|
|
46
|
+
- Mark tests that need a tenant `@pytest.mark.integration`. Never run them
|
|
47
|
+
unless asked, because they write to the tenant.
|
|
48
|
+
- Add a `docs/CHANGELOG.md` entry for every user-visible change.
|
|
49
|
+
- Never commit `.test.env`, credentials, tenant URLs or data from a real
|
|
50
|
+
tenant. Examples use `example.benchling.com`.
|
|
51
|
+
|
|
52
|
+
## Style
|
|
53
|
+
|
|
54
|
+
- Line length is 100. Ruff formats the code.
|
|
55
|
+
- Write docstrings in plain present tense, saying what the function does.
|
|
56
|
+
- Keep comments short and about current behaviour.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for helping. Bug reports, fixes and new helpers are all welcome. For a
|
|
4
|
+
larger change, open an issue first so we can agree on the shape before you
|
|
5
|
+
write it.
|
|
6
|
+
|
|
7
|
+
## Ground rules
|
|
8
|
+
|
|
9
|
+
- **Pass through SDK models.** Never introduce wrapper dataclasses for
|
|
10
|
+
Benchling resources.
|
|
11
|
+
- **Generic over bespoke.** Prefer helpers that work on any resource to
|
|
12
|
+
per-resource code.
|
|
13
|
+
- **Every public function is typed and documented.** CI runs mypy
|
|
14
|
+
`--strict` and ruff.
|
|
15
|
+
- **Unit tests run with zero credentials.** Anything touching a real
|
|
16
|
+
tenant is marked `@pytest.mark.integration`.
|
|
17
|
+
- **Optional dependencies stay optional.** Import them inside the function
|
|
18
|
+
that needs them and declare them as an extra in `pyproject.toml`.
|
|
19
|
+
|
|
20
|
+
## Setup
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
python -m venv venv && source venv/bin/activate
|
|
24
|
+
make install # pip install -e ".[dev]"
|
|
25
|
+
pre-commit install # optional: ruff and file checks on every commit
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Checks
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
make lint # ruff check and ruff format --check
|
|
32
|
+
make type # mypy --strict
|
|
33
|
+
make test # unit tests, no credentials needed
|
|
34
|
+
make test-all # unit and integration tests
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Integration tests need a tenant. Copy `.test.env.template` to `.test.env`
|
|
38
|
+
and fill it in. Use a sandbox tenant, because the tests create and archive
|
|
39
|
+
resources.
|
|
40
|
+
|
|
41
|
+
## Pull requests
|
|
42
|
+
|
|
43
|
+
A pull request needs:
|
|
44
|
+
|
|
45
|
+
- passing CI
|
|
46
|
+
- a test for every behaviour change
|
|
47
|
+
- an entry under `docs/CHANGELOG.md`
|
|
48
|
+
- docstrings for any new public function
|
|
49
|
+
|
|
50
|
+
Keep each pull request to one change.
|
|
51
|
+
|
|
52
|
+
## Test fixtures
|
|
53
|
+
|
|
54
|
+
Shared fixtures live in `tests/fixtures/` and are registered by
|
|
55
|
+
`tests/conftest.py`. Use them instead of defining fakes inside test files.
|
|
56
|
+
|
|
57
|
+
| Module | Provides |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `builders` | V3 wire-format payloads (`text_value`, `link_value`, `custom_entity_payload`, ...) and real SDK models built from them (`custom_entity`, `field_definitions`) |
|
|
60
|
+
| `fakes` | `FakeResource` (applies `name_any_of`, `id_any_of`, `schema_eq` and records calls), `UnfilteredResource`, `FakeSchemaResource`, `FakeClock` |
|
|
61
|
+
| `config` | `clean_env`, `api_key_env`, `api_key_config`, `oauth_config` |
|
|
62
|
+
| `cache` | `clock` (freezes cache time; `clock.advance(s)` expires entries), `cache_dir`, `memory_backend`, `disk_backend`, `tiered_backend`, `cache_policy`, `memory_cache`, `disk_cache` |
|
|
63
|
+
| `tenant` | A canned plasmid tenant: `plasmid_field_definitions`, `plasmids`, `entity_resource`, `unfiltered_resource`, `schema_resource` |
|
|
64
|
+
|
|
65
|
+
Unit tests run with every `BENCHLING_*` variable removed
|
|
66
|
+
(`tests/unit/conftest.py`). Use `clock` rather than `time.sleep` for TTL
|
|
67
|
+
tests.
|
|
68
|
+
|
|
69
|
+
These fixtures are private to this repo. The shipped
|
|
70
|
+
`involve_benchling.testing` plugin provides the live-tenant fixtures
|
|
71
|
+
(`benchling_config`, `benchling`, `benchling_tracker`) for integration tests.
|
|
72
|
+
|
|
73
|
+
## Security
|
|
74
|
+
|
|
75
|
+
Report vulnerabilities privately, as described in [SECURITY.md](SECURITY.md).
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
.PHONY: install lint type test test-all cov
|
|
2
|
+
|
|
3
|
+
install:
|
|
4
|
+
pip install -e ".[dev]"
|
|
5
|
+
|
|
6
|
+
lint:
|
|
7
|
+
ruff check src tests
|
|
8
|
+
ruff format --check src tests
|
|
9
|
+
|
|
10
|
+
type:
|
|
11
|
+
mypy
|
|
12
|
+
|
|
13
|
+
test:
|
|
14
|
+
pytest
|
|
15
|
+
|
|
16
|
+
test-all:
|
|
17
|
+
pytest -m ""
|
|
18
|
+
|
|
19
|
+
cov:
|
|
20
|
+
pytest --cov --cov-report=term-missing
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: involve-benchling
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: Caching, name resolution, dataframes, read-only clients and testing utilities for the Benchling V3 Python SDK.
|
|
5
|
+
Project-URL: Homepage, https://github.com/involvedata/involve-benchling
|
|
6
|
+
Project-URL: Repository, https://github.com/involvedata/involve-benchling.git
|
|
7
|
+
Project-URL: Issues, https://github.com/involvedata/involve-benchling/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/involvedata/involve-benchling/blob/main/docs/CHANGELOG.md
|
|
9
|
+
Author: Involve Data
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: api,benchling,biology,biotech,laboratory,lims,sdk
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: benchling-v3-sdk-python>=15.0.0
|
|
24
|
+
Requires-Dist: httpx>=0.27
|
|
25
|
+
Requires-Dist: pydantic>=2.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
28
|
+
Requires-Dist: pandas>=2.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pre-commit>=3.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
33
|
+
Provides-Extra: pandas
|
|
34
|
+
Requires-Dist: pandas>=2.0; extra == 'pandas'
|
|
35
|
+
Provides-Extra: testing
|
|
36
|
+
Requires-Dist: pytest>=8.0; extra == 'testing'
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
|
|
39
|
+
# involve-benchling
|
|
40
|
+
|
|
41
|
+
**The toolkit the official Benchling SDK doesn't give you.**
|
|
42
|
+
|
|
43
|
+
A thin, composable layer over [`benchling-v3-sdk-python`](https://pypi.org/project/benchling-v3-sdk-python/)
|
|
44
|
+
— it never hides the SDK. You keep Benchling's typed models, pagination,
|
|
45
|
+
and full API surface; this library adds what's missing around them.
|
|
46
|
+
|
|
47
|
+
> **Status: alpha.** The API may change before 1.0. See the [changelog](https://github.com/involvedata/involve-benchling/blob/main/docs/CHANGELOG.md).
|
|
48
|
+
|
|
49
|
+
involve-benchling is an independent project. It is not affiliated with or endorsed by
|
|
50
|
+
Benchling, Inc.
|
|
51
|
+
|
|
52
|
+
## Why
|
|
53
|
+
|
|
54
|
+
The Benchling V3 SDK is a complete API client. Teams that build on it tend to
|
|
55
|
+
rebuild the same pieces around it:
|
|
56
|
+
|
|
57
|
+
| Pillar | Module | What it gives you |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| **Caching** | `involve_benchling.cache` | Tiered (memory + disk, shared across processes), pickle-free JSON serialisation of SDK models, per-category TTLs. Reference data (schemas, dropdowns, registries) goes from ~500ms to <1ms. |
|
|
60
|
+
| **Resolution** | `involve_benchling.resolve` | Generic `get_by_name` / `find_one` over *any* V3 resource, with typed `NotFoundError` / `AmbiguousError` instead of silent first-match. |
|
|
61
|
+
| **DataFrames** | `involve_benchling.dataframes` | Explicit `to_dataframe()` that expands V3 `schemaFields` into one typed, named column per field. Optional extra. |
|
|
62
|
+
| **Read-only clients** | `involve_benchling.core.readonly` | A client that cannot change tenant data, enforced in the HTTP transport below every SDK method. |
|
|
63
|
+
| **Testing** | `involve_benchling.testing` | pytest plugin: env-based config/client fixtures and a `benchling_tracker` that cleans up every resource a test created — even on failure. |
|
|
64
|
+
|
|
65
|
+
## Install
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install involve-benchling # core (the SDK and its own dependencies)
|
|
69
|
+
pip install "involve-benchling[pandas]" # + dataframe support
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Quick start
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from involve_benchling import BenchlingConfig, connect, resolve
|
|
76
|
+
|
|
77
|
+
config = BenchlingConfig.from_env() # BENCHLING_BASE_URL, BENCHLING_API_KEY, ...
|
|
78
|
+
benchling = connect(config) # a plain benchling_v3_sdk.Benchling
|
|
79
|
+
|
|
80
|
+
# The SDK is right there — use it directly:
|
|
81
|
+
for seq in benchling.dna_sequence.list(page_size=50):
|
|
82
|
+
print(seq.id, seq.name)
|
|
83
|
+
|
|
84
|
+
# Resolution with typed errors, over any resource:
|
|
85
|
+
plasmid = resolve.get_by_name(benchling.custom_entity, "pEX-001")
|
|
86
|
+
schema_id = resolve.get_id_by_name(benchling.entity_schema, "Plasmid")
|
|
87
|
+
|
|
88
|
+
# Caching reference data:
|
|
89
|
+
from involve_benchling.cache import BenchlingCache
|
|
90
|
+
|
|
91
|
+
cache = BenchlingCache.from_policy(config.cache, namespace=config.base_url)
|
|
92
|
+
schemas = cache.get_or_fetch(
|
|
93
|
+
"schemas:entity",
|
|
94
|
+
category="schema",
|
|
95
|
+
fetch=lambda: list(benchling.entity_schema.list()),
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
# Analysis-ready dataframes:
|
|
99
|
+
from involve_benchling.dataframes import field_names, to_dataframe
|
|
100
|
+
|
|
101
|
+
df = to_dataframe(
|
|
102
|
+
benchling.custom_entity.list(schema_eq=schema_id),
|
|
103
|
+
field_names=field_names(benchling.custom_entity_schema, schema_id),
|
|
104
|
+
)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Read-only clients
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
config = BenchlingConfig.from_env(read_only=True) # or BENCHLING_READ_ONLY=1
|
|
111
|
+
benchling = connect(config)
|
|
112
|
+
|
|
113
|
+
benchling.folder.list() # fine
|
|
114
|
+
benchling.folder.create(name="x", parent_id="lib_1")
|
|
115
|
+
# ReadOnlyViolationError: Read-only client blocked POST .../api/v3/folder/items
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The check sits in the `httpx` transport, below every SDK method. A
|
|
119
|
+
read-only client sends only `GET`, `HEAD` and `OPTIONS`, plus `POST` to the
|
|
120
|
+
OAuth token exchange and `/api/v3/search`, which read without changing data.
|
|
121
|
+
Raw-response calls and methods added in later SDK releases are covered without
|
|
122
|
+
a list of write verbs to maintain.
|
|
123
|
+
|
|
124
|
+
### Cache storage
|
|
125
|
+
|
|
126
|
+
The disk tier defaults to `.benchling-cache/` in the working directory. It
|
|
127
|
+
creates the directory and its files readable only by the current user, and
|
|
128
|
+
writes a `.gitignore` into it so the cache is never committed. Cached
|
|
129
|
+
responses can hold sensitive data, so point `CachePolicy.directory` somewhere
|
|
130
|
+
protected.
|
|
131
|
+
|
|
132
|
+
The cache is keyed by `namespace` (usually the tenant URL), not by
|
|
133
|
+
credential. Don't share one cache directory between credentials with
|
|
134
|
+
different access, or a narrower credential can read what a broader one
|
|
135
|
+
cached.
|
|
136
|
+
|
|
137
|
+
### Testing your own Benchling integrations
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
import pytest
|
|
141
|
+
|
|
142
|
+
@pytest.mark.integration
|
|
143
|
+
def test_my_workflow(benchling, benchling_tracker):
|
|
144
|
+
entity = benchling.custom_entity.create(...)
|
|
145
|
+
benchling_tracker.track(
|
|
146
|
+
f"custom_entity {entity.id}",
|
|
147
|
+
lambda: benchling.custom_entity.update(
|
|
148
|
+
entity.id, archived=True, archive_reason="Made in error"
|
|
149
|
+
),
|
|
150
|
+
)
|
|
151
|
+
# ... test things; cleanup happens even if assertions fail
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Design principles
|
|
155
|
+
|
|
156
|
+
1. **Pass through SDK models.** No parallel dataclass universe; functions
|
|
157
|
+
accept and return `benchling_v3_sdk` types.
|
|
158
|
+
2. **Generic over bespoke.** One `get_by_name` for 100+ resources, not
|
|
159
|
+
one service class per resource.
|
|
160
|
+
3. **Explicit APIs.** No magic kwargs, no hidden state. Strictly typed
|
|
161
|
+
(`py.typed`, mypy `--strict`).
|
|
162
|
+
4. **Everything optional is an extra.** Core depends on the SDK and
|
|
163
|
+
nothing else.
|
|
164
|
+
5. **No pickle.** Cached values are JSON documents; a shared cache
|
|
165
|
+
directory is never a code-execution vector.
|
|
166
|
+
|
|
167
|
+
## Roadmap
|
|
168
|
+
|
|
169
|
+
- `config` — configuration as code: export, plan and apply tenant configuration from
|
|
170
|
+
YAML state files. Design: [`docs/design/config-as-code.md`](https://github.com/involvedata/involve-benchling/blob/main/docs/design/config-as-code.md).
|
|
171
|
+
- `tools.discovery` — tenant environment discovery: schemas, dropdowns,
|
|
172
|
+
relationships; ERD and documentation generation.
|
|
173
|
+
- `tools.entry_search` — entry search with automatic user/project
|
|
174
|
+
resolution.
|
|
175
|
+
- Cache invalidation hooks for write operations.
|
|
176
|
+
- Async parity helpers for `AsyncBenchling`.
|
|
177
|
+
|
|
178
|
+
## Development
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
python -m venv venv && source venv/bin/activate
|
|
182
|
+
make install # pip install -e ".[dev]"
|
|
183
|
+
make lint type test
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Integration tests need a tenant. Copy `.test.env.template` to `.test.env`,
|
|
187
|
+
fill it in, then run `pytest -m integration`. See [CONTRIBUTING.md](https://github.com/involvedata/involve-benchling/blob/main/CONTRIBUTING.md)
|
|
188
|
+
for the full workflow.
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
Apache-2.0 © Involve Data
|