lltp 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.
- lltp-0.1.0a1/LICENSE +201 -0
- lltp-0.1.0a1/PKG-INFO +131 -0
- lltp-0.1.0a1/README.md +101 -0
- lltp-0.1.0a1/pyproject.toml +52 -0
- lltp-0.1.0a1/setup.cfg +4 -0
- lltp-0.1.0a1/src/lltp/__init__.py +15 -0
- lltp-0.1.0a1/src/lltp/client.py +85 -0
- lltp-0.1.0a1/src/lltp/lifecycle.py +80 -0
- lltp-0.1.0a1/src/lltp/schemas/__init__.py +1 -0
- lltp-0.1.0a1/src/lltp/schemas/envelope.schema.json +1302 -0
- lltp-0.1.0a1/src/lltp/schemas/provider.schema.json +383 -0
- lltp-0.1.0a1/src/lltp/types.py +61 -0
- lltp-0.1.0a1/src/lltp/validate.py +106 -0
- lltp-0.1.0a1/src/lltp/webhook.py +91 -0
- lltp-0.1.0a1/src/lltp.egg-info/PKG-INFO +131 -0
- lltp-0.1.0a1/src/lltp.egg-info/SOURCES.txt +21 -0
- lltp-0.1.0a1/src/lltp.egg-info/dependency_links.txt +1 -0
- lltp-0.1.0a1/src/lltp.egg-info/requires.txt +9 -0
- lltp-0.1.0a1/src/lltp.egg-info/top_level.txt +1 -0
- lltp-0.1.0a1/tests/test_client_integration.py +27 -0
- lltp-0.1.0a1/tests/test_lifecycle.py +81 -0
- lltp-0.1.0a1/tests/test_validate.py +33 -0
- lltp-0.1.0a1/tests/test_webhook.py +41 -0
lltp-0.1.0a1/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of tracking or improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] LLTP Project Contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing permissions
|
|
201
|
+
and limitations under the License.
|
lltp-0.1.0a1/PKG-INFO
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lltp
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: Python reference SDK for the Lab-in-the-Loop Transport Protocol (LLTP) v0.1
|
|
5
|
+
Author: BioLM
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/BioLM/lltp-py
|
|
8
|
+
Project-URL: Repository, https://github.com/BioLM/lltp-py
|
|
9
|
+
Project-URL: Documentation, https://github.com/lltprotocol/lltp
|
|
10
|
+
Keywords: lltp,bio-ai,lab-in-the-loop
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: httpx>=0.23.0
|
|
24
|
+
Requires-Dist: jsonschema<5,>=4.0
|
|
25
|
+
Requires-Dist: importlib_resources>=5.0; python_version < "3.10"
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-httpx>=0.30.0; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# lltp-py
|
|
32
|
+
|
|
33
|
+
Python reference SDK for [LLTP](https://github.com/lltprotocol/lltp) (Lab-in-the-Loop Transport Protocol) v0.1.
|
|
34
|
+
|
|
35
|
+
**Primary audience:** authors of `{provider}-lltp` connectors (and similar
|
|
36
|
+
consumables). Agents and design tools typically talk to those connectors, not
|
|
37
|
+
this SDK directly — though nothing prevents using the client helpers that way.
|
|
38
|
+
|
|
39
|
+
Maintained by [BioLM](https://biolm.com) during protocol kickoff. See the [spec repo `GOVERNANCE.md`](https://github.com/lltprotocol/lltp/blob/main/GOVERNANCE.md) for long-term stewardship intent.
|
|
40
|
+
|
|
41
|
+
**Status:** v0.1-alpha. Message signing (`sign` / `verify`) is not yet implemented.
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install lltp
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
For local development:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install -e ".[dev]"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Requires Python >=3.8.
|
|
56
|
+
|
|
57
|
+
## Quick start
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from lltp import validate_envelope, derive_order_status
|
|
61
|
+
from lltp.client import LLTPClient
|
|
62
|
+
import json
|
|
63
|
+
|
|
64
|
+
with open("tests/fixtures/scenario-a-dna-synthesis/01-order.json") as f:
|
|
65
|
+
order = json.load(f)
|
|
66
|
+
|
|
67
|
+
validate_envelope(order)
|
|
68
|
+
print(derive_order_status(order["requirements"])) # IN_PROGRESS
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Mock provider (Scenario A)
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install -e .
|
|
75
|
+
python scripts/mock_provider.py --port 8765
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
In another shell:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from lltp.client import LLTPClient
|
|
82
|
+
import json
|
|
83
|
+
|
|
84
|
+
with open("tests/fixtures/scenario-a-dna-synthesis/01-order.json") as f:
|
|
85
|
+
order = json.load(f)
|
|
86
|
+
|
|
87
|
+
with LLTPClient() as client:
|
|
88
|
+
catalog = client.fetch_catalog("http://127.0.0.1:8765")
|
|
89
|
+
summary = client.submit_order("http://127.0.0.1:8765", order)
|
|
90
|
+
print(summary)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## API overview
|
|
94
|
+
|
|
95
|
+
| Module | Purpose |
|
|
96
|
+
|--------|---------|
|
|
97
|
+
| `lltp.validate` | `validate_envelope`, `validate_catalog` (JSON Schema) |
|
|
98
|
+
| `lltp.lifecycle` | `derive_order_status`, `merge_requirements` |
|
|
99
|
+
| `lltp.client` | `LLTPClient` — HTTP client for provider endpoints |
|
|
100
|
+
| `lltp.webhook` | `WebhookHandler` — merge STATUS/RESULT deltas |
|
|
101
|
+
|
|
102
|
+
## Tests
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pip install -e ".[dev]"
|
|
106
|
+
pytest
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Refreshing vendored schemas and fixtures
|
|
110
|
+
|
|
111
|
+
When the [spec repo](https://github.com/lltprotocol/lltp) changes:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
cp ../lltp/schema/0.1/{envelope,provider}.schema.json src/lltp/schemas/
|
|
115
|
+
cp ../lltp/examples/catalog/twist.json tests/fixtures/catalog/
|
|
116
|
+
cp ../lltp/examples/scenario-a-dna-synthesis/*.json tests/fixtures/scenario-a-dna-synthesis/
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Conformance
|
|
120
|
+
|
|
121
|
+
See [CONFORMANCE.md](CONFORMANCE.md) for what this alpha SDK implements vs deferred.
|
|
122
|
+
|
|
123
|
+
## Related repositories
|
|
124
|
+
|
|
125
|
+
- [lltp](https://github.com/lltprotocol/lltp) — protocol specification
|
|
126
|
+
- [BioLM/lltp-js](https://github.com/BioLM/lltp-js) — JavaScript/TypeScript reference SDK
|
|
127
|
+
- `{provider}-lltp` — provider connectors (separate repos; e.g. `twist-lltp`) that use this SDK
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
lltp-0.1.0a1/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# lltp-py
|
|
2
|
+
|
|
3
|
+
Python reference SDK for [LLTP](https://github.com/lltprotocol/lltp) (Lab-in-the-Loop Transport Protocol) v0.1.
|
|
4
|
+
|
|
5
|
+
**Primary audience:** authors of `{provider}-lltp` connectors (and similar
|
|
6
|
+
consumables). Agents and design tools typically talk to those connectors, not
|
|
7
|
+
this SDK directly — though nothing prevents using the client helpers that way.
|
|
8
|
+
|
|
9
|
+
Maintained by [BioLM](https://biolm.com) during protocol kickoff. See the [spec repo `GOVERNANCE.md`](https://github.com/lltprotocol/lltp/blob/main/GOVERNANCE.md) for long-term stewardship intent.
|
|
10
|
+
|
|
11
|
+
**Status:** v0.1-alpha. Message signing (`sign` / `verify`) is not yet implemented.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install lltp
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
For local development:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install -e ".[dev]"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Requires Python >=3.8.
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from lltp import validate_envelope, derive_order_status
|
|
31
|
+
from lltp.client import LLTPClient
|
|
32
|
+
import json
|
|
33
|
+
|
|
34
|
+
with open("tests/fixtures/scenario-a-dna-synthesis/01-order.json") as f:
|
|
35
|
+
order = json.load(f)
|
|
36
|
+
|
|
37
|
+
validate_envelope(order)
|
|
38
|
+
print(derive_order_status(order["requirements"])) # IN_PROGRESS
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Mock provider (Scenario A)
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install -e .
|
|
45
|
+
python scripts/mock_provider.py --port 8765
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
In another shell:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from lltp.client import LLTPClient
|
|
52
|
+
import json
|
|
53
|
+
|
|
54
|
+
with open("tests/fixtures/scenario-a-dna-synthesis/01-order.json") as f:
|
|
55
|
+
order = json.load(f)
|
|
56
|
+
|
|
57
|
+
with LLTPClient() as client:
|
|
58
|
+
catalog = client.fetch_catalog("http://127.0.0.1:8765")
|
|
59
|
+
summary = client.submit_order("http://127.0.0.1:8765", order)
|
|
60
|
+
print(summary)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## API overview
|
|
64
|
+
|
|
65
|
+
| Module | Purpose |
|
|
66
|
+
|--------|---------|
|
|
67
|
+
| `lltp.validate` | `validate_envelope`, `validate_catalog` (JSON Schema) |
|
|
68
|
+
| `lltp.lifecycle` | `derive_order_status`, `merge_requirements` |
|
|
69
|
+
| `lltp.client` | `LLTPClient` — HTTP client for provider endpoints |
|
|
70
|
+
| `lltp.webhook` | `WebhookHandler` — merge STATUS/RESULT deltas |
|
|
71
|
+
|
|
72
|
+
## Tests
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install -e ".[dev]"
|
|
76
|
+
pytest
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Refreshing vendored schemas and fixtures
|
|
80
|
+
|
|
81
|
+
When the [spec repo](https://github.com/lltprotocol/lltp) changes:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
cp ../lltp/schema/0.1/{envelope,provider}.schema.json src/lltp/schemas/
|
|
85
|
+
cp ../lltp/examples/catalog/twist.json tests/fixtures/catalog/
|
|
86
|
+
cp ../lltp/examples/scenario-a-dna-synthesis/*.json tests/fixtures/scenario-a-dna-synthesis/
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Conformance
|
|
90
|
+
|
|
91
|
+
See [CONFORMANCE.md](CONFORMANCE.md) for what this alpha SDK implements vs deferred.
|
|
92
|
+
|
|
93
|
+
## Related repositories
|
|
94
|
+
|
|
95
|
+
- [lltp](https://github.com/lltprotocol/lltp) — protocol specification
|
|
96
|
+
- [BioLM/lltp-js](https://github.com/BioLM/lltp-js) — JavaScript/TypeScript reference SDK
|
|
97
|
+
- `{provider}-lltp` — provider connectors (separate repos; e.g. `twist-lltp`) that use this SDK
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "lltp"
|
|
7
|
+
version = "0.1.0a1"
|
|
8
|
+
description = "Python reference SDK for the Lab-in-the-Loop Transport Protocol (LLTP) v0.1"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "Apache-2.0" }
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
authors = [{ name = "BioLM" }]
|
|
13
|
+
keywords = ["lltp", "bio-ai", "lab-in-the-loop"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: Apache Software License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.8",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"httpx>=0.23.0",
|
|
27
|
+
"jsonschema>=4.0,<5",
|
|
28
|
+
'importlib_resources>=5.0; python_version < "3.10"',
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dev = [
|
|
33
|
+
"pytest>=7.0",
|
|
34
|
+
"pytest-httpx>=0.30.0",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://github.com/BioLM/lltp-py"
|
|
39
|
+
Repository = "https://github.com/BioLM/lltp-py"
|
|
40
|
+
Documentation = "https://github.com/lltprotocol/lltp"
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.packages.find]
|
|
43
|
+
where = ["src"]
|
|
44
|
+
|
|
45
|
+
[tool.setuptools.package-data]
|
|
46
|
+
lltp = ["schemas/*.json"]
|
|
47
|
+
|
|
48
|
+
[tool.pytest.ini_options]
|
|
49
|
+
testpaths = ["tests"]
|
|
50
|
+
markers = [
|
|
51
|
+
"integration: tests that start or require mock provider",
|
|
52
|
+
]
|
lltp-0.1.0a1/setup.cfg
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""LLTP v0.1 — Python reference SDK."""
|
|
2
|
+
|
|
3
|
+
from lltp.lifecycle import derive_order_status, merge_requirements
|
|
4
|
+
from lltp.validate import ValidationError, validate_catalog, validate_envelope
|
|
5
|
+
|
|
6
|
+
__version__ = "0.1.0a1"
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"__version__",
|
|
10
|
+
"ValidationError",
|
|
11
|
+
"derive_order_status",
|
|
12
|
+
"merge_requirements",
|
|
13
|
+
"validate_catalog",
|
|
14
|
+
"validate_envelope",
|
|
15
|
+
]
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""HTTP client for LLTP v0.1 lab providers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict, Optional
|
|
6
|
+
from urllib.parse import urljoin
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
|
|
10
|
+
from lltp.validate import validate_catalog, validate_envelope
|
|
11
|
+
|
|
12
|
+
JsonDict = Dict[str, Any]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class LLTPClient:
|
|
16
|
+
"""Thin httpx wrapper for LLTP v0.1 provider endpoints."""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
*,
|
|
21
|
+
timeout: float = 30.0,
|
|
22
|
+
validate_outgoing: bool = True,
|
|
23
|
+
client: Optional[httpx.Client] = None,
|
|
24
|
+
) -> None:
|
|
25
|
+
self._validate_outgoing = validate_outgoing
|
|
26
|
+
self._owns_client = client is None
|
|
27
|
+
self._client = client or httpx.Client(timeout=timeout)
|
|
28
|
+
|
|
29
|
+
def close(self) -> None:
|
|
30
|
+
if self._owns_client:
|
|
31
|
+
self._client.close()
|
|
32
|
+
|
|
33
|
+
def __enter__(self) -> "LLTPClient":
|
|
34
|
+
return self
|
|
35
|
+
|
|
36
|
+
def __exit__(self, *args: object) -> None:
|
|
37
|
+
self.close()
|
|
38
|
+
|
|
39
|
+
def fetch_catalog(self, base_url: str) -> JsonDict:
|
|
40
|
+
url = self._url(base_url, "/.well-known/lltp-catalog.json")
|
|
41
|
+
response = self._client.get(url)
|
|
42
|
+
response.raise_for_status()
|
|
43
|
+
data = response.json()
|
|
44
|
+
validate_catalog(data)
|
|
45
|
+
return data
|
|
46
|
+
|
|
47
|
+
def submit_order(self, base_url: str, envelope: JsonDict) -> JsonDict:
|
|
48
|
+
if self._validate_outgoing:
|
|
49
|
+
validate_envelope(envelope)
|
|
50
|
+
url = self._url(base_url, "/.lltp/orders")
|
|
51
|
+
response = self._client.post(url, json=envelope)
|
|
52
|
+
response.raise_for_status()
|
|
53
|
+
return response.json()
|
|
54
|
+
|
|
55
|
+
def get_order(self, base_url: str, order_id: str) -> JsonDict:
|
|
56
|
+
url = self._url(base_url, f"/.lltp/orders/{order_id}")
|
|
57
|
+
response = self._client.get(url)
|
|
58
|
+
response.raise_for_status()
|
|
59
|
+
return response.json()
|
|
60
|
+
|
|
61
|
+
def get_order_status(self, base_url: str, order_id: str) -> JsonDict:
|
|
62
|
+
url = self._url(base_url, f"/.lltp/orders/{order_id}/status")
|
|
63
|
+
response = self._client.get(url)
|
|
64
|
+
response.raise_for_status()
|
|
65
|
+
return response.json()
|
|
66
|
+
|
|
67
|
+
def fulfill_requirement(
|
|
68
|
+
self,
|
|
69
|
+
base_url: str,
|
|
70
|
+
order_id: str,
|
|
71
|
+
requirement_id: str,
|
|
72
|
+
envelope: JsonDict,
|
|
73
|
+
) -> JsonDict:
|
|
74
|
+
if self._validate_outgoing:
|
|
75
|
+
validate_envelope(envelope)
|
|
76
|
+
path = f"/.lltp/orders/{order_id}/requirements/{requirement_id}"
|
|
77
|
+
url = self._url(base_url, path)
|
|
78
|
+
response = self._client.post(url, json=envelope)
|
|
79
|
+
response.raise_for_status()
|
|
80
|
+
return response.json()
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def _url(base_url: str, path: str) -> str:
|
|
84
|
+
base = base_url if base_url.endswith("/") else base_url + "/"
|
|
85
|
+
return urljoin(base, path.lstrip("/"))
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Order lifecycle derivation and requirement merge semantics."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from copy import deepcopy
|
|
6
|
+
from typing import List, Optional
|
|
7
|
+
|
|
8
|
+
from lltp.types import MUTABLE_REQUIREMENT_FIELDS, RequirementDict
|
|
9
|
+
|
|
10
|
+
_SATISFIED = frozenset({"FULFILLED", "SKIPPED"})
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def derive_order_status(
|
|
14
|
+
requirements: List[RequirementDict],
|
|
15
|
+
*,
|
|
16
|
+
cancelled: bool = False,
|
|
17
|
+
) -> str:
|
|
18
|
+
"""
|
|
19
|
+
Derive order status from the requirement set.
|
|
20
|
+
|
|
21
|
+
Implements rules in spec/0.1/lifecycle.md. SUBMITTED is not produced here —
|
|
22
|
+
it is an optional HTTP 202 courtesy only.
|
|
23
|
+
"""
|
|
24
|
+
if cancelled:
|
|
25
|
+
return "CANCELLED"
|
|
26
|
+
if any(r.get("status") == "REJECTED" for r in requirements):
|
|
27
|
+
return "FAILED"
|
|
28
|
+
if requirements and all(r.get("status") in _SATISFIED for r in requirements):
|
|
29
|
+
return "COMPLETED"
|
|
30
|
+
if any(
|
|
31
|
+
r.get("status") == "AWAITING" and r.get("assigned_to") == "REQUESTER"
|
|
32
|
+
for r in requirements
|
|
33
|
+
):
|
|
34
|
+
return "BLOCKED"
|
|
35
|
+
requester_done = all(
|
|
36
|
+
r.get("status") in _SATISFIED
|
|
37
|
+
for r in requirements
|
|
38
|
+
if r.get("assigned_to") == "REQUESTER"
|
|
39
|
+
)
|
|
40
|
+
if requester_done and any(
|
|
41
|
+
r.get("status") == "AWAITING"
|
|
42
|
+
and r.get("assigned_to") in ("PROVIDER", "EXTERNAL")
|
|
43
|
+
for r in requirements
|
|
44
|
+
):
|
|
45
|
+
return "IN_PROGRESS"
|
|
46
|
+
if any(r.get("status") == "AWAITING" for r in requirements):
|
|
47
|
+
return "ACTIVE"
|
|
48
|
+
return "ACTIVE"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def merge_requirements(
|
|
52
|
+
current: List[RequirementDict],
|
|
53
|
+
delta: List[RequirementDict],
|
|
54
|
+
) -> List[RequirementDict]:
|
|
55
|
+
"""
|
|
56
|
+
Merge STATUS delta entries into the current requirement list.
|
|
57
|
+
|
|
58
|
+
Upserts by requirement_id. Only mutable fields from the delta are applied
|
|
59
|
+
to existing entries; immutable template fields are preserved.
|
|
60
|
+
"""
|
|
61
|
+
by_id = {r["requirement_id"]: deepcopy(r) for r in current}
|
|
62
|
+
for patch in delta:
|
|
63
|
+
req_id = patch["requirement_id"]
|
|
64
|
+
if req_id not in by_id:
|
|
65
|
+
by_id[req_id] = deepcopy(patch)
|
|
66
|
+
continue
|
|
67
|
+
existing = by_id[req_id]
|
|
68
|
+
for key, value in patch.items():
|
|
69
|
+
if key in MUTABLE_REQUIREMENT_FIELDS or key == "requirement_id":
|
|
70
|
+
if key == "requirement_id":
|
|
71
|
+
continue
|
|
72
|
+
existing[key] = value
|
|
73
|
+
elif key not in existing:
|
|
74
|
+
existing[key] = value
|
|
75
|
+
return list(by_id.values())
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def requirement_index(requirements: List[RequirementDict]) -> dict:
|
|
79
|
+
"""Map requirement_id -> requirement dict."""
|
|
80
|
+
return {r["requirement_id"]: r for r in requirements}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Vendored LLTP JSON Schema files."""
|