phenoworks-sdk 0.1.0__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.
- phenoworks_sdk-0.1.0/.gitignore +14 -0
- phenoworks_sdk-0.1.0/LICENSE +202 -0
- phenoworks_sdk-0.1.0/PKG-INFO +186 -0
- phenoworks_sdk-0.1.0/README.md +160 -0
- phenoworks_sdk-0.1.0/mkdocs/async.md +62 -0
- phenoworks_sdk-0.1.0/mkdocs/cli.md +69 -0
- phenoworks_sdk-0.1.0/mkdocs/datasets.md +43 -0
- phenoworks_sdk-0.1.0/mkdocs/development.md +112 -0
- phenoworks_sdk-0.1.0/mkdocs/getting-started.md +63 -0
- phenoworks_sdk-0.1.0/mkdocs/index.md +41 -0
- phenoworks_sdk-0.1.0/mkdocs/pipelines.md +83 -0
- phenoworks_sdk-0.1.0/mkdocs/reference.md +970 -0
- phenoworks_sdk-0.1.0/mkdocs/uploads.md +45 -0
- phenoworks_sdk-0.1.0/mkdocs.yml +37 -0
- phenoworks_sdk-0.1.0/pyproject.toml +48 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/__init__.py +27 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/__main__.py +6 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/_common.py +110 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/async_client.py +663 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/async_resources.py +2689 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/auth.py +38 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/cli/__init__.py +16 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/cli/app.py +363 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/cli/authoring.py +170 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/cli/formatting.py +63 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/cli/metadata.py +627 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/client.py +649 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/errors.py +68 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/py.typed +0 -0
- phenoworks_sdk-0.1.0/src/phenoworks_sdk/resources.py +2659 -0
- phenoworks_sdk-0.1.0/tests/test_auth_and_modalities.py +133 -0
- phenoworks_sdk-0.1.0/tests/test_client.py +393 -0
- phenoworks_sdk-0.1.0/tests/test_contract.py +76 -0
- phenoworks_sdk-0.1.0/tests/test_live_workflow.py +30 -0
- phenoworks_sdk-0.1.0/tests/test_metadata.py +269 -0
- phenoworks_sdk-0.1.0/tests/test_sdk_cli.py +60 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Built from mkdocs/ with MkDocs; keep the source in version control.
|
|
2
|
+
/docs/
|
|
3
|
+
# Local configuration and analysis outputs.
|
|
4
|
+
.env
|
|
5
|
+
.env.*
|
|
6
|
+
!.env.example
|
|
7
|
+
/results/
|
|
8
|
+
/dist/
|
|
9
|
+
/build/
|
|
10
|
+
.venv/
|
|
11
|
+
__pycache__/
|
|
12
|
+
*.py[cod]
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.ruff_cache/
|
|
@@ -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,186 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: phenoworks-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package for interacting with PhenoWorks projects, datasets, pipelines, and artifacts.
|
|
5
|
+
Project-URL: Homepage, https://github.com/OpenSciML/phenoworks
|
|
6
|
+
Project-URL: Repository, https://github.com/OpenSciML/phenoworks/tree/main/packages/phenoworks-sdk
|
|
7
|
+
Project-URL: Documentation, https://github.com/OpenSciML/phenoworks/tree/main/packages/phenoworks-sdk/mkdocs
|
|
8
|
+
Project-URL: Issues, https://github.com/OpenSciML/phenoworks/issues
|
|
9
|
+
Author-email: haruiz <henryruiz22@gmail.com>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Requires-Dist: httpx<1,>=0.27
|
|
14
|
+
Provides-Extra: authoring
|
|
15
|
+
Requires-Dist: lgopy; extra == 'authoring'
|
|
16
|
+
Provides-Extra: cli
|
|
17
|
+
Requires-Dist: pydantic<3,>=2.8; extra == 'cli'
|
|
18
|
+
Requires-Dist: rich>=13; extra == 'cli'
|
|
19
|
+
Requires-Dist: typer>=0.12.3; extra == 'cli'
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pydantic<3,>=2.8; extra == 'dev'
|
|
22
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
23
|
+
Requires-Dist: rich>=13; extra == 'dev'
|
|
24
|
+
Requires-Dist: typer>=0.12.3; extra == 'dev'
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# PhenoWorks SDK
|
|
28
|
+
|
|
29
|
+
PhenoWorks SDK is a Python package for working with PhenoWorks from scripts,
|
|
30
|
+
notebooks, and the command line. It connects to your PhenoWorks server using an
|
|
31
|
+
API key and gives you access to projects, datasets, pipelines, and analysis
|
|
32
|
+
outputs with the permissions of your account.
|
|
33
|
+
|
|
34
|
+
Use it to:
|
|
35
|
+
|
|
36
|
+
- Browse projects and studies, and find datasets by modality.
|
|
37
|
+
- Upload files and manage datasets, assets, plots, and annotations.
|
|
38
|
+
- Submit pipelines, monitor their progress, and retrieve previous runs.
|
|
39
|
+
- Download artifacts for downstream analysis and machine-learning workflows.
|
|
40
|
+
- Discover analysis blocks and manage account-level installations.
|
|
41
|
+
|
|
42
|
+
The package provides `PhenoWorksClient`, `AsyncPhenoWorksClient`, and the optional
|
|
43
|
+
`phenoworks` CLI. The Python client requires Python 3.11 or later and HTTPX.
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
From the PhenoWorks repository root, install the Python package:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install ./packages/phenoworks-sdk
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
To include the CLI:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install './packages/phenoworks-sdk[cli]'
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
These commands install from this checkout. See the
|
|
60
|
+
[installation guide](mkdocs/getting-started.md) for uv workspace usage.
|
|
61
|
+
|
|
62
|
+
## Connect to PhenoWorks
|
|
63
|
+
|
|
64
|
+
Create an API key in your account settings and configure your server connection:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
export PHENOWORKS_API_URL="https://your-phenoworks-server"
|
|
68
|
+
export PHENOWORKS_API_KEY="YOUR_API_KEY"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Then list the projects available to your account:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from phenoworks_sdk import PhenoWorksClient
|
|
75
|
+
|
|
76
|
+
with PhenoWorksClient() as client:
|
|
77
|
+
projects = client.projects.list()
|
|
78
|
+
for project in projects:
|
|
79
|
+
print(project["id"], project["name"])
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
You can also pass `base_url` and `api_key` directly to the client. Keep real keys
|
|
83
|
+
out of committed code and shared notebooks.
|
|
84
|
+
|
|
85
|
+
## Find datasets by modality
|
|
86
|
+
|
|
87
|
+
Replace the example project ID with one from your account:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from phenoworks_sdk import PhenoWorksClient
|
|
91
|
+
|
|
92
|
+
with PhenoWorksClient() as client:
|
|
93
|
+
datasets = client.datasets.filter_by_modality("thermal", project_id=7)
|
|
94
|
+
for dataset in datasets:
|
|
95
|
+
print(dataset["id"], dataset["name"])
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
This filters datasets by their declared `supported_modalities`. It does not
|
|
99
|
+
verify that matching assets have been uploaded.
|
|
100
|
+
|
|
101
|
+
## Run a pipeline and download results
|
|
102
|
+
|
|
103
|
+
Save a valid pipeline definition as `pipeline.json`, using analysis blocks
|
|
104
|
+
available to your account. Replace `42` with the dataset you want to process.
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
import json
|
|
108
|
+
from pathlib import Path
|
|
109
|
+
|
|
110
|
+
from phenoworks_sdk import PhenoWorksClient
|
|
111
|
+
|
|
112
|
+
with PhenoWorksClient() as client:
|
|
113
|
+
definition = json.loads(Path("pipeline.json").read_text(encoding="utf-8"))
|
|
114
|
+
run = client.run_pipeline(dataset_id=42, json_pipeline=definition)
|
|
115
|
+
print("Pipeline:", run.pipeline_id, "Operation:", run.operation_id)
|
|
116
|
+
run.wait(timeout=3600)
|
|
117
|
+
|
|
118
|
+
for artifact in run.artifacts():
|
|
119
|
+
if artifact["status"] == "ready":
|
|
120
|
+
destination = Path("results") / f"artifact-{artifact['id']}"
|
|
121
|
+
client.artifacts.download(artifact["id"], destination)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Inspect each artifact's type, format, and metadata to select the output needed
|
|
125
|
+
for your analysis. Downloads require a local filename and refuse to overwrite
|
|
126
|
+
existing files unless `overwrite=True` is supplied.
|
|
127
|
+
|
|
128
|
+
To retrieve a previous run, use `client.pipeline_run(pipeline_id=123)` inside a
|
|
129
|
+
client context. This reconnects to the existing run without submitting work.
|
|
130
|
+
See [pipelines and artifacts](mkdocs/pipelines.md) for discovery, waiting,
|
|
131
|
+
error handling, and downloads.
|
|
132
|
+
|
|
133
|
+
## Command-line usage
|
|
134
|
+
|
|
135
|
+
The CLI uses the same server URL and API key environment variables:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
phenoworks auth me
|
|
139
|
+
phenoworks datasets filter-by-modality thermal --param project_id=7
|
|
140
|
+
phenoworks pipelines run --dataset-id 42 --file pipeline.json --wait
|
|
141
|
+
phenoworks artifacts list --param pipeline_id=123
|
|
142
|
+
phenoworks artifacts download 789 --output ./results/features.csv
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Use IDs and filenames from your own account. Run `phenoworks --help` to explore
|
|
146
|
+
commands. The [CLI guide](mkdocs/cli.md) covers uploads, JSON payloads, and
|
|
147
|
+
migration from the backend CLI.
|
|
148
|
+
|
|
149
|
+
## Documentation
|
|
150
|
+
|
|
151
|
+
- [Installation and authentication](mkdocs/getting-started.md)
|
|
152
|
+
- [Dataset discovery](mkdocs/datasets.md)
|
|
153
|
+
- [Pipelines and artifacts](mkdocs/pipelines.md)
|
|
154
|
+
- [File uploads and recovery](mkdocs/uploads.md)
|
|
155
|
+
- [Async clients and MCP integration](mkdocs/async.md)
|
|
156
|
+
- [Python API reference](mkdocs/reference.md)
|
|
157
|
+
- [Development and compatibility](mkdocs/development.md)
|
|
158
|
+
|
|
159
|
+
To preview the documentation from the SDK package directory:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
uv run --group docs mkdocs serve
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Markdown sources live in `mkdocs/`; `mkdocs build --strict` generates the site in
|
|
166
|
+
`docs/`. Generated HTML is ignored by Git.
|
|
167
|
+
|
|
168
|
+
## Development
|
|
169
|
+
|
|
170
|
+
Run tests and build the package from the repository root:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
uv run --package phenoworks-sdk --extra dev pytest packages/phenoworks-sdk/tests
|
|
174
|
+
uv build --package phenoworks-sdk
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Version 0.1 targets the API in this PhenoWorks checkout. Most SDK tests use mock
|
|
178
|
+
HTTP responses; the optional live-server test requires explicit configuration.
|
|
179
|
+
See the [development guide](mkdocs/development.md) before running it.
|
|
180
|
+
|
|
181
|
+
Contributions follow the PhenoWorks [contribution guidelines](https://github.com/OpenSciML/phenoworks/blob/main/CONTRIBUTING.md).
|
|
182
|
+
Report vulnerabilities using the project's [security policy](https://github.com/OpenSciML/phenoworks/blob/main/SECURITY.md).
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
Licensed under [Apache 2.0](LICENSE).
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# PhenoWorks SDK
|
|
2
|
+
|
|
3
|
+
PhenoWorks SDK is a Python package for working with PhenoWorks from scripts,
|
|
4
|
+
notebooks, and the command line. It connects to your PhenoWorks server using an
|
|
5
|
+
API key and gives you access to projects, datasets, pipelines, and analysis
|
|
6
|
+
outputs with the permissions of your account.
|
|
7
|
+
|
|
8
|
+
Use it to:
|
|
9
|
+
|
|
10
|
+
- Browse projects and studies, and find datasets by modality.
|
|
11
|
+
- Upload files and manage datasets, assets, plots, and annotations.
|
|
12
|
+
- Submit pipelines, monitor their progress, and retrieve previous runs.
|
|
13
|
+
- Download artifacts for downstream analysis and machine-learning workflows.
|
|
14
|
+
- Discover analysis blocks and manage account-level installations.
|
|
15
|
+
|
|
16
|
+
The package provides `PhenoWorksClient`, `AsyncPhenoWorksClient`, and the optional
|
|
17
|
+
`phenoworks` CLI. The Python client requires Python 3.11 or later and HTTPX.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
From the PhenoWorks repository root, install the Python package:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install ./packages/phenoworks-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
To include the CLI:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install './packages/phenoworks-sdk[cli]'
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
These commands install from this checkout. See the
|
|
34
|
+
[installation guide](mkdocs/getting-started.md) for uv workspace usage.
|
|
35
|
+
|
|
36
|
+
## Connect to PhenoWorks
|
|
37
|
+
|
|
38
|
+
Create an API key in your account settings and configure your server connection:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
export PHENOWORKS_API_URL="https://your-phenoworks-server"
|
|
42
|
+
export PHENOWORKS_API_KEY="YOUR_API_KEY"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then list the projects available to your account:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from phenoworks_sdk import PhenoWorksClient
|
|
49
|
+
|
|
50
|
+
with PhenoWorksClient() as client:
|
|
51
|
+
projects = client.projects.list()
|
|
52
|
+
for project in projects:
|
|
53
|
+
print(project["id"], project["name"])
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
You can also pass `base_url` and `api_key` directly to the client. Keep real keys
|
|
57
|
+
out of committed code and shared notebooks.
|
|
58
|
+
|
|
59
|
+
## Find datasets by modality
|
|
60
|
+
|
|
61
|
+
Replace the example project ID with one from your account:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from phenoworks_sdk import PhenoWorksClient
|
|
65
|
+
|
|
66
|
+
with PhenoWorksClient() as client:
|
|
67
|
+
datasets = client.datasets.filter_by_modality("thermal", project_id=7)
|
|
68
|
+
for dataset in datasets:
|
|
69
|
+
print(dataset["id"], dataset["name"])
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
This filters datasets by their declared `supported_modalities`. It does not
|
|
73
|
+
verify that matching assets have been uploaded.
|
|
74
|
+
|
|
75
|
+
## Run a pipeline and download results
|
|
76
|
+
|
|
77
|
+
Save a valid pipeline definition as `pipeline.json`, using analysis blocks
|
|
78
|
+
available to your account. Replace `42` with the dataset you want to process.
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
import json
|
|
82
|
+
from pathlib import Path
|
|
83
|
+
|
|
84
|
+
from phenoworks_sdk import PhenoWorksClient
|
|
85
|
+
|
|
86
|
+
with PhenoWorksClient() as client:
|
|
87
|
+
definition = json.loads(Path("pipeline.json").read_text(encoding="utf-8"))
|
|
88
|
+
run = client.run_pipeline(dataset_id=42, json_pipeline=definition)
|
|
89
|
+
print("Pipeline:", run.pipeline_id, "Operation:", run.operation_id)
|
|
90
|
+
run.wait(timeout=3600)
|
|
91
|
+
|
|
92
|
+
for artifact in run.artifacts():
|
|
93
|
+
if artifact["status"] == "ready":
|
|
94
|
+
destination = Path("results") / f"artifact-{artifact['id']}"
|
|
95
|
+
client.artifacts.download(artifact["id"], destination)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Inspect each artifact's type, format, and metadata to select the output needed
|
|
99
|
+
for your analysis. Downloads require a local filename and refuse to overwrite
|
|
100
|
+
existing files unless `overwrite=True` is supplied.
|
|
101
|
+
|
|
102
|
+
To retrieve a previous run, use `client.pipeline_run(pipeline_id=123)` inside a
|
|
103
|
+
client context. This reconnects to the existing run without submitting work.
|
|
104
|
+
See [pipelines and artifacts](mkdocs/pipelines.md) for discovery, waiting,
|
|
105
|
+
error handling, and downloads.
|
|
106
|
+
|
|
107
|
+
## Command-line usage
|
|
108
|
+
|
|
109
|
+
The CLI uses the same server URL and API key environment variables:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
phenoworks auth me
|
|
113
|
+
phenoworks datasets filter-by-modality thermal --param project_id=7
|
|
114
|
+
phenoworks pipelines run --dataset-id 42 --file pipeline.json --wait
|
|
115
|
+
phenoworks artifacts list --param pipeline_id=123
|
|
116
|
+
phenoworks artifacts download 789 --output ./results/features.csv
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Use IDs and filenames from your own account. Run `phenoworks --help` to explore
|
|
120
|
+
commands. The [CLI guide](mkdocs/cli.md) covers uploads, JSON payloads, and
|
|
121
|
+
migration from the backend CLI.
|
|
122
|
+
|
|
123
|
+
## Documentation
|
|
124
|
+
|
|
125
|
+
- [Installation and authentication](mkdocs/getting-started.md)
|
|
126
|
+
- [Dataset discovery](mkdocs/datasets.md)
|
|
127
|
+
- [Pipelines and artifacts](mkdocs/pipelines.md)
|
|
128
|
+
- [File uploads and recovery](mkdocs/uploads.md)
|
|
129
|
+
- [Async clients and MCP integration](mkdocs/async.md)
|
|
130
|
+
- [Python API reference](mkdocs/reference.md)
|
|
131
|
+
- [Development and compatibility](mkdocs/development.md)
|
|
132
|
+
|
|
133
|
+
To preview the documentation from the SDK package directory:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
uv run --group docs mkdocs serve
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Markdown sources live in `mkdocs/`; `mkdocs build --strict` generates the site in
|
|
140
|
+
`docs/`. Generated HTML is ignored by Git.
|
|
141
|
+
|
|
142
|
+
## Development
|
|
143
|
+
|
|
144
|
+
Run tests and build the package from the repository root:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
uv run --package phenoworks-sdk --extra dev pytest packages/phenoworks-sdk/tests
|
|
148
|
+
uv build --package phenoworks-sdk
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Version 0.1 targets the API in this PhenoWorks checkout. Most SDK tests use mock
|
|
152
|
+
HTTP responses; the optional live-server test requires explicit configuration.
|
|
153
|
+
See the [development guide](mkdocs/development.md) before running it.
|
|
154
|
+
|
|
155
|
+
Contributions follow the PhenoWorks [contribution guidelines](https://github.com/OpenSciML/phenoworks/blob/main/CONTRIBUTING.md).
|
|
156
|
+
Report vulnerabilities using the project's [security policy](https://github.com/OpenSciML/phenoworks/blob/main/SECURITY.md).
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
Licensed under [Apache 2.0](LICENSE).
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Async clients and shared services
|
|
2
|
+
|
|
3
|
+
Use `AsyncPhenoWorksClient` when your application already uses an event loop.
|
|
4
|
+
Configure your server and API key as described in [getting started](getting-started.md),
|
|
5
|
+
then await API calls. Replace the example IDs with IDs from your account.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from phenoworks_sdk import AsyncPhenoWorksClient
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async def analyze():
|
|
12
|
+
async with AsyncPhenoWorksClient() as client:
|
|
13
|
+
run = client.pipeline_run(pipeline_id=123)
|
|
14
|
+
await run.wait()
|
|
15
|
+
return await run.artifacts()
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
HTTP requests and pipeline polling are asynchronous. Local
|
|
19
|
+
file reads/writes and progress callbacks execute synchronously in bounded chunks.
|
|
20
|
+
Keep callbacks short. Async resource methods have the same names and arguments
|
|
21
|
+
as their synchronous counterparts.
|
|
22
|
+
|
|
23
|
+
Call `await analyze()` in an async application or notebook, or
|
|
24
|
+
`asyncio.run(analyze())` in a script after importing `asyncio`.
|
|
25
|
+
|
|
26
|
+
## Forward credentials in a service
|
|
27
|
+
|
|
28
|
+
Pass `auth_token="..."` instead of `api_key` to use an existing bearer token.
|
|
29
|
+
For a shared service such as MCP, use explicit forwarding mode:
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from phenoworks_sdk import AsyncPhenoWorksClient
|
|
33
|
+
|
|
34
|
+
async def find_thermal(caller_api_key: str) -> list[dict]:
|
|
35
|
+
async with AsyncPhenoWorksClient(
|
|
36
|
+
base_url="https://your-phenoworks-server", forward_auth_headers=True
|
|
37
|
+
) as client:
|
|
38
|
+
return await client.datasets.filter_by_modality(
|
|
39
|
+
"thermal", headers={"X-API-Key": caller_api_key}
|
|
40
|
+
)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
In forwarding mode, each request supplies the caller's credential. Environment
|
|
44
|
+
credentials are ignored. Resource methods, `request()`, `get()`, `post()`, `stream()`, and
|
|
45
|
+
`download()` accept request-specific `headers`. They replace fixed authentication
|
|
46
|
+
rather than merging with it, and never mutate shared transport headers. High-level
|
|
47
|
+
run/upload helpers retain their owning client's credentials; use fixed per-user
|
|
48
|
+
clients for those helpers. Do not share a fixed user client between callers.
|
|
49
|
+
|
|
50
|
+
## Downloads and progress
|
|
51
|
+
|
|
52
|
+
Async download progress callbacks may be synchronous or awaitable.
|
|
53
|
+
`save_stream()` consumes an already-open SDK response, atomically saves it, and
|
|
54
|
+
returns `path`, `size_bytes`, and `sha256`. MCP uses this helper while retaining
|
|
55
|
+
control of destination paths and progress messages.
|
|
56
|
+
|
|
57
|
+
## PhenoWorks MCP
|
|
58
|
+
|
|
59
|
+
PhenoWorks MCP uses the async SDK for API authentication, HTTP requests, and
|
|
60
|
+
streaming downloads. MCP retains responsibility for tool schemas, caller
|
|
61
|
+
context, progress messages, and destination paths. It communicates with the
|
|
62
|
+
same backend API as a Python SDK client.
|