kalbio 0.2.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.
- kalbio-0.2.0/PKG-INFO +289 -0
- kalbio-0.2.0/README.md +268 -0
- kalbio-0.2.0/kalbio/__init__.py +1 -0
- kalbio-0.2.0/kalbio/_kaleidoscope_model.py +111 -0
- kalbio-0.2.0/kalbio/activities.py +1202 -0
- kalbio-0.2.0/kalbio/client.py +463 -0
- kalbio-0.2.0/kalbio/dashboards.py +276 -0
- kalbio-0.2.0/kalbio/entity_fields.py +474 -0
- kalbio-0.2.0/kalbio/entity_types.py +188 -0
- kalbio-0.2.0/kalbio/exports.py +126 -0
- kalbio-0.2.0/kalbio/helpers.py +52 -0
- kalbio-0.2.0/kalbio/imports.py +89 -0
- kalbio-0.2.0/kalbio/labels.py +88 -0
- kalbio-0.2.0/kalbio/programs.py +96 -0
- kalbio-0.2.0/kalbio/property_fields.py +81 -0
- kalbio-0.2.0/kalbio/record_views.py +191 -0
- kalbio-0.2.0/kalbio/records.py +1173 -0
- kalbio-0.2.0/kalbio/workspace.py +315 -0
- kalbio-0.2.0/pyproject.toml +36 -0
kalbio-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: kalbio
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Python client for Kaleidoscope API
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Ahmed Elnaiem
|
|
7
|
+
Author-email: ahmed@kaleidoscope.bio
|
|
8
|
+
Requires-Python: >=3.10,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Dist: pydantic (>=2.9.2,<3.0.0)
|
|
15
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
16
|
+
Project-URL: Documentation, https://api.docs.kaleidoscope.bio
|
|
17
|
+
Project-URL: Homepage, https://github.com/kaleidoscope-tech/kalbio
|
|
18
|
+
Project-URL: Repository, https://github.com/kaleidoscope-tech/kalbio
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Kalbio
|
|
22
|
+
|
|
23
|
+
<!-- **Source Code**: [https://github.com/kaleidoscope-tech/kalbio](https://github.com/kaleidoscope-tech/kalbio)
|
|
24
|
+
|
|
25
|
+
--- -->
|
|
26
|
+
|
|
27
|
+
Kalbio is a Python Client library for building applications with the Kaleidoscope platform.
|
|
28
|
+
|
|
29
|
+
## Key features
|
|
30
|
+
|
|
31
|
+
- **Type-safe API Client**: Built with Pydantic models for full type safety and IDE autocomplete support
|
|
32
|
+
- **Intuitive Resource Management**: Clean, object-oriented interface for programs, activities, records, and more
|
|
33
|
+
- **Advanced Search & Filtering**: Powerful query capabilities with type-safe filter operators
|
|
34
|
+
- **File Upload Support**: Direct file upload to record fields with support for multiple file types
|
|
35
|
+
- **Comprehensive Coverage**: Access all Kaleidoscope platform resources through a unified client
|
|
36
|
+
- **Bulk Operations**: Import and export capabilities for efficient data management
|
|
37
|
+
|
|
38
|
+
## Requirements
|
|
39
|
+
|
|
40
|
+
- [Python](https://docs.python.org/3/) 3.12+
|
|
41
|
+
- [Pydantic](https://docs.pydantic.dev/) 2.9.2+
|
|
42
|
+
- [Requests](https://requests.readthedocs.io/) 2.32.3+
|
|
43
|
+
|
|
44
|
+
<!--
|
|
45
|
+
TODO
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
Clone the repository and install the client in editable mode:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
git clone https://github.com/kaleidoscope-tech/kalbio.git
|
|
53
|
+
cd kalbio
|
|
54
|
+
pip install -e .
|
|
55
|
+
```
|
|
56
|
+
-->
|
|
57
|
+
|
|
58
|
+
## Authentication
|
|
59
|
+
|
|
60
|
+
Set your API credentials as environment variables before running examples:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
export KALEIDOSCOPE_API_CLIENT_ID="your_client_id"
|
|
64
|
+
export KALEIDOSCOPE_API_CLIENT_SECRET="your_client_secret"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Example
|
|
68
|
+
|
|
69
|
+
### Create it
|
|
70
|
+
|
|
71
|
+
Create a file `main.py` with:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from kalbio.client import KaleidoscopeClient
|
|
75
|
+
from kalbio.activities import ActivityStatusEnum
|
|
76
|
+
|
|
77
|
+
# Initialize the client using environment variables
|
|
78
|
+
client = KaleidoscopeClient()
|
|
79
|
+
|
|
80
|
+
# # Or with explicit arguements
|
|
81
|
+
# client = KaleidoscopeClient(
|
|
82
|
+
# client_id="your_api_client_id",
|
|
83
|
+
# client_secret="your_api_client_secret"
|
|
84
|
+
# )
|
|
85
|
+
|
|
86
|
+
# Work with activities
|
|
87
|
+
activities = client.activities.get_activities()
|
|
88
|
+
for activity in activities:
|
|
89
|
+
print(f"Activity: {activity.title} - Status: {activity.status.value}")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Run it
|
|
93
|
+
|
|
94
|
+
Run the program with:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
python main.py
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Output:
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
Activity: Experiment 1 - Status: to do
|
|
104
|
+
Activity: Task 1 - Status: to do
|
|
105
|
+
Activity: Drug Tests - Status: in progress
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Check it
|
|
109
|
+
|
|
110
|
+
You now have a fully functional Kaleidoscope API client.
|
|
111
|
+
|
|
112
|
+
## Features
|
|
113
|
+
|
|
114
|
+
### Intuitive API Design
|
|
115
|
+
|
|
116
|
+
Work with resources naturally:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
# Records
|
|
120
|
+
record = client.records.get_record_by_id("record-uuid")
|
|
121
|
+
|
|
122
|
+
if record:
|
|
123
|
+
record.add_value(
|
|
124
|
+
field_id="field-uuid",
|
|
125
|
+
content="Experiment result",
|
|
126
|
+
activity_id="activity-uuid"
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
# Entity Types
|
|
130
|
+
entity_types = client.entity_types.get_types()
|
|
131
|
+
compound_type = client.entity_types.get_type_by_name("Compound")
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### File Upload Support
|
|
135
|
+
|
|
136
|
+
Upload files directly to records:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
# Upload a file to a record field
|
|
140
|
+
with open("experiment_data.csv", "rb") as file:
|
|
141
|
+
record.update_field_file(
|
|
142
|
+
field_id="data-field-id",
|
|
143
|
+
file_name="experiment_data.csv",
|
|
144
|
+
file_data=file,
|
|
145
|
+
file_type="text/csv",
|
|
146
|
+
activity_id="activity-uuid"
|
|
147
|
+
)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Comprehensive Resource Management
|
|
151
|
+
|
|
152
|
+
Kalbio provides services for all Kaleidoscope resources:
|
|
153
|
+
|
|
154
|
+
- **Programs**: Organize your work
|
|
155
|
+
- **Activities**: Tasks, experiments, projects, etc.
|
|
156
|
+
- **Records**: Structured data storage
|
|
157
|
+
- **Entity Types**: Define your data schemas
|
|
158
|
+
- **Entity Fields**: Manage field definitions
|
|
159
|
+
- **Labels**: Tag and categorize
|
|
160
|
+
- **Imports/Exports**: Bulk data operations
|
|
161
|
+
- **Workspace**: User and group management
|
|
162
|
+
|
|
163
|
+
## Interactive Documentation
|
|
164
|
+
|
|
165
|
+
### Available Services
|
|
166
|
+
|
|
167
|
+
Once you have a client instance, you have access to:
|
|
168
|
+
|
|
169
|
+
| Service | Description |
|
|
170
|
+
| ---------------------- | ------------------------------------------- |
|
|
171
|
+
| `client.programs` | Program management |
|
|
172
|
+
| `client.activities` | Activities (tasks, experiments, projects) |
|
|
173
|
+
| `client.records` | Record CRUD operations |
|
|
174
|
+
| `client.entity_types` | Entity type definitions |
|
|
175
|
+
| `client.entity_fields` | Field definitions (key fields, data fields) |
|
|
176
|
+
| `client.labels` | Label management |
|
|
177
|
+
| `client.imports` | Import operations and templates |
|
|
178
|
+
| `client.exports` | Export operations |
|
|
179
|
+
| `client.workspace` | Workspace, users, and groups |
|
|
180
|
+
|
|
181
|
+
### Activity Management
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
# Create an activity
|
|
185
|
+
new_activity = client.activities.create_activity(
|
|
186
|
+
title="Synthesis Experiment",
|
|
187
|
+
activity_type="experiment",
|
|
188
|
+
program_ids=["program-uuid"],
|
|
189
|
+
assigned_user_ids=["user-uuid"]
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
if new_activity:
|
|
193
|
+
# Update activity status
|
|
194
|
+
new_activity.update(status=ActivityStatusEnum.IN_PROGRESS)
|
|
195
|
+
|
|
196
|
+
# Add records to activity
|
|
197
|
+
new_activity.add_records(["record-uuid-1", "record-uuid-2"])
|
|
198
|
+
|
|
199
|
+
# Get activity data
|
|
200
|
+
record_data = new_activity.get_record_data()
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Record Operations
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
# Get record by ID
|
|
207
|
+
record = client.records.get_record_by_id("record-uuid")
|
|
208
|
+
|
|
209
|
+
if record:
|
|
210
|
+
# Add a value
|
|
211
|
+
record.add_value(
|
|
212
|
+
field_id="field-uuid",
|
|
213
|
+
content="High purity sample",
|
|
214
|
+
activity_id="activity-uuid"
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
# Get field value
|
|
218
|
+
value = record.get_value_content(field_id="field-uuid")
|
|
219
|
+
|
|
220
|
+
# Get values for specific activity
|
|
221
|
+
activity_values = record.get_activity_data(activity_id="activity-uuid")
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Full Example
|
|
225
|
+
|
|
226
|
+
Here's a complete workflow example:
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
# Initialize client
|
|
230
|
+
client = KaleidoscopeClient(
|
|
231
|
+
KALEIDOSCOPE_API_CLIENT_ID,
|
|
232
|
+
KALEIDOSCOPE_API_CLIENT_SECRET,
|
|
233
|
+
"https://api.kaleidoscope.bio",
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
# 1. Get or create a program
|
|
237
|
+
programs = client.programs.get_programs()
|
|
238
|
+
program = programs[0] if programs else None
|
|
239
|
+
|
|
240
|
+
if program:
|
|
241
|
+
print(f"Working with program: {program.title}")
|
|
242
|
+
|
|
243
|
+
# 2. Get entity types
|
|
244
|
+
entity_types = client.entity_types.get_types()
|
|
245
|
+
compound_type = next(
|
|
246
|
+
(et for et in entity_types if et.slice_name == "Compound"),
|
|
247
|
+
None
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
if compound_type:
|
|
251
|
+
# 3. Search for records
|
|
252
|
+
record_ids = client.records.search_records(
|
|
253
|
+
entity_slice_id=compound_type.id,
|
|
254
|
+
limit=10
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
print(f"Found {len(record_ids)} compound records")
|
|
258
|
+
|
|
259
|
+
# 4. Get detailed record information
|
|
260
|
+
if record_ids:
|
|
261
|
+
record = client.records.get_record_by_id(record_ids[0])
|
|
262
|
+
assert record
|
|
263
|
+
print(f"Record: {record.record_identifier}")
|
|
264
|
+
|
|
265
|
+
# 5. Create an activity
|
|
266
|
+
activity = client.activities.create_activity(
|
|
267
|
+
title="Quality Check",
|
|
268
|
+
activity_type="task",
|
|
269
|
+
program_ids=[program.id]
|
|
270
|
+
)
|
|
271
|
+
assert activity
|
|
272
|
+
|
|
273
|
+
# 6. Add data to record
|
|
274
|
+
record.add_value(
|
|
275
|
+
field_id="notes-field-id",
|
|
276
|
+
content="Quality check completed successfully",
|
|
277
|
+
activity_id=activity.id
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
# 7. Update activity status
|
|
281
|
+
activity.update(task_status=ActivityStatusEnum.COMPLETE)
|
|
282
|
+
|
|
283
|
+
print("Workflow completed successfully!")
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Support
|
|
287
|
+
|
|
288
|
+
For support, email [support@kaleidoscope.bio](mailto:support@kaleidoscope.bio).
|
|
289
|
+
|
kalbio-0.2.0/README.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# Kalbio
|
|
2
|
+
|
|
3
|
+
<!-- **Source Code**: [https://github.com/kaleidoscope-tech/kalbio](https://github.com/kaleidoscope-tech/kalbio)
|
|
4
|
+
|
|
5
|
+
--- -->
|
|
6
|
+
|
|
7
|
+
Kalbio is a Python Client library for building applications with the Kaleidoscope platform.
|
|
8
|
+
|
|
9
|
+
## Key features
|
|
10
|
+
|
|
11
|
+
- **Type-safe API Client**: Built with Pydantic models for full type safety and IDE autocomplete support
|
|
12
|
+
- **Intuitive Resource Management**: Clean, object-oriented interface for programs, activities, records, and more
|
|
13
|
+
- **Advanced Search & Filtering**: Powerful query capabilities with type-safe filter operators
|
|
14
|
+
- **File Upload Support**: Direct file upload to record fields with support for multiple file types
|
|
15
|
+
- **Comprehensive Coverage**: Access all Kaleidoscope platform resources through a unified client
|
|
16
|
+
- **Bulk Operations**: Import and export capabilities for efficient data management
|
|
17
|
+
|
|
18
|
+
## Requirements
|
|
19
|
+
|
|
20
|
+
- [Python](https://docs.python.org/3/) 3.12+
|
|
21
|
+
- [Pydantic](https://docs.pydantic.dev/) 2.9.2+
|
|
22
|
+
- [Requests](https://requests.readthedocs.io/) 2.32.3+
|
|
23
|
+
|
|
24
|
+
<!--
|
|
25
|
+
TODO
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
Clone the repository and install the client in editable mode:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
git clone https://github.com/kaleidoscope-tech/kalbio.git
|
|
33
|
+
cd kalbio
|
|
34
|
+
pip install -e .
|
|
35
|
+
```
|
|
36
|
+
-->
|
|
37
|
+
|
|
38
|
+
## Authentication
|
|
39
|
+
|
|
40
|
+
Set your API credentials as environment variables before running examples:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
export KALEIDOSCOPE_API_CLIENT_ID="your_client_id"
|
|
44
|
+
export KALEIDOSCOPE_API_CLIENT_SECRET="your_client_secret"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Example
|
|
48
|
+
|
|
49
|
+
### Create it
|
|
50
|
+
|
|
51
|
+
Create a file `main.py` with:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from kalbio.client import KaleidoscopeClient
|
|
55
|
+
from kalbio.activities import ActivityStatusEnum
|
|
56
|
+
|
|
57
|
+
# Initialize the client using environment variables
|
|
58
|
+
client = KaleidoscopeClient()
|
|
59
|
+
|
|
60
|
+
# # Or with explicit arguements
|
|
61
|
+
# client = KaleidoscopeClient(
|
|
62
|
+
# client_id="your_api_client_id",
|
|
63
|
+
# client_secret="your_api_client_secret"
|
|
64
|
+
# )
|
|
65
|
+
|
|
66
|
+
# Work with activities
|
|
67
|
+
activities = client.activities.get_activities()
|
|
68
|
+
for activity in activities:
|
|
69
|
+
print(f"Activity: {activity.title} - Status: {activity.status.value}")
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Run it
|
|
73
|
+
|
|
74
|
+
Run the program with:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
python main.py
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Output:
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
Activity: Experiment 1 - Status: to do
|
|
84
|
+
Activity: Task 1 - Status: to do
|
|
85
|
+
Activity: Drug Tests - Status: in progress
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Check it
|
|
89
|
+
|
|
90
|
+
You now have a fully functional Kaleidoscope API client.
|
|
91
|
+
|
|
92
|
+
## Features
|
|
93
|
+
|
|
94
|
+
### Intuitive API Design
|
|
95
|
+
|
|
96
|
+
Work with resources naturally:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
# Records
|
|
100
|
+
record = client.records.get_record_by_id("record-uuid")
|
|
101
|
+
|
|
102
|
+
if record:
|
|
103
|
+
record.add_value(
|
|
104
|
+
field_id="field-uuid",
|
|
105
|
+
content="Experiment result",
|
|
106
|
+
activity_id="activity-uuid"
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
# Entity Types
|
|
110
|
+
entity_types = client.entity_types.get_types()
|
|
111
|
+
compound_type = client.entity_types.get_type_by_name("Compound")
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### File Upload Support
|
|
115
|
+
|
|
116
|
+
Upload files directly to records:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
# Upload a file to a record field
|
|
120
|
+
with open("experiment_data.csv", "rb") as file:
|
|
121
|
+
record.update_field_file(
|
|
122
|
+
field_id="data-field-id",
|
|
123
|
+
file_name="experiment_data.csv",
|
|
124
|
+
file_data=file,
|
|
125
|
+
file_type="text/csv",
|
|
126
|
+
activity_id="activity-uuid"
|
|
127
|
+
)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Comprehensive Resource Management
|
|
131
|
+
|
|
132
|
+
Kalbio provides services for all Kaleidoscope resources:
|
|
133
|
+
|
|
134
|
+
- **Programs**: Organize your work
|
|
135
|
+
- **Activities**: Tasks, experiments, projects, etc.
|
|
136
|
+
- **Records**: Structured data storage
|
|
137
|
+
- **Entity Types**: Define your data schemas
|
|
138
|
+
- **Entity Fields**: Manage field definitions
|
|
139
|
+
- **Labels**: Tag and categorize
|
|
140
|
+
- **Imports/Exports**: Bulk data operations
|
|
141
|
+
- **Workspace**: User and group management
|
|
142
|
+
|
|
143
|
+
## Interactive Documentation
|
|
144
|
+
|
|
145
|
+
### Available Services
|
|
146
|
+
|
|
147
|
+
Once you have a client instance, you have access to:
|
|
148
|
+
|
|
149
|
+
| Service | Description |
|
|
150
|
+
| ---------------------- | ------------------------------------------- |
|
|
151
|
+
| `client.programs` | Program management |
|
|
152
|
+
| `client.activities` | Activities (tasks, experiments, projects) |
|
|
153
|
+
| `client.records` | Record CRUD operations |
|
|
154
|
+
| `client.entity_types` | Entity type definitions |
|
|
155
|
+
| `client.entity_fields` | Field definitions (key fields, data fields) |
|
|
156
|
+
| `client.labels` | Label management |
|
|
157
|
+
| `client.imports` | Import operations and templates |
|
|
158
|
+
| `client.exports` | Export operations |
|
|
159
|
+
| `client.workspace` | Workspace, users, and groups |
|
|
160
|
+
|
|
161
|
+
### Activity Management
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
# Create an activity
|
|
165
|
+
new_activity = client.activities.create_activity(
|
|
166
|
+
title="Synthesis Experiment",
|
|
167
|
+
activity_type="experiment",
|
|
168
|
+
program_ids=["program-uuid"],
|
|
169
|
+
assigned_user_ids=["user-uuid"]
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
if new_activity:
|
|
173
|
+
# Update activity status
|
|
174
|
+
new_activity.update(status=ActivityStatusEnum.IN_PROGRESS)
|
|
175
|
+
|
|
176
|
+
# Add records to activity
|
|
177
|
+
new_activity.add_records(["record-uuid-1", "record-uuid-2"])
|
|
178
|
+
|
|
179
|
+
# Get activity data
|
|
180
|
+
record_data = new_activity.get_record_data()
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Record Operations
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
# Get record by ID
|
|
187
|
+
record = client.records.get_record_by_id("record-uuid")
|
|
188
|
+
|
|
189
|
+
if record:
|
|
190
|
+
# Add a value
|
|
191
|
+
record.add_value(
|
|
192
|
+
field_id="field-uuid",
|
|
193
|
+
content="High purity sample",
|
|
194
|
+
activity_id="activity-uuid"
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
# Get field value
|
|
198
|
+
value = record.get_value_content(field_id="field-uuid")
|
|
199
|
+
|
|
200
|
+
# Get values for specific activity
|
|
201
|
+
activity_values = record.get_activity_data(activity_id="activity-uuid")
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Full Example
|
|
205
|
+
|
|
206
|
+
Here's a complete workflow example:
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
# Initialize client
|
|
210
|
+
client = KaleidoscopeClient(
|
|
211
|
+
KALEIDOSCOPE_API_CLIENT_ID,
|
|
212
|
+
KALEIDOSCOPE_API_CLIENT_SECRET,
|
|
213
|
+
"https://api.kaleidoscope.bio",
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
# 1. Get or create a program
|
|
217
|
+
programs = client.programs.get_programs()
|
|
218
|
+
program = programs[0] if programs else None
|
|
219
|
+
|
|
220
|
+
if program:
|
|
221
|
+
print(f"Working with program: {program.title}")
|
|
222
|
+
|
|
223
|
+
# 2. Get entity types
|
|
224
|
+
entity_types = client.entity_types.get_types()
|
|
225
|
+
compound_type = next(
|
|
226
|
+
(et for et in entity_types if et.slice_name == "Compound"),
|
|
227
|
+
None
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
if compound_type:
|
|
231
|
+
# 3. Search for records
|
|
232
|
+
record_ids = client.records.search_records(
|
|
233
|
+
entity_slice_id=compound_type.id,
|
|
234
|
+
limit=10
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
print(f"Found {len(record_ids)} compound records")
|
|
238
|
+
|
|
239
|
+
# 4. Get detailed record information
|
|
240
|
+
if record_ids:
|
|
241
|
+
record = client.records.get_record_by_id(record_ids[0])
|
|
242
|
+
assert record
|
|
243
|
+
print(f"Record: {record.record_identifier}")
|
|
244
|
+
|
|
245
|
+
# 5. Create an activity
|
|
246
|
+
activity = client.activities.create_activity(
|
|
247
|
+
title="Quality Check",
|
|
248
|
+
activity_type="task",
|
|
249
|
+
program_ids=[program.id]
|
|
250
|
+
)
|
|
251
|
+
assert activity
|
|
252
|
+
|
|
253
|
+
# 6. Add data to record
|
|
254
|
+
record.add_value(
|
|
255
|
+
field_id="notes-field-id",
|
|
256
|
+
content="Quality check completed successfully",
|
|
257
|
+
activity_id=activity.id
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
# 7. Update activity status
|
|
261
|
+
activity.update(task_status=ActivityStatusEnum.COMPLETE)
|
|
262
|
+
|
|
263
|
+
print("Workflow completed successfully!")
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Support
|
|
267
|
+
|
|
268
|
+
For support, email [support@kaleidoscope.bio](mailto:support@kaleidoscope.bio).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.0"
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Kaleidoscope Base Model Module.
|
|
3
|
+
|
|
4
|
+
Internal class.
|
|
5
|
+
|
|
6
|
+
This module defines the base model class for all Kaleidoscope objects, providing
|
|
7
|
+
common functionality for serialization, comparison, and client management.
|
|
8
|
+
|
|
9
|
+
The `_KaleidoscopeBaseModel` class extends Pydantic's BaseModel to provide:
|
|
10
|
+
- Unique identification via id attribute
|
|
11
|
+
- Client instance management for API interactions
|
|
12
|
+
- Standard serialization methods (JSON, dictionary)
|
|
13
|
+
- Comparison and hashing based on id
|
|
14
|
+
- String representation methods
|
|
15
|
+
|
|
16
|
+
Classes:
|
|
17
|
+
_KaleidoscopeBaseModel: Base class for all Kaleidoscope model objects.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel
|
|
21
|
+
from kalbio.client import KaleidoscopeClient
|
|
22
|
+
import json
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class _KaleidoscopeBaseModel(BaseModel):
|
|
26
|
+
"""
|
|
27
|
+
Base model class for Kaleidoscope objects.
|
|
28
|
+
This class provides common functionality for all Kaleidoscope model objects,
|
|
29
|
+
including serialization, comparison, and client management.
|
|
30
|
+
Attributes:
|
|
31
|
+
id (str): Unique identifier for the model instance.
|
|
32
|
+
_client (KaleidoscopeClient): Internal reference to the Kaleidoscope client instance.
|
|
33
|
+
Methods:
|
|
34
|
+
__eq__(other): Compare two model instances based on their type and id.
|
|
35
|
+
__hash__(): Return hash value based on the id attribute.
|
|
36
|
+
__str__(): Return string representation of the model instance.
|
|
37
|
+
__repr__(): Return string representation of the model instance.
|
|
38
|
+
to_json(): Serialize the model instance to a JSON string.
|
|
39
|
+
to_dict(): Convert the model instance to a dictionary containing the id.
|
|
40
|
+
_set_client(client): Set the KaleidoscopeClient instance for this object.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
id: str
|
|
44
|
+
_client: KaleidoscopeClient
|
|
45
|
+
|
|
46
|
+
def __eq__(self, other):
|
|
47
|
+
return isinstance(other, self.__class__) and self.id == other.id
|
|
48
|
+
|
|
49
|
+
def __hash__(self):
|
|
50
|
+
return hash(self.id)
|
|
51
|
+
|
|
52
|
+
def __str__(self):
|
|
53
|
+
return f"{type(self).__name__}:'{self.id[:8]}...'"
|
|
54
|
+
|
|
55
|
+
def __repr__(self):
|
|
56
|
+
return f"{self.__class__}({self.model_dump()})"
|
|
57
|
+
|
|
58
|
+
def to_json(self) -> str:
|
|
59
|
+
"""
|
|
60
|
+
Serializes the model to a JSON-formatted string.
|
|
61
|
+
Returns:
|
|
62
|
+
str: A JSON string representation of the model, with indentation for readability.
|
|
63
|
+
Notes:
|
|
64
|
+
- This method is a thin convenience wrapper. To customize serialization options,
|
|
65
|
+
call json.dumps(...) directly on a `dict` of the model.
|
|
66
|
+
- One way a `dict` may be optained throught the `to_dict()` method
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
return json.dumps(self.model_dump(), indent=4, sort_keys=False, default=str)
|
|
70
|
+
|
|
71
|
+
def to_dict(self) -> dict:
|
|
72
|
+
"""
|
|
73
|
+
Return a dictionary representation of the model by delegating to self.model_dump().
|
|
74
|
+
Returns:
|
|
75
|
+
dict: A mapping of field names to their serialized values. The exact structure and
|
|
76
|
+
serialization behavior (e.g., handling of nested models, inclusion of defaults,
|
|
77
|
+
or custom encoders) follow the semantics of the underlying model_dump implementation.
|
|
78
|
+
Notes:
|
|
79
|
+
- This method is a thin convenience wrapper. To customize serialization options,
|
|
80
|
+
call model_dump(...) directly with the desired parameters.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
return self.model_dump()
|
|
84
|
+
|
|
85
|
+
def _set_client(self, client: KaleidoscopeClient) -> None:
|
|
86
|
+
"""
|
|
87
|
+
Set the `KaleidoscopeClient` instance for this object.
|
|
88
|
+
Also recursively sets client on all _KaleidoscopeBaseModel attributes
|
|
89
|
+
"""
|
|
90
|
+
self._client = client
|
|
91
|
+
|
|
92
|
+
# Iterate through field names and get actual values from the instance
|
|
93
|
+
for field_name in self.__class__.model_fields.keys():
|
|
94
|
+
value = getattr(self, field_name, None)
|
|
95
|
+
if value is None:
|
|
96
|
+
continue
|
|
97
|
+
|
|
98
|
+
if isinstance(value, _KaleidoscopeBaseModel):
|
|
99
|
+
value._set_client(client)
|
|
100
|
+
elif isinstance(value, list):
|
|
101
|
+
for item in value:
|
|
102
|
+
if isinstance(item, _KaleidoscopeBaseModel):
|
|
103
|
+
item._set_client(client)
|
|
104
|
+
elif isinstance(value, dict):
|
|
105
|
+
for item in value.values():
|
|
106
|
+
if isinstance(item, _KaleidoscopeBaseModel):
|
|
107
|
+
item._set_client(client)
|
|
108
|
+
elif isinstance(item, list):
|
|
109
|
+
for nested_item in item:
|
|
110
|
+
if isinstance(nested_item, _KaleidoscopeBaseModel):
|
|
111
|
+
nested_item._set_client(client)
|