Entity Fields
entity_fields
Module for managing entity fields in Kaleidoscope.
This module provides classes and services for working with entity fields, which are the schema definitions for data stored in the Kaleidoscope system. It includes:
- DataFieldTypeEnum: An enumeration of all supported field types
- EntityField: A model representing a field definition
- EntityFieldsService: A service class for retrieving and creating entity fields
Entity fields can be of two types:
- Key fields: Used to uniquely identify entities
- Data fields: Used to store additional information about entities
The service provides caching mechanisms to minimize API calls and includes error handling for all network operations.
Classes:
| Name | Description |
|---|---|
DataFieldTypeEnum |
An enumeration of all supported field types |
EntityField |
A model representing a field definition |
EntityFieldsService |
A service class for retrieving and creating entity fields |
Example
# Get all key fields
key_fields = client.entity_fields.get_key_fields()
# Create or get a data field
field = client.entity_fields.get_or_create_data_field(
field_name="temperature",
field_type=DataFieldTypeEnum.NUMBER
)
DataFieldTypeEnum
Enumeration of data field types supported by the system.
This enum defines all possible types of data fields that can be used in the application. Each field type represents a specific kind of data structure and validation rules.
Attributes:
| Name | Type | Description |
|---|---|---|
TEXT |
Plain text field. |
|
NUMBER |
Numeric field for storing numbers. |
|
QUALIFIED_NUMBER |
Numeric field with additional qualifiers or units. |
|
SMILES_STRING |
Field for storing SMILES (Simplified Molecular Input Line Entry System) notation. |
|
SELECT |
Single selection field from predefined options. |
|
MULTISELECT |
Multiple selection field from predefined options. |
|
MOLFILE |
Field for storing molecular structure files. |
|
RECORD_REFERENCE |
Reference to another record by record_id. |
|
FILE |
Generic file attachment field. |
|
IMAGE |
Image file field. |
|
DATE |
Date field. |
|
URL |
Web URL field. |
|
BOOLEAN |
Boolean (true/false) field. |
|
EMAIL |
Email address field. |
|
PHONE |
Phone number field. |
|
FORMULA |
Field for storing formulas or calculated expressions. |
|
PEOPLE |
Field for referencing people/users. |
|
VOTES |
Field for storing vote counts or voting data. |
|
XY_ARRAY |
Field for storing XY coordinate arrays. |
|
DNA_OLIGO |
Field for storing DNA oligonucleotide sequences. |
|
RNA_OLIGO |
Field for storing RNA oligonucleotide sequences. |
|
PEPTID |
Field for storing peptide sequences. |
|
PLASMID |
Field for storing plasmid information. |
|
GOOGLE_DRIVE |
Field for Google Drive file references. |
|
S3_FILE |
Field for AWS S3 file references. |
|
SNOWFLAKE_QUERY |
Field for Snowflake database query references. |
EntityField
Bases: _KaleidoscopeBaseModel
Represents a field within an entity in the Kaleidoscope system.
This class defines the structure and metadata for individual fields that belong to an entity, including type information, key status, and optional references.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The UUID of the field. |
created_at |
datetime
|
Timestamp when the field was created. |
is_key |
bool
|
Indicates whether this field is a key field for the entity. |
field_name |
str
|
The name of the field. |
field_type |
DataFieldTypeEnum
|
The data type of the field. |
ref_slice_id |
str | None
|
Optional reference to a slice ID for relational fields. |
Example
from kalbio.entity_fields import EntityField, DataFieldTypeEnum
from datetime import datetime
ef = EntityField(
id="field_uuid",
created_at=datetime.utcnow(),
is_key=True,
field_name="sample_id",
field_type=DataFieldTypeEnum.TEXT,
ref_slice_id=None,
)
print(str(ef)) # sample_id
EntityFieldIdentifier
module-attribute
EntityFieldIdentifier: TypeAlias = EntityField | str
An Identifier Type for Entity Fields.
An EntityField should be able to be identified by:
- EntityField (object instance)
- UUID (str)
- field_name (str)
EntityFieldsService
EntityFieldsService(client: KaleidoscopeClient)
Service class for managing key fields and data fields in Kaleidoscope.
Entity fields can be of two types:
- Key fields: Used to uniquely identify entities
- Data fields: Used to store additional information about entities
Example
key_fields = client.entity_fields.get_key_fields()
temperature = client.entity_fields.get_or_create_data_field(
field_name="temperature",
field_type=DataFieldTypeEnum.NUMBER,
)
Methods:
| Name | Description |
|---|---|
get_key_fields |
Retrieve key fields and cache the result. |
get_key_field_by_id |
Get a key field by an identifier. |
get_or_create_key_field |
Retrieve an existing key field by name or create it. |
get_data_fields |
Retrieve data fields and cache the result. |
get_data_field_by_id |
Get a data field by identifier. |
get_or_create_data_field |
Create a data field or return the existing one. |
Source code in kalbio/entity_fields.py
183 184 | |
get_key_fields
cached
get_key_fields() -> list[EntityField]
Retrieve key fields and cache the result.
Returns:
| Type | Description |
|---|---|
list[EntityField]
|
Key field definitions for the workspace. |
Notes
On error, the caches are cleared and an empty list is returned.
Example
key_fields = client.entity_fields.get_key_fields()
Source code in kalbio/entity_fields.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
get_key_field_by_id
get_key_field_by_id(identifier: EntityFieldIdentifier) -> EntityField | None
Get a key field by an identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
EntityFieldIdentifier
|
Key field identifier. Data field identifiers will return None. This method will accept and resolve any type of EntityFieldIdentifier. |
required |
Returns:
| Type | Description |
|---|---|
EntityField | None
|
Matching key field if found. If not, returns None. |
Example
key_field = client.entity_fields.get_key_field_by_id("sample_id")
Source code in kalbio/entity_fields.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
get_or_create_key_field
get_or_create_key_field(field_name: str) -> EntityField | None
Retrieve an existing key field by name or create it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
Name of the key field to fetch or create. |
required |
Returns:
| Type | Description |
|---|---|
EntityField | None
|
Existing or newly created key field, or None on error. |
Example
key_field = client.entity_fields.get_or_create_key_field("sample_id")
Source code in kalbio/entity_fields.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
get_data_fields
cached
get_data_fields() -> list[EntityField]
Retrieve data fields and cache the result.
Returns:
| Type | Description |
|---|---|
list[EntityField]
|
Data field definitions for the workspace. |
Notes
On error, the caches are cleared and an empty list is returned.
Example
data_fields = client.entity_fields.get_data_fields()
Source code in kalbio/entity_fields.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
get_data_field_by_id
get_data_field_by_id(identifier: EntityFieldIdentifier) -> EntityField | None
Get a data field by identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
EntityFieldIdentifier
|
Identifier for a data field. Key field identifiers return None. This method will accept and resolve any type of EntityFieldIdentifier. |
required |
Returns:
| Type | Description |
|---|---|
EntityField | None
|
Matching data field, if found. |
Example
data_field = client.entity_fields.get_data_field_by_id("temperature")
Source code in kalbio/entity_fields.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
get_or_create_data_field
get_or_create_data_field(field_name: str, field_type: DataFieldTypeEnum) -> EntityField | None
Create a data field or return the existing one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
Name of the data field to create or retrieve. |
required |
field_type
|
DataFieldTypeEnum
|
Data field type. |
required |
Returns:
| Type | Description |
|---|---|
EntityField | None
|
Existing or newly created data field, or None on error. |
Example
concentration = client.entity_fields.get_or_create_data_field(
field_name="concentration",
field_type=DataFieldTypeEnum.NUMBER,
)
Source code in kalbio/entity_fields.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |