rapidata 1.4.5__py3-none-any.whl → 1.5.0__py3-none-any.whl

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.

Potentially problematic release.


This version of rapidata might be problematic. Click here for more details.

@@ -0,0 +1,96 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Rapidata.Dataset
5
+
6
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+
8
+ The version of the OpenAPI document: v1
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ from __future__ import annotations
16
+ import pprint
17
+ import re # noqa: F401
18
+ import json
19
+
20
+ from datetime import datetime
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr
22
+ from typing import Any, ClassVar, Dict, List
23
+ from typing import Optional, Set
24
+ from typing_extensions import Self
25
+
26
+ class ValidationSetModel(BaseModel):
27
+ """
28
+ ValidationSetModel
29
+ """ # noqa: E501
30
+ id: StrictStr
31
+ name: StrictStr
32
+ owner_id: StrictStr = Field(alias="ownerId")
33
+ owner_mail: StrictStr = Field(alias="ownerMail")
34
+ created_at: datetime = Field(alias="createdAt")
35
+ __properties: ClassVar[List[str]] = ["id", "name", "ownerId", "ownerMail", "createdAt"]
36
+
37
+ model_config = ConfigDict(
38
+ populate_by_name=True,
39
+ validate_assignment=True,
40
+ protected_namespaces=(),
41
+ )
42
+
43
+
44
+ def to_str(self) -> str:
45
+ """Returns the string representation of the model using alias"""
46
+ return pprint.pformat(self.model_dump(by_alias=True))
47
+
48
+ def to_json(self) -> str:
49
+ """Returns the JSON representation of the model using alias"""
50
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
51
+ return json.dumps(self.to_dict())
52
+
53
+ @classmethod
54
+ def from_json(cls, json_str: str) -> Optional[Self]:
55
+ """Create an instance of ValidationSetModel from a JSON string"""
56
+ return cls.from_dict(json.loads(json_str))
57
+
58
+ def to_dict(self) -> Dict[str, Any]:
59
+ """Return the dictionary representation of the model using alias.
60
+
61
+ This has the following differences from calling pydantic's
62
+ `self.model_dump(by_alias=True)`:
63
+
64
+ * `None` is only added to the output dict for nullable fields that
65
+ were set at model initialization. Other fields with value `None`
66
+ are ignored.
67
+ """
68
+ excluded_fields: Set[str] = set([
69
+ ])
70
+
71
+ _dict = self.model_dump(
72
+ by_alias=True,
73
+ exclude=excluded_fields,
74
+ exclude_none=True,
75
+ )
76
+ return _dict
77
+
78
+ @classmethod
79
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
80
+ """Create an instance of ValidationSetModel from a dict"""
81
+ if obj is None:
82
+ return None
83
+
84
+ if not isinstance(obj, dict):
85
+ return cls.model_validate(obj)
86
+
87
+ _obj = cls.model_validate({
88
+ "id": obj.get("id"),
89
+ "name": obj.get("name"),
90
+ "ownerId": obj.get("ownerId"),
91
+ "ownerMail": obj.get("ownerMail"),
92
+ "createdAt": obj.get("createdAt")
93
+ })
94
+ return _obj
95
+
96
+
@@ -0,0 +1,105 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Rapidata.Dataset
5
+
6
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+
8
+ The version of the OpenAPI document: v1
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ from __future__ import annotations
16
+ import pprint
17
+ import re # noqa: F401
18
+ import json
19
+
20
+ from pydantic import BaseModel, ConfigDict, Field, StrictInt
21
+ from typing import Any, ClassVar, Dict, List, Optional
22
+ from rapidata.api_client.models.validation_set_model import ValidationSetModel
23
+ from typing import Optional, Set
24
+ from typing_extensions import Self
25
+
26
+ class ValidationSetModelPagedResult(BaseModel):
27
+ """
28
+ ValidationSetModelPagedResult
29
+ """ # noqa: E501
30
+ total: StrictInt
31
+ page: StrictInt
32
+ page_size: StrictInt = Field(alias="pageSize")
33
+ items: List[ValidationSetModel]
34
+ total_pages: Optional[StrictInt] = Field(default=None, alias="totalPages")
35
+ __properties: ClassVar[List[str]] = ["total", "page", "pageSize", "items", "totalPages"]
36
+
37
+ model_config = ConfigDict(
38
+ populate_by_name=True,
39
+ validate_assignment=True,
40
+ protected_namespaces=(),
41
+ )
42
+
43
+
44
+ def to_str(self) -> str:
45
+ """Returns the string representation of the model using alias"""
46
+ return pprint.pformat(self.model_dump(by_alias=True))
47
+
48
+ def to_json(self) -> str:
49
+ """Returns the JSON representation of the model using alias"""
50
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
51
+ return json.dumps(self.to_dict())
52
+
53
+ @classmethod
54
+ def from_json(cls, json_str: str) -> Optional[Self]:
55
+ """Create an instance of ValidationSetModelPagedResult from a JSON string"""
56
+ return cls.from_dict(json.loads(json_str))
57
+
58
+ def to_dict(self) -> Dict[str, Any]:
59
+ """Return the dictionary representation of the model using alias.
60
+
61
+ This has the following differences from calling pydantic's
62
+ `self.model_dump(by_alias=True)`:
63
+
64
+ * `None` is only added to the output dict for nullable fields that
65
+ were set at model initialization. Other fields with value `None`
66
+ are ignored.
67
+ * OpenAPI `readOnly` fields are excluded.
68
+ """
69
+ excluded_fields: Set[str] = set([
70
+ "total_pages",
71
+ ])
72
+
73
+ _dict = self.model_dump(
74
+ by_alias=True,
75
+ exclude=excluded_fields,
76
+ exclude_none=True,
77
+ )
78
+ # override the default output from pydantic by calling `to_dict()` of each item in items (list)
79
+ _items = []
80
+ if self.items:
81
+ for _item_items in self.items:
82
+ if _item_items:
83
+ _items.append(_item_items.to_dict())
84
+ _dict['items'] = _items
85
+ return _dict
86
+
87
+ @classmethod
88
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
89
+ """Create an instance of ValidationSetModelPagedResult from a dict"""
90
+ if obj is None:
91
+ return None
92
+
93
+ if not isinstance(obj, dict):
94
+ return cls.model_validate(obj)
95
+
96
+ _obj = cls.model_validate({
97
+ "total": obj.get("total"),
98
+ "page": obj.get("page"),
99
+ "pageSize": obj.get("pageSize"),
100
+ "items": [ValidationSetModel.from_dict(_item) for _item in obj["items"]] if obj.get("items") is not None else None,
101
+ "totalPages": obj.get("totalPages")
102
+ })
103
+ return _obj
104
+
105
+
@@ -89,20 +89,8 @@ Class | Method | HTTP request | Description
89
89
  *DatasetApi* | [**dataset_upload_datapoint_post**](rapidata/api_client/docs/DatasetApi.md#dataset_upload_datapoint_post) | **POST** /Dataset/UploadDatapoint | Creates a new multi asset datapoint.
90
90
  *DatasetApi* | [**dataset_upload_files_from_s3_post**](rapidata/api_client/docs/DatasetApi.md#dataset_upload_files_from_s3_post) | **POST** /Dataset/UploadFilesFromS3 | Uploads files from an S3 bucket to a dataset.
91
91
  *DatasetApi* | [**dataset_upload_images_to_dataset_post**](rapidata/api_client/docs/DatasetApi.md#dataset_upload_images_to_dataset_post) | **POST** /Dataset/UploadImagesToDataset | Uploads images to a dataset.
92
- *IdentityApi* | [**identity_confirm_get**](rapidata/api_client/docs/IdentityApi.md#identity_confirm_get) | **GET** /Identity/Confirm | Confirms a user's signup by a token.
93
92
  *IdentityApi* | [**identity_create_client_post**](rapidata/api_client/docs/IdentityApi.md#identity_create_client_post) | **POST** /Identity/CreateClient | Creates a new client for the current customer.
94
- *IdentityApi* | [**identity_create_legacy_client_post**](rapidata/api_client/docs/IdentityApi.md#identity_create_legacy_client_post) | **POST** /Identity/CreateLegacyClient | Creates a new client for a customer.
95
- *IdentityApi* | [**identity_external_login_callback_get**](rapidata/api_client/docs/IdentityApi.md#identity_external_login_callback_get) | **GET** /Identity/ExternalLoginCallback | Logs in a user using after receiving a grant from an external provider.
96
- *IdentityApi* | [**identity_external_login_post**](rapidata/api_client/docs/IdentityApi.md#identity_external_login_post) | **POST** /Identity/ExternalLogin | Logs in a user using an external provider.
97
- *IdentityApi* | [**identity_get_auth_token_get**](rapidata/api_client/docs/IdentityApi.md#identity_get_auth_token_get) | **GET** /Identity/GetAuthToken | Issues a new auth token using the refresh token.
98
- *IdentityApi* | [**identity_get_client_auth_token_post**](rapidata/api_client/docs/IdentityApi.md#identity_get_client_auth_token_post) | **POST** /Identity/GetClientAuthToken | Issues a new auth token using the client credentials.
99
- *IdentityApi* | [**identity_index_post**](rapidata/api_client/docs/IdentityApi.md#identity_index_post) | **POST** /Identity/Index | Logs in a user by username or email and password.
100
- *IdentityApi* | [**identity_logout_post**](rapidata/api_client/docs/IdentityApi.md#identity_logout_post) | **POST** /Identity/Logout | Logs out the current user by deleting the refresh token cookie.
101
93
  *IdentityApi* | [**identity_register_temporary_post**](rapidata/api_client/docs/IdentityApi.md#identity_register_temporary_post) | **POST** /Identity/RegisterTemporary | Registers and logs in a temporary customer.
102
- *IdentityApi* | [**identity_request_reset_post**](rapidata/api_client/docs/IdentityApi.md#identity_request_reset_post) | **POST** /Identity/RequestReset | Request a password reset for a user.
103
- *IdentityApi* | [**identity_signup_post**](rapidata/api_client/docs/IdentityApi.md#identity_signup_post) | **POST** /Identity/Signup | Signs up a new user.
104
- *IdentityApi* | [**identity_submit_reset_post**](rapidata/api_client/docs/IdentityApi.md#identity_submit_reset_post) | **POST** /Identity/SubmitReset | Updates the password of a user after a password reset request.
105
- *IdentityApi* | [**identity_temporary_post**](rapidata/api_client/docs/IdentityApi.md#identity_temporary_post) | **POST** /Identity/Temporary | Creates a new temporary user.
106
94
  *NewsletterApi* | [**newsletter_post**](rapidata/api_client/docs/NewsletterApi.md#newsletter_post) | **POST** /Newsletter | Signs a user up to the newsletter.
107
95
  *NewsletterApi* | [**newsletter_unsubscribe_post**](rapidata/api_client/docs/NewsletterApi.md#newsletter_unsubscribe_post) | **POST** /Newsletter/Unsubscribe | Unsubscribes a user from the newsletter.
108
96
  *OrderApi* | [**order_approve_post**](rapidata/api_client/docs/OrderApi.md#order_approve_post) | **POST** /Order/Approve | Approves an order that has been submitted for manual approval.
@@ -140,6 +128,7 @@ Class | Method | HTTP request | Description
140
128
  *ValidationApi* | [**validation_add_validation_text_rapid_post**](rapidata/api_client/docs/ValidationApi.md#validation_add_validation_text_rapid_post) | **POST** /Validation/AddValidationTextRapid | Adds a new validation rapid to the specified validation set.
141
129
  *ValidationApi* | [**validation_create_validation_set_post**](rapidata/api_client/docs/ValidationApi.md#validation_create_validation_set_post) | **POST** /Validation/CreateValidationSet | Creates a new empty validation set.
142
130
  *ValidationApi* | [**validation_get_available_validation_sets_get**](rapidata/api_client/docs/ValidationApi.md#validation_get_available_validation_sets_get) | **GET** /Validation/GetAvailableValidationSets | Gets the available validation sets for the current user.
131
+ *ValidationApi* | [**validation_get_by_id_get**](rapidata/api_client/docs/ValidationApi.md#validation_get_by_id_get) | **GET** /Validation/GetById | Gets a validation set by the id.
143
132
  *ValidationApi* | [**validation_import_compare_post**](rapidata/api_client/docs/ValidationApi.md#validation_import_compare_post) | **POST** /Validation/ImportCompare | Imports a compare validation set from a zip file.
144
133
  *ValidationApi* | [**validation_import_post**](rapidata/api_client/docs/ValidationApi.md#validation_import_post) | **POST** /Validation/Import | Imports a validation set from a zip file.
145
134
  *ValidationApi* | [**validation_query_validation_sets_get**](rapidata/api_client/docs/ValidationApi.md#validation_query_validation_sets_get) | **GET** /Validation/QueryValidationSets | Queries validation sets based on the provided filter, paging and sorting criteria.
@@ -212,7 +201,6 @@ Class | Method | HTTP request | Description
212
201
  - [CreateDatasetArtifactModelDataset](rapidata/api_client/docs/CreateDatasetArtifactModelDataset.md)
213
202
  - [CreateDemographicRapidModel](rapidata/api_client/docs/CreateDemographicRapidModel.md)
214
203
  - [CreateEmptyValidationSetResult](rapidata/api_client/docs/CreateEmptyValidationSetResult.md)
215
- - [CreateLegacyClientModel](rapidata/api_client/docs/CreateLegacyClientModel.md)
216
204
  - [CreateOrderModel](rapidata/api_client/docs/CreateOrderModel.md)
217
205
  - [CreateOrderModelReferee](rapidata/api_client/docs/CreateOrderModelReferee.md)
218
206
  - [CreateOrderModelUserFiltersInner](rapidata/api_client/docs/CreateOrderModelUserFiltersInner.md)
@@ -268,6 +256,7 @@ Class | Method | HTTP request | Description
268
256
  - [GetPipelineByIdResultArtifactsValue](rapidata/api_client/docs/GetPipelineByIdResultArtifactsValue.md)
269
257
  - [GetPublicOrdersResult](rapidata/api_client/docs/GetPublicOrdersResult.md)
270
258
  - [GetSimpleWorkflowResultOverviewResult](rapidata/api_client/docs/GetSimpleWorkflowResultOverviewResult.md)
259
+ - [GetValidationSetByIdResult](rapidata/api_client/docs/GetValidationSetByIdResult.md)
271
260
  - [GetWorkflowByIdResult](rapidata/api_client/docs/GetWorkflowByIdResult.md)
272
261
  - [GetWorkflowByIdResultWorkflow](rapidata/api_client/docs/GetWorkflowByIdResultWorkflow.md)
273
262
  - [GetWorkflowProgressResult](rapidata/api_client/docs/GetWorkflowProgressResult.md)
@@ -278,12 +267,8 @@ Class | Method | HTTP request | Description
278
267
  - [ImportFromFileResult](rapidata/api_client/docs/ImportFromFileResult.md)
279
268
  - [ImportValidationSetFromFileResult](rapidata/api_client/docs/ImportValidationSetFromFileResult.md)
280
269
  - [InProgressRapidModel](rapidata/api_client/docs/InProgressRapidModel.md)
281
- - [IssueAuthTokenResult](rapidata/api_client/docs/IssueAuthTokenResult.md)
282
270
  - [LabelingSelection](rapidata/api_client/docs/LabelingSelection.md)
283
271
  - [LanguageUserFilterModel](rapidata/api_client/docs/LanguageUserFilterModel.md)
284
- - [LegacyIssueClientAuthTokenResult](rapidata/api_client/docs/LegacyIssueClientAuthTokenResult.md)
285
- - [LegacyRequestPasswordResetCommand](rapidata/api_client/docs/LegacyRequestPasswordResetCommand.md)
286
- - [LegacySubmitPasswordResetCommand](rapidata/api_client/docs/LegacySubmitPasswordResetCommand.md)
287
272
  - [Line](rapidata/api_client/docs/Line.md)
288
273
  - [LinePayload](rapidata/api_client/docs/LinePayload.md)
289
274
  - [LinePoint](rapidata/api_client/docs/LinePoint.md)
@@ -299,7 +284,6 @@ Class | Method | HTTP request | Description
299
284
  - [LocationMetadataExistsFilterConfig](rapidata/api_client/docs/LocationMetadataExistsFilterConfig.md)
300
285
  - [LocationMetadataModel](rapidata/api_client/docs/LocationMetadataModel.md)
301
286
  - [LogicOperator](rapidata/api_client/docs/LogicOperator.md)
302
- - [LoginModel](rapidata/api_client/docs/LoginModel.md)
303
287
  - [MetadataVisibilities](rapidata/api_client/docs/MetadataVisibilities.md)
304
288
  - [MultiAsset](rapidata/api_client/docs/MultiAsset.md)
305
289
  - [MultiAssetModel](rapidata/api_client/docs/MultiAssetModel.md)
@@ -351,11 +335,10 @@ Class | Method | HTTP request | Description
351
335
  - [RapidResultModel](rapidata/api_client/docs/RapidResultModel.md)
352
336
  - [RapidResultModelResult](rapidata/api_client/docs/RapidResultModelResult.md)
353
337
  - [RapidSkippedModel](rapidata/api_client/docs/RapidSkippedModel.md)
338
+ - [RegisterTemporaryCustomerModel](rapidata/api_client/docs/RegisterTemporaryCustomerModel.md)
354
339
  - [RootFilter](rapidata/api_client/docs/RootFilter.md)
355
340
  - [SendCompletionMailStepModel](rapidata/api_client/docs/SendCompletionMailStepModel.md)
356
341
  - [Shape](rapidata/api_client/docs/Shape.md)
357
- - [SignupCustomerModel](rapidata/api_client/docs/SignupCustomerModel.md)
358
- - [SignupShadowCustomerModel](rapidata/api_client/docs/SignupShadowCustomerModel.md)
359
342
  - [SimpleWorkflowConfig](rapidata/api_client/docs/SimpleWorkflowConfig.md)
360
343
  - [SimpleWorkflowConfigModel](rapidata/api_client/docs/SimpleWorkflowConfigModel.md)
361
344
  - [SimpleWorkflowConfigModelBlueprint](rapidata/api_client/docs/SimpleWorkflowConfigModelBlueprint.md)
@@ -399,9 +382,9 @@ Class | Method | HTTP request | Description
399
382
  - [ValidationChance](rapidata/api_client/docs/ValidationChance.md)
400
383
  - [ValidationImportPostRequestBlueprint](rapidata/api_client/docs/ValidationImportPostRequestBlueprint.md)
401
384
  - [ValidationSelection](rapidata/api_client/docs/ValidationSelection.md)
402
- - [ValidationSet](rapidata/api_client/docs/ValidationSet.md)
385
+ - [ValidationSetModel](rapidata/api_client/docs/ValidationSetModel.md)
386
+ - [ValidationSetModelPagedResult](rapidata/api_client/docs/ValidationSetModelPagedResult.md)
403
387
  - [ValidationSetOverviewModel](rapidata/api_client/docs/ValidationSetOverviewModel.md)
404
- - [ValidationSetPagedResult](rapidata/api_client/docs/ValidationSetPagedResult.md)
405
388
  - [WorkflowAggregationStepModel](rapidata/api_client/docs/WorkflowAggregationStepModel.md)
406
389
  - [WorkflowArtifactModel](rapidata/api_client/docs/WorkflowArtifactModel.md)
407
390
  - [WorkflowConfigArtifactModel](rapidata/api_client/docs/WorkflowConfigArtifactModel.md)
@@ -47,9 +47,10 @@ class RapidataValidationSet:
47
47
  Get a `ValidationSet` either by using `rapi.get_validation_set(id)` to get an existing validation set or by using `rapi.new_validation_set(name)` to create a new validation set.
48
48
  """
49
49
 
50
- def __init__(self, validation_set_id, openapi_service: OpenAPIService):
50
+ def __init__(self, validation_set_id, openapi_service: OpenAPIService, name: str):
51
51
  self.id = validation_set_id
52
52
  self.openapi_service = openapi_service
53
+ self.name = name
53
54
 
54
55
  def add_general_validation_rapid(
55
56
  self,
@@ -153,7 +154,7 @@ class RapidataValidationSet:
153
154
  else:
154
155
  raise ValueError("Invalid asset type")
155
156
 
156
- def add_classify_validation_rapid(
157
+ def add_classify_rapid(
157
158
  self,
158
159
  asset: MediaAsset | TextAsset,
159
160
  question: str,
@@ -188,7 +189,7 @@ class RapidataValidationSet:
188
189
  randomCorrectProbability=len(truths) / len(categories),
189
190
  )
190
191
 
191
- def add_compare_validation_rapid(
192
+ def add_compare_rapid(
192
193
  self,
193
194
  asset: MultiAsset,
194
195
  question: str,
@@ -225,7 +226,7 @@ class RapidataValidationSet:
225
226
  randomCorrectProbability=1 / len(asset),
226
227
  )
227
228
 
228
- def add_transcription_validation_rapid(
229
+ def add_transcription_rapid(
229
230
  self,
230
231
  asset: MediaAsset | TextAsset,
231
232
  question: str,
@@ -58,6 +58,7 @@ class ValidationSetBuilder:
58
58
  validation_set = RapidataValidationSet(
59
59
  validation_set_id=self.validation_set_id,
60
60
  openapi_service=self.openapi_service,
61
+ name=self.name,
61
62
  )
62
63
 
63
64
  for rapid_part in self._rapid_parts:
@@ -1,7 +1,7 @@
1
1
  from rapidata.api_client.models.feature_flag_model import FeatureFlagModel
2
- from enum import StrEnum
2
+ from enum import Enum
3
3
 
4
- class TranslationBehaviour(StrEnum):
4
+ class TranslationBehaviour(Enum):
5
5
  BOTH = "both"
6
6
  ONLY_ORIGINAL = "only original"
7
7
  ONLY_TRANSLATED = "only translated"
@@ -70,7 +70,7 @@ class FeatureFlags:
70
70
  Returns:
71
71
  FeatureFlags: The current FeatureFlags instance for method chaining.
72
72
  """
73
- self._flags["translation_behaviour"] = behaviour
73
+ self._flags["translation_behaviour"] = behaviour.value
74
74
  return self
75
75
 
76
76
  def free_text_minimum_characters(self, value: int):
@@ -120,4 +120,4 @@ class FeatureFlags:
120
120
  FeatureFlags: The current FeatureFlags instance for method chaining.
121
121
  """
122
122
  self._flags[key] = value
123
- return self
123
+ return self
@@ -20,6 +20,8 @@ from rapidata.api_client.models.root_filter import RootFilter
20
20
  from rapidata.api_client.models.filter import Filter
21
21
  from rapidata.api_client.models.sort_criterion import SortCriterion
22
22
 
23
+ from rapidata.api_client.models.query_validation_set_model import QueryValidationSetModel
24
+
23
25
 
24
26
  class RapidataClient:
25
27
  """The Rapidata client is the main entry point for interacting with the Rapidata API. It allows you to create orders and validation sets. For creating a new order, check out `new_order()`. For creating a new validation set, check out `new_validation_set()`."""
@@ -28,7 +30,7 @@ class RapidataClient:
28
30
  self,
29
31
  client_id: str,
30
32
  client_secret: str,
31
- endpoint: str = "https://auth.rapidata.ai",
33
+ endpoint: str = "https://api.rapidata.ai",
32
34
  token_url: str = "https://auth.rapidata.ai/connect/token",
33
35
  oauth_scope: str = "openid",
34
36
  cert_path: str | None = None,
@@ -71,17 +73,6 @@ class RapidataClient:
71
73
  """
72
74
  return ValidationSetBuilder(name=name, openapi_service=self.openapi_service)
73
75
 
74
- def get_validation_set(self, validation_set_id: str) -> RapidataValidationSet:
75
- """Get a validation set by ID.
76
-
77
- Args:
78
- validation_set_id (str): The ID of the validation set.
79
-
80
- Returns:
81
- RapidataValidationSet: The ValidationSet instance.
82
- """
83
- return RapidataValidationSet(validation_set_id, self.openapi_service)
84
-
85
76
  def get_order(self, order_id: str) -> RapidataOrder:
86
77
  """Get an order by ID.
87
78
 
@@ -106,7 +97,7 @@ class RapidataClient:
106
97
  order_id=order_id,
107
98
  name=order.order_name,
108
99
  openapi_service=self.openapi_service)
109
-
100
+
110
101
  def find_orders(self, name: str = "", amount: int = 1) -> list[RapidataOrder]:
111
102
  """Find your recent orders given criteria. If nothing is provided, it will return the most recent order.
112
103
 
@@ -123,16 +114,49 @@ class RapidataClient:
123
114
  filter=RootFilter(filters=[Filter(field="OrderName", operator="Contains", value=name)]),
124
115
  sortCriteria=[SortCriterion(direction="Desc", propertyName="OrderDate")]
125
116
  ))
126
-
117
+
127
118
  except BadRequestException as e:
128
119
  raise ValueError(f"Error occured during request. \nError: {e.body} \nTraceid: {e.headers.get('X-Trace-Id') if isinstance(e.headers, HTTPHeaderDict) else 'Unknown'}")
129
120
 
130
121
  except Exception as e:
131
122
  raise ValueError(f"Unknown error occured: {e}")
132
-
123
+
133
124
  orders = [self.get_order(order.id) for order in order_page_result.items]
134
125
  return orders
135
126
 
127
+ def get_validation_set(self, validation_set_id: str) -> RapidataValidationSet:
128
+ """Get a validation set by ID.
129
+
130
+ Args:
131
+ validation_set_id (str): The ID of the validation set.
132
+
133
+ Returns:
134
+ RapidataValidationSet: The ValidationSet instance.
135
+ """
136
+ try:
137
+ validation_set = self.openapi_service.validation_api.validation_get_by_id_get(id=validation_set_id)
138
+ except Exception:
139
+ raise ValueError(f"ValidationSet with ID {validation_set_id} not found.")
140
+
141
+ return RapidataValidationSet(validation_set_id, self.openapi_service, validation_set.name)
142
+
143
+ def find_validation_sets(self, name: str = "", amount: int = 1) -> list[RapidataValidationSet]:
144
+ try:
145
+ validation_page_result = self.openapi_service.validation_api.validation_query_validation_sets_get(QueryValidationSetModel(
146
+ pageInfo=PageInfo(index=1, size=amount),
147
+ filter=RootFilter(filters=[Filter(field="Name", operator="Contains", value=name)]),
148
+ sortCriteria=[SortCriterion(direction="Desc", propertyName="CreatedAt")]
149
+ ))
150
+
151
+ except BadRequestException as e:
152
+ raise ValueError(f"Error occured during request. \nError: {e.body} \nTraceid: {e.headers.get('X-Trace-Id') if isinstance(e.headers, HTTPHeaderDict) else 'Unknown'}")
153
+
154
+ except Exception as e:
155
+ raise ValueError(f"Unknown error occured: {e}")
156
+
157
+ orders = [self.get_validation_set(validation_set.id) for validation_set in validation_page_result.items] # type: ignore # will be fixed with the next backend deployment
158
+ return orders
159
+
136
160
  def create_classify_order(self, name: str) -> ClassificationQuestionBuilder:
137
161
  """Create a new classification order where people are asked to classify an image.
138
162
 
@@ -143,7 +167,7 @@ class RapidataClient:
143
167
  ClassificationQuestionBuilder: A ClassificationQuestionBuilder instance.
144
168
  """
145
169
  return ClassificationQuestionBuilder(name=name, openapi_service=self.openapi_service)
146
-
170
+
147
171
  def create_compare_order(self, name: str) -> CompareCriteriaBuilder:
148
172
  """Create a new comparison order where people are asked to compare two images.
149
173
 
@@ -1,5 +1,7 @@
1
1
  import json
2
+ import time
2
3
  import requests
4
+ import threading
3
5
  from rapidata.api_client.api.campaign_api import CampaignApi
4
6
  from rapidata.api_client.api.dataset_api import DatasetApi
5
7
  from rapidata.api_client.api.order_api import OrderApi
@@ -13,6 +15,8 @@ from rapidata.api_client.configuration import Configuration
13
15
 
14
16
  class OpenAPIService:
15
17
 
18
+ _TOKEN_EXPIRATION_MINUTES = 30
19
+
16
20
  def __init__(
17
21
  self,
18
22
  client_id: str,
@@ -20,18 +24,41 @@ class OpenAPIService:
20
24
  endpoint: str,
21
25
  token_url: str,
22
26
  oauth_scope: str,
23
- cert_path: str | None = None,
27
+ cert_path: str | None = None
24
28
  ):
25
29
  client_configuration = Configuration(host=endpoint, ssl_ca_cert=cert_path)
26
30
  self.api_client = ApiClient(configuration=client_configuration)
27
31
 
28
- token = self.__fetch_token(client_id, client_secret, oauth_scope, token_url, cert_path)
32
+ self._client_id = client_id
33
+ self._client_secret = client_secret
34
+ self._oauth_scope = oauth_scope
35
+ self._token_url = token_url
36
+ self._cert_path = cert_path
29
37
 
30
- client_configuration.api_key["bearer"] = f"Bearer {token}"
31
38
  self._api_client = ApiClient()
32
39
  self._order_api = OrderApi(self.api_client)
33
40
  self._dataset_api = DatasetApi(self.api_client)
34
41
 
42
+ api_token = self.__fetch_token(
43
+ self._client_id, self._client_secret, self._oauth_scope, self._token_url, self._cert_path
44
+ )
45
+ self.api_client.configuration.api_key["bearer"] = f"Bearer {api_token}"
46
+
47
+ refresh_thread = threading.Thread(
48
+ target=lambda: self.__refresh_token_periodically(self._TOKEN_EXPIRATION_MINUTES - 1)
49
+ )
50
+ refresh_thread.daemon = True
51
+ refresh_thread.start()
52
+
53
+ def __refresh_token_periodically(self, refresh_interval):
54
+ while True:
55
+ new_token = self.__fetch_token(
56
+ self._client_id, self._client_secret, self._oauth_scope, self._token_url, self._cert_path
57
+ )
58
+ self.api_client.configuration.api_key["bearer"] = f"Bearer {new_token}"
59
+
60
+ time.sleep(refresh_interval)
61
+
35
62
  @property
36
63
  def order_api(self) -> OrderApi:
37
64
  return self._order_api
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rapidata
3
- Version: 1.4.5
3
+ Version: 1.5.0
4
4
  Summary: Rapidata package containing the Rapidata Python Client to interact with the Rapidata Web API in an easy way.
5
5
  License: Apache-2.0
6
6
  Author: Rapidata AG