Skip to content

Client

client

Kaleidoscope API Client Module.

This module provides the main client class for interacting with the Kaleidoscope API, along with a base model class for Kaleidoscope entities.

The KaleidoscopeClient provides access to various service endpoints including:

  • activities: Manage activities
  • imports: Import data into Kaleidoscope
  • programs: Manage programs
  • entity_types: Manage entity types
  • records: Manage records
  • fields: Manage fields
  • experiments: Manage experiments
  • record_views: Manage record views
  • exports: Export data from Kaleidoscope

Attributes:

Name Type Description
PROD_API_URL str

The production URL for the Kaleidoscope API.

VALID_CONTENT_TYPES list

List of acceptable content types for file downloads.

TIMEOUT_MAXIMUM int

Maximum timeout for API requests in seconds.

Example
    # instantiate client object
    client = KaleidoscopeClient(
        client_id="your_client_id",
        client_secret="your_client_secret"
    )

    # retrieve activities
    programs = client.activities.get_activities()

PROD_API_URL module-attribute

PROD_API_URL = 'https://api.kaleidoscope.bio'

The production URL for the Kaleidoscope API.

This is the default url used for the KaleidoscopeClient, in the event no url is provided in the KaleidoscopeClient's initialization

VALID_CONTENT_TYPES module-attribute

VALID_CONTENT_TYPES = ['text/csv', 'chemical/x-mdl-sdfile', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']

List of acceptable content types for file downloads.

Any file retrieved by the KaleidoscopeClient must be of one the above types

TIMEOUT_MAXIMUM module-attribute

TIMEOUT_MAXIMUM = 10

Maximum timeout for API requests in seconds.

TokenResponse

KaleidoscopeClient

KaleidoscopeClient(client_id: str, client_secret: str, url: str | None = None)

A client for interacting with the Kaleidoscope API.

This client provides a high-level interface to various Kaleidoscope services including imports, programs, entity types, records, fields, tasks, experiments, record views, and exports. It handles authentication using API key credentials and provides methods for making HTTP requests (GET, POST, PUT) to the API endpoints.

Attributes:

Name Type Description
activities ActivitiesService

Service for managing activities.

dashboards DashboardsService

Service for managing dashboards.

workspace WorkspaceService

Service for workspace-related operations.

programs ProgramsService

Service for managing programs.

labels LabelsService

Service for managing labels.

entity_types EntityTypesService

Service for managing entity types.

entity_fields EntityFieldsService

Service for managing entity fields.

records RecordsService

Service for managing records.

record_views RecordViewsService

Service for managing record views.

imports ImportsService

Service for managing data imports.

exports ExportsService

Service for managing data exports.

property_fields PropertyFieldsService

Service for managing property fields.

Example
client = KaleidoscopeClient(
    client_id="your_api_client_id",
    client_secret="your_api_client_secret"
}
# Use the client to interact with various services
programs = client.activities.get_activities()

Sets up the client with API credentials and optional API URL, and initializes service interfaces for interacting with different API endpoints.

Parameters:

Name Type Description Default
client_id str

The API client ID for authentication.

required
client_secret str

The API client secret for authentication.

required
url str | None

The base URL for the API. Defaults to the production API URL if not provided.

None
Source code in kalpy/client.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
def __init__(
    self,
    client_id: str,
    client_secret: str,
    url: Optional[str] = None,
):
    """Initialize the Kaleidoscope API client.

    Sets up the client with API credentials and optional API URL, and initializes
    service interfaces for interacting with different API endpoints.

    Args:
        client_id (str): The API client ID for authentication.
        client_secret (str): The API client secret for authentication.
        url (Optional[str]): The base URL for the API. Defaults to the production
            API URL if not provided.
    """
    from kalpy.activities import ActivitiesService
    from kalpy.dashboards import DashboardsService
    from kalpy.entity_fields import EntityFieldsService
    from kalpy.entity_types import EntityTypesService
    from kalpy.exports import ExportsService
    from kalpy.imports import ImportsService
    from kalpy.labels import LabelsService
    from kalpy.programs import ProgramsService
    from kalpy.property_fields import PropertyFieldsService
    from kalpy.record_views import RecordViewsService
    from kalpy.records import RecordsService
    from kalpy.workspace import WorkspaceService

    self._api_url = url if url else PROD_API_URL

    self.activities = ActivitiesService(self)
    self.dashboards = DashboardsService(self)
    self.entity_fields = EntityFieldsService(self)
    self.entity_types = EntityTypesService(self)
    self.exports = ExportsService(self)
    self.imports = ImportsService(self)
    self.labels = LabelsService(self)
    self.property_fields = PropertyFieldsService(self)
    self.programs = ProgramsService(self)
    self.record_views = RecordViewsService(self)
    self.records = RecordsService(self)
    self.workspace = WorkspaceService(self)

    self._client_id = client_id
    self._client_secret = client_secret
    self._get_auth_token()