personal_knowledge_library 3.3.1__py3-none-any.whl → 3.4.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 personal_knowledge_library might be problematic. Click here for more details.

@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright © 2024 Wacom. All rights reserved.
2
+ # Copyright © 2024-present Wacom. All rights reserved.
3
3
  import asyncio
4
4
  import urllib.parse
5
5
  from typing import List, Any, Optional, Dict
@@ -16,6 +16,7 @@ from knowledge.services import (
16
16
  FORCE_PARAM,
17
17
  APPLICATION_JSON_HEADER,
18
18
  USER_AGENT_HEADER_FLAG,
19
+ DEFAULT_TIMEOUT,
19
20
  )
20
21
  from knowledge.services.asyncio.base import AsyncServiceAPIClient, handle_error
21
22
  from knowledge.services.graph import AUTHORIZATION_HEADER_FLAG, CONTENT_TYPE_HEADER_FLAG
@@ -59,7 +60,11 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
59
60
  # ------------------------------------------ Groups handling ------------------------------------------------------
60
61
 
61
62
  async def create_group(
62
- self, name: str, rights: GroupAccessRight = GroupAccessRight(read=True), auth_key: Optional[str] = None
63
+ self,
64
+ name: str,
65
+ rights: GroupAccessRight = GroupAccessRight(read=True),
66
+ auth_key: Optional[str] = None,
67
+ timeout: int = DEFAULT_TIMEOUT,
63
68
  ) -> Group:
64
69
  """
65
70
  Creates a group.
@@ -74,6 +79,8 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
74
79
  Access rights
75
80
  auth_key: Optional[str]
76
81
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
82
+ timeout: int
83
+ Default timeout for the request (in seconds). Default: 60 seconds.
77
84
 
78
85
  Returns
79
86
  -------
@@ -95,7 +102,9 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
95
102
  }
96
103
  payload: Dict[str, str] = {NAME_TAG: name, GROUP_USER_RIGHTS_TAG: rights.to_list()}
97
104
  async with AsyncServiceAPIClient.__async_session__() as session:
98
- async with session.post(url, headers=headers, json=payload, verify_ssl=self.verify_calls) as response:
105
+ async with session.post(
106
+ url, headers=headers, json=payload, timeout=timeout, verify_ssl=self.verify_calls
107
+ ) as response:
99
108
  if not response.ok:
100
109
  raise await handle_error("Creation of group failed.", response, payload=payload, headers=headers)
101
110
  group: Dict[str, Any] = await response.json(loads=orjson.loads)
@@ -103,7 +112,12 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
103
112
  return Group.parse(group)
104
113
 
105
114
  async def update_group(
106
- self, group_id: str, name: str, rights: GroupAccessRight = GroupAccessRight, auth_key: Optional[str] = None
115
+ self,
116
+ group_id: str,
117
+ name: str,
118
+ rights: GroupAccessRight = GroupAccessRight,
119
+ auth_key: Optional[str] = None,
120
+ timeout: int = DEFAULT_TIMEOUT,
107
121
  ):
108
122
  """
109
123
  Updates a group.
@@ -120,7 +134,8 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
120
134
  Access rights
121
135
  auth_key: Optional[str]
122
136
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
123
-
137
+ timeout: int
138
+ Default timeout for the request (in seconds). Default: 60 seconds.
124
139
  Raises
125
140
  ------
126
141
  WacomServiceException
@@ -136,12 +151,16 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
136
151
  }
137
152
  payload: Dict[str, str] = {NAME_TAG: name, GROUP_USER_RIGHTS_TAG: rights.to_list()}
138
153
  async with AsyncServiceAPIClient.__async_session__() as session:
139
- async with session.patch(url, headers=headers, json=payload, verify_ssl=self.verify_calls) as response:
154
+ async with session.patch(
155
+ url, headers=headers, json=payload, timeout=timeout, verify_ssl=self.verify_calls
156
+ ) as response:
140
157
  if not response.ok:
141
158
  raise await handle_error("Update of group failed.", response, payload=payload, headers=headers)
142
159
  await asyncio.sleep(0.25 if self.use_graceful_shutdown else 0.0)
143
160
 
144
- async def delete_group(self, group_id: str, force: bool = False, auth_key: Optional[str] = None):
161
+ async def delete_group(
162
+ self, group_id: str, force: bool = False, auth_key: Optional[str] = None, timeout: int = DEFAULT_TIMEOUT
163
+ ):
145
164
  """
146
165
  Delete a group.
147
166
 
@@ -153,6 +172,8 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
153
172
  If True, the group will be deleted even if it is not empty.
154
173
  auth_key: Optional[str]
155
174
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
175
+ timeout: int
176
+ Default timeout for the request (in seconds). Default: 60 seconds.
156
177
 
157
178
  Raises
158
179
  ------
@@ -168,13 +189,20 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
168
189
  }
169
190
  params: Dict[str, str] = {FORCE_TAG: str(force).lower()}
170
191
  async with AsyncServiceAPIClient.__async_session__() as session:
171
- async with session.delete(url, headers=headers, params=params, verify_ssl=self.verify_calls) as response:
192
+ async with session.delete(
193
+ url, headers=headers, params=params, timeout=timeout, verify_ssl=self.verify_calls
194
+ ) as response:
172
195
  if not response.ok:
173
196
  raise await handle_error("Deletion of group failed.", response, headers=headers)
174
197
  await asyncio.sleep(0.25 if self.use_graceful_shutdown else 0.0)
175
198
 
176
199
  async def listing_groups(
177
- self, admin: bool = False, limit: int = 20, offset: int = 0, auth_key: Optional[str] = None
200
+ self,
201
+ admin: bool = False,
202
+ limit: int = 20,
203
+ offset: int = 0,
204
+ auth_key: Optional[str] = None,
205
+ timeout: int = DEFAULT_TIMEOUT,
178
206
  ) -> List[Group]:
179
207
  """
180
208
  Listing all groups configured for this instance.
@@ -190,6 +218,8 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
190
218
  Offset of the first group to return.
191
219
  auth_key: Optional[str]
192
220
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
221
+ timeout: int
222
+ Default timeout for the request (in seconds). Default: 60 seconds.
193
223
 
194
224
  Returns
195
225
  -------
@@ -212,7 +242,9 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
212
242
  USER_AGENT_HEADER_FLAG: self.user_agent,
213
243
  }
214
244
  async with AsyncServiceAPIClient.__async_session__() as session:
215
- async with session.get(url, headers=headers, params=params, verify_ssl=self.verify_calls) as response:
245
+ async with session.get(
246
+ url, headers=headers, params=params, timeout=timeout, verify_ssl=self.verify_calls
247
+ ) as response:
216
248
  if response.ok:
217
249
  groups: List[Dict[str, Any]] = await response.json(loads=orjson.loads)
218
250
  else:
@@ -220,7 +252,7 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
220
252
  await asyncio.sleep(0.25 if self.use_graceful_shutdown else 0.0)
221
253
  return [Group.parse(g) for g in groups]
222
254
 
223
- async def group(self, group_id: str, auth_key: Optional[str] = None) -> GroupInfo:
255
+ async def group(self, group_id: str, auth_key: Optional[str] = None, timeout: int = DEFAULT_TIMEOUT) -> GroupInfo:
224
256
  """Get a group.
225
257
 
226
258
  Parameters
@@ -229,6 +261,8 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
229
261
  Group ID
230
262
  auth_key: Optional[str]
231
263
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
264
+ timeout: int
265
+ Default timeout for the request (in seconds). Default: 60 seconds.
232
266
 
233
267
  Returns
234
268
  -------
@@ -248,14 +282,16 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
248
282
  USER_AGENT_HEADER_FLAG: self.user_agent,
249
283
  }
250
284
  async with AsyncServiceAPIClient.__async_session__() as session:
251
- async with session.get(url, headers=headers, verify_ssl=self.verify_calls) as response:
285
+ async with session.get(url, headers=headers, timeout=timeout, verify_ssl=self.verify_calls) as response:
252
286
  if response.ok:
253
287
  group: Dict[str, Any] = await response.json(loads=orjson.loads)
254
288
  else:
255
289
  raise await handle_error("Getting of group information failed.", response, headers=headers)
256
290
  return GroupInfo.parse(group)
257
291
 
258
- async def join_group(self, group_id: str, join_key: str, auth_key: Optional[str] = None):
292
+ async def join_group(
293
+ self, group_id: str, join_key: str, auth_key: Optional[str] = None, timeout: int = DEFAULT_TIMEOUT
294
+ ):
259
295
  """User joining a group with his auth token.
260
296
 
261
297
  Parameters
@@ -265,8 +301,9 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
265
301
  join_key: str
266
302
  Key which is used to join the group.
267
303
  auth_key: Optional[str]
268
- If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
269
-
304
+ If the auth key is set, the logged-in user (if any) will be ignored and the auth key will be used.
305
+ timeout: int
306
+ Default timeout for the request (in seconds). Default: 60 seconds.
270
307
  Raises
271
308
  ------
272
309
  WacomServiceException
@@ -283,12 +320,14 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
283
320
  JOIN_KEY_PARAM: join_key,
284
321
  }
285
322
  async with AsyncServiceAPIClient.__async_session__() as session:
286
- async with session.post(url, headers=headers, params=params, verify_ssl=self.verify_calls) as response:
323
+ async with session.post(
324
+ url, headers=headers, params=params, timeout=timeout, verify_ssl=self.verify_calls
325
+ ) as response:
287
326
  if not response.ok:
288
327
  raise await handle_error("Joining of group failed.", response, headers=headers, parameters=params)
289
328
  await asyncio.sleep(0.25 if self.use_graceful_shutdown else 0.0)
290
329
 
291
- async def leave_group(self, group_id: str, auth_key: Optional[str] = None):
330
+ async def leave_group(self, group_id: str, auth_key: Optional[str] = None, timeout: int = DEFAULT_TIMEOUT):
292
331
  """User leaving a group with his auth token.
293
332
 
294
333
  Parameters
@@ -297,6 +336,8 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
297
336
  Group ID
298
337
  auth_key: Optional[str]
299
338
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
339
+ timeout: int
340
+ Default timeout for the request (in seconds). Default: 60 seconds.
300
341
 
301
342
  Raises
302
343
  ------
@@ -311,12 +352,14 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
311
352
  USER_AGENT_HEADER_FLAG: self.user_agent,
312
353
  }
313
354
  async with AsyncServiceAPIClient.__async_session__() as session:
314
- async with session.post(url, headers=headers, verify_ssl=self.verify_calls) as response:
355
+ async with session.post(url, headers=headers, timeout=timeout, verify_ssl=self.verify_calls) as response:
315
356
  if not response.ok:
316
357
  raise await handle_error("Leaving of group failed.", response, headers=headers)
317
358
  await asyncio.sleep(0.25 if self.use_graceful_shutdown else 0.0)
318
359
 
319
- async def add_user_to_group(self, group_id: str, user_id: str, auth_key: Optional[str] = None):
360
+ async def add_user_to_group(
361
+ self, group_id: str, user_id: str, auth_key: Optional[str] = None, timeout: int = DEFAULT_TIMEOUT
362
+ ):
320
363
  """Adding a user to group.
321
364
 
322
365
  Parameters
@@ -327,6 +370,8 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
327
370
  User who is added to the group
328
371
  auth_key: Optional[str]
329
372
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
373
+ timeout: int
374
+ Default timeout for the request (in seconds). Default: 60 seconds.
330
375
 
331
376
  Raises
332
377
  ------
@@ -344,7 +389,9 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
344
389
  USER_TO_ADD_PARAM: user_id,
345
390
  }
346
391
  async with AsyncServiceAPIClient.__async_session__() as session:
347
- async with session.post(url, headers=headers, params=params, verify_ssl=self.verify_calls) as response:
392
+ async with session.post(
393
+ url, headers=headers, params=params, timeout=timeout, verify_ssl=self.verify_calls
394
+ ) as response:
348
395
  if not response.ok:
349
396
  raise await handle_error(
350
397
  "Adding of user to group failed.", response, headers=headers, parameters=params
@@ -352,7 +399,12 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
352
399
  await asyncio.sleep(0.25 if self.use_graceful_shutdown else 0.0)
353
400
 
354
401
  async def remove_user_from_group(
355
- self, group_id: str, user_id: str, force: bool = False, auth_key: Optional[str] = None
402
+ self,
403
+ group_id: str,
404
+ user_id: str,
405
+ force: bool = False,
406
+ auth_key: Optional[str] = None,
407
+ timeout: int = DEFAULT_TIMEOUT,
356
408
  ):
357
409
  """Remove a user from group.
358
410
 
@@ -366,7 +418,8 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
366
418
  If true remove user and entities owned by the user if any
367
419
  auth_key: Optional[str]
368
420
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
369
-
421
+ timeout: int
422
+ Default timeout for the request (in seconds). Default: 60 seconds.
370
423
  Raises
371
424
  ------
372
425
  WacomServiceException
@@ -381,7 +434,9 @@ class AsyncGroupManagementService(AsyncServiceAPIClient):
381
434
  }
382
435
  params: Dict[str, str] = {USER_TO_REMOVE_PARAM: user_id, FORCE_PARAM: str(force)}
383
436
  async with AsyncServiceAPIClient.__async_session__() as session:
384
- async with session.post(url, headers=headers, params=params, verify_ssl=self.verify_calls) as response:
437
+ async with session.post(
438
+ url, headers=headers, params=params, timeout=timeout, verify_ssl=self.verify_calls
439
+ ) as response:
385
440
  if not response.ok:
386
441
  raise await handle_error(
387
442
  "Removing of user from group failed.", response, headers=headers, parameters=params
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright © 2024 Wacom. All rights reserved.
2
+ # Copyright © 2024-present Wacom. All rights reserved.
3
3
  import asyncio
4
- from typing import Dict, Any, Optional, List
4
+ from typing import Dict, Any, Optional, List, Literal
5
5
 
6
6
  import orjson
7
7
 
@@ -35,7 +35,7 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
35
35
  super().__init__("Async Semantic Search ", service_url, service_endpoint)
36
36
 
37
37
  async def retrieve_document_chunks(
38
- self, locale: LocaleCode, uri: str, auth_key: Optional[str] = None
38
+ self, locale: LocaleCode, uri: str, auth_key: Optional[str] = None, timeout: int = DEFAULT_TIMEOUT
39
39
  ) -> List[VectorDBDocument]:
40
40
  """
41
41
  Retrieve document chunks from vector database. The service is automatically chunking the document into
@@ -49,6 +49,8 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
49
49
  URI of the document
50
50
  auth_key: Optional[str] (Default:= None)
51
51
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
52
+ timeout: int
53
+ Default timeout for the request (default: 60 seconds)
52
54
 
53
55
  Returns
54
56
  -------
@@ -71,7 +73,7 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
71
73
  }
72
74
  async with self.__async_session__() as session:
73
75
  async with session.get(
74
- url, params={"locale": locale, "uri": uri}, headers=headers, timeout=DEFAULT_TIMEOUT
76
+ url, params={"locale": locale, "uri": uri}, headers=headers, timeout=timeout
75
77
  ) as response:
76
78
  if response.ok:
77
79
  docs: List[VectorDBDocument] = [
@@ -88,7 +90,7 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
88
90
  return docs
89
91
 
90
92
  async def retrieve_labels(
91
- self, locale: LocaleCode, uri: str, auth_key: Optional[str] = None
93
+ self, locale: LocaleCode, uri: str, auth_key: Optional[str] = None, timeout: int = DEFAULT_TIMEOUT
92
94
  ) -> List[VectorDBDocument]:
93
95
  """
94
96
  Retrieve labels from vector database.
@@ -101,6 +103,8 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
101
103
  URI of the document
102
104
  auth_key: Optional[str] (Default:= None)
103
105
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
106
+ timeout: int
107
+ Default timeout for the request (default: 60 seconds)
104
108
 
105
109
  Returns
106
110
  -------
@@ -123,7 +127,7 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
123
127
  }
124
128
  async with self.__async_session__() as session:
125
129
  async with session.get(
126
- url, params={"locale": locale, "uri": uri}, headers=headers, timeout=DEFAULT_TIMEOUT
130
+ url, params={"locale": locale, "uri": uri}, headers=headers, timeout=timeout
127
131
  ) as response:
128
132
  if response.ok:
129
133
  docs: List[VectorDBDocument] = [
@@ -140,7 +144,11 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
140
144
  return docs
141
145
 
142
146
  async def count_documents(
143
- self, locale: LocaleCode, concept_type: Optional[str] = None, auth_key: Optional[str] = None
147
+ self,
148
+ locale: LocaleCode,
149
+ concept_type: Optional[str] = None,
150
+ auth_key: Optional[str] = None,
151
+ timeout: int = DEFAULT_TIMEOUT,
144
152
  ) -> int:
145
153
  """
146
154
  Count all documents for a tenant.
@@ -153,6 +161,8 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
153
161
  Concept type.
154
162
  auth_key: Optional[str] (Default:= None)
155
163
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
164
+ timeout: int
165
+ Default timeout for the request (default: 60 seconds)
156
166
 
157
167
  Returns
158
168
  -------
@@ -176,7 +186,7 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
176
186
  if concept_type:
177
187
  params["concept_type"] = concept_type
178
188
  async with self.__async_session__() as session:
179
- async with session.get(url, params=params, headers=headers) as response:
189
+ async with session.get(url, params=params, headers=headers, timeout=timeout) as response:
180
190
  if response.ok:
181
191
  count: int = (await response.json(loads=orjson.loads)).get("count", 0)
182
192
  else:
@@ -187,7 +197,11 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
187
197
  return count
188
198
 
189
199
  async def count_documents_filter(
190
- self, locale: LocaleCode, filters: Dict[str, Any], auth_key: Optional[str] = None
200
+ self,
201
+ locale: LocaleCode,
202
+ filters: Dict[str, Any],
203
+ auth_key: Optional[str] = None,
204
+ timeout: int = DEFAULT_TIMEOUT,
191
205
  ) -> int:
192
206
  """
193
207
  Count all documents for a tenant using a filter.
@@ -200,6 +214,8 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
200
214
  Filters for the search
201
215
  auth_key: Optional[str] (Default:= None)
202
216
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
217
+ timeout: int
218
+ Default timeout for the request (default: 60 seconds).
203
219
 
204
220
  Returns
205
221
  -------
@@ -220,7 +236,9 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
220
236
  AUTHORIZATION_HEADER_FLAG: f"Bearer {auth_key}",
221
237
  }
222
238
  async with self.__async_session__() as session:
223
- async with session.post(url, json={"locale": locale, "filter": filters}, headers=headers) as response:
239
+ async with session.post(
240
+ url, json={"locale": locale, "filter": filters}, timeout=timeout, headers=headers
241
+ ) as response:
224
242
  if response.ok:
225
243
  count: int = (await response.json(loads=orjson.loads)).get("count", 0)
226
244
  else:
@@ -234,7 +252,11 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
234
252
  return count
235
253
 
236
254
  async def count_labels(
237
- self, locale: str, concept_type: Optional[str] = None, auth_key: Optional[str] = None
255
+ self,
256
+ locale: str,
257
+ concept_type: Optional[str] = None,
258
+ auth_key: Optional[str] = None,
259
+ timeout: int = DEFAULT_TIMEOUT,
238
260
  ) -> int:
239
261
  """
240
262
  Count all labels entries for a tenant.
@@ -247,6 +269,8 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
247
269
  Concept type.
248
270
  auth_key: Optional[str] (Default:= None)
249
271
  If auth key is provided, it will be used for the request.
272
+ timeout: int
273
+ Default timeout for the request (default: 60 seconds)
250
274
 
251
275
  Returns
252
276
  -------
@@ -270,7 +294,7 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
270
294
  if concept_type:
271
295
  params["concept_type"] = concept_type
272
296
  async with self.__async_session__() as session:
273
- async with session.get(url, params=params, headers=headers) as response:
297
+ async with session.get(url, params=params, headers=headers, timeout=timeout) as response:
274
298
  if response.ok:
275
299
  count: int = (await response.json(loads=orjson.loads)).get("count", 0)
276
300
  else:
@@ -281,7 +305,11 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
281
305
  return count
282
306
 
283
307
  async def count_labels_filter(
284
- self, locale: LocaleCode, filters: Dict[str, Any], auth_key: Optional[str] = None
308
+ self,
309
+ locale: LocaleCode,
310
+ filters: Dict[str, Any],
311
+ auth_key: Optional[str] = None,
312
+ timeout: int = DEFAULT_TIMEOUT,
285
313
  ) -> int:
286
314
  """
287
315
  Count all labels for a tenant using a filter.
@@ -294,6 +322,8 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
294
322
  Filters for the search
295
323
  auth_key: Optional[str] (Default:= None)
296
324
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
325
+ timeout: int
326
+ Default timeout for the request (default: 60 seconds).
297
327
 
298
328
  Returns
299
329
  -------
@@ -314,7 +344,9 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
314
344
  AUTHORIZATION_HEADER_FLAG: f"Bearer {auth_key}",
315
345
  }
316
346
  async with self.__async_session__() as session:
317
- async with session.post(url, json={"locale": locale, "filter": filters}, headers=headers) as response:
347
+ async with session.post(
348
+ url, json={"locale": locale, "filter": filters}, timeout=timeout, headers=headers
349
+ ) as response:
318
350
  if response.ok:
319
351
  count: int = (await response.json(loads=orjson.loads)).get("count", 0)
320
352
  else:
@@ -333,7 +365,9 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
333
365
  locale: str,
334
366
  filters: Optional[Dict[str, Any]] = None,
335
367
  max_results: int = 10,
368
+ filter_mode: Optional[Literal["AND", "OR"]] = None,
336
369
  auth_key: Optional[str] = None,
370
+ timeout: int = DEFAULT_TIMEOUT,
337
371
  ) -> DocumentSearchResponse:
338
372
  """
339
373
  Async Semantic search.
@@ -348,9 +382,12 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
348
382
  Filters for the search
349
383
  max_results: int
350
384
  Maximum number of results
385
+ filter_mode: Optional[Literal["AND", "OR"]] = None
386
+ Filter mode for the search. If None is provided, the default is "AND".
351
387
  auth_key: Optional[str] (Default:= None)
352
388
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
353
-
389
+ timeout: int
390
+ Default timeout for the request (default: 60 seconds)
354
391
  Returns
355
392
  -------
356
393
  response: DocumentSearchResponse
@@ -375,8 +412,10 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
375
412
  "locale": locale,
376
413
  "max_results": max_results,
377
414
  }
415
+ if filter_mode:
416
+ params["filter_mode"] = filter_mode
378
417
  async with self.__async_session__() as session:
379
- async with session.post(url, headers=headers, json=params) as response:
418
+ async with session.post(url, headers=headers, json=params, timeout=timeout) as response:
380
419
  if response.ok:
381
420
  response_dict: Dict[str, Any] = await response.json(loads=orjson.loads)
382
421
  else:
@@ -390,7 +429,9 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
390
429
  locale: str,
391
430
  filters: Optional[Dict[str, Any]] = None,
392
431
  max_results: int = 10,
432
+ filter_mode: Optional[Literal["AND", "OR"]] = None,
393
433
  auth_key: Optional[str] = None,
434
+ timeout: int = DEFAULT_TIMEOUT,
394
435
  ) -> LabelMatchingResponse:
395
436
  """
396
437
  Async search for semantically similar labels.
@@ -405,9 +446,12 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
405
446
  Filters for the search
406
447
  max_results: int
407
448
  Maximum number of results
449
+ filter_mode: Optional[Literal["AND", "OR"]] = None
450
+ Filter mode for the search. If None is provided, the default is "AND".
408
451
  auth_key: Optional[str] (Default:= None)
409
452
  If the auth key is set the logged-in user (if any) will be ignored and the auth key will be used.
410
-
453
+ timeout: int
454
+ Default timeout for the request (default: 60 seconds).
411
455
  Returns
412
456
  -------
413
457
  response: LabelMatchingResponse
@@ -427,8 +471,10 @@ class AsyncSemanticSearchClient(AsyncServiceAPIClient):
427
471
  "locale": locale,
428
472
  "max_results": max_results,
429
473
  }
474
+ if filter_mode:
475
+ params["filter_mode"] = filter_mode
430
476
  async with self.__async_session__() as session:
431
- async with session.post(url, headers=headers, json=params) as response:
477
+ async with session.post(url, headers=headers, json=params, timeout=timeout) as response:
432
478
  if response.ok:
433
479
  response_dict: Dict[str, Any] = await response.json(loads=orjson.loads)
434
480
  else:
@@ -59,7 +59,12 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
59
59
  # ------------------------------------------ Users handling --------------------------------------------------------
60
60
 
61
61
  async def create_user(
62
- self, tenant_key: str, external_id: str, meta_data: Dict[str, str] = None, roles: List[UserRole] = None
62
+ self,
63
+ tenant_key: str,
64
+ external_id: str,
65
+ meta_data: Dict[str, str] = None,
66
+ roles: List[UserRole] = None,
67
+ timeout: int = DEFAULT_TIMEOUT,
63
68
  ) -> Tuple[User, str, str, datetime]:
64
69
  """
65
70
  Creates user for a tenant.
@@ -74,6 +79,8 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
74
79
  Meta-data dictionary.
75
80
  roles: List[UserRole]
76
81
  List of roles.
82
+ timeout: int
83
+ Denotes the timeout for the request in seconds (default: 60 seconds).
77
84
 
78
85
  Returns
79
86
  -------
@@ -103,7 +110,7 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
103
110
  }
104
111
  async with self.__async_session__() as session:
105
112
  async with session.post(
106
- url, headers=headers, json=payload, timeout=DEFAULT_TIMEOUT, verify_ssl=self.verify_calls
113
+ url, headers=headers, json=payload, timeout=timeout, verify_ssl=self.verify_calls
107
114
  ) as response:
108
115
  if response.ok:
109
116
  results: Dict[str, Union[str, Dict[str, str], List[str]]] = await response.json(loads=orjson.loads)
@@ -130,6 +137,7 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
130
137
  external_id: str,
131
138
  meta_data: Dict[str, str] = None,
132
139
  roles: List[UserRole] = None,
140
+ timeout: int = DEFAULT_TIMEOUT,
133
141
  ):
134
142
  """Updates user for a tenant.
135
143
 
@@ -145,6 +153,8 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
145
153
  Meta-data dictionary.
146
154
  roles: List[UserRole]
147
155
  List of roles.
156
+ timeout: int
157
+ Denotes the timeout for the request in seconds (default: 60 seconds).
148
158
 
149
159
  Raises
150
160
  ------
@@ -164,13 +174,15 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
164
174
  params: Dict[str, str] = {USER_ID_TAG: internal_id, EXTERNAL_USER_ID_TAG: external_id}
165
175
  async with self.__async_session__() as session:
166
176
  async with session.patch(
167
- url, headers=headers, json=payload, params=params, timeout=DEFAULT_TIMEOUT, verify_ssl=self.verify_calls
177
+ url, headers=headers, json=payload, params=params, timeout=timeout, verify_ssl=self.verify_calls
168
178
  ) as response:
169
179
  if not response.ok:
170
180
  raise await handle_error("Failed to update the user.", response, headers=headers, payload=payload)
171
181
  await asyncio.sleep(0.25 if self.use_graceful_shutdown else 0.0)
172
182
 
173
- async def delete_user(self, tenant_key: str, external_id: str, internal_id: str, force: bool = False):
183
+ async def delete_user(
184
+ self, tenant_key: str, external_id: str, internal_id: str, force: bool = False, timeout: int = DEFAULT_TIMEOUT
185
+ ):
174
186
  """Deletes user from tenant.
175
187
 
176
188
  Parameters
@@ -183,6 +195,8 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
183
195
  Internal id of user.
184
196
  force: bool
185
197
  If set to true removes all user data including groups and entities.
198
+ timeout: int
199
+ Default timeout for the request (in seconds) (Default:= 60 seconds).
186
200
 
187
201
  Raises
188
202
  ------
@@ -194,13 +208,13 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
194
208
  params: Dict[str, str] = {USER_ID_TAG: internal_id, EXTERNAL_USER_ID_TAG: external_id, FORCE_TAG: str(force)}
195
209
  async with self.__async_session__() as session:
196
210
  async with session.delete(
197
- url, headers=headers, params=params, timeout=DEFAULT_TIMEOUT, verify_ssl=self.verify_calls
211
+ url, headers=headers, params=params, timeout=timeout, verify_ssl=self.verify_calls
198
212
  ) as response:
199
213
  if not response.ok:
200
214
  raise await handle_error("Failed to delete the user.", response, headers=headers)
201
215
  await asyncio.sleep(0.25 if self.use_graceful_shutdown else 0.0)
202
216
 
203
- async def user_internal_id(self, tenant_key: str, external_id: str) -> str:
217
+ async def user_internal_id(self, tenant_key: str, external_id: str, timeout: int = DEFAULT_TIMEOUT) -> str:
204
218
  """User internal id.
205
219
 
206
220
  Parameters
@@ -209,7 +223,8 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
209
223
  API key for tenant
210
224
  external_id: str
211
225
  External id of user
212
-
226
+ timeout: int
227
+ Default timeout for the request (in seconds) (Default:= 60 seconds).
213
228
  Returns
214
229
  -------
215
230
  internal_user_id: str
@@ -225,7 +240,7 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
225
240
  parameters: Dict[str, str] = {EXTERNAL_USER_ID_TAG: external_id}
226
241
  async with self.__async_session__() as session:
227
242
  async with session.get(
228
- url, headers=headers, params=parameters, timeout=DEFAULT_TIMEOUT, verify_ssl=self.verify_calls
243
+ url, headers=headers, params=parameters, timeout=timeout, verify_ssl=self.verify_calls
229
244
  ) as response:
230
245
  if response.ok:
231
246
  response_dict: Dict[str, Any] = await response.json(loads=orjson.loads)
@@ -234,7 +249,9 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
234
249
  await asyncio.sleep(0.25 if self.use_graceful_shutdown else 0.0)
235
250
  return response_dict[INTERNAL_USER_ID_TAG]
236
251
 
237
- async def listing_users(self, tenant_key: str, offset: int = 0, limit: int = 20) -> List[User]:
252
+ async def listing_users(
253
+ self, tenant_key: str, offset: int = 0, limit: int = 20, timeout: int = DEFAULT_TIMEOUT
254
+ ) -> List[User]:
238
255
  """
239
256
  Listing all users configured for this instance.
240
257
 
@@ -246,6 +263,8 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
246
263
  Offset value to define starting position in list. [DEFAULT:= 0]
247
264
  limit: int - [optional]
248
265
  Define the limit of the list size. [DEFAULT:= 20]
266
+ timeout: int - [optional]
267
+ Default timeout for the request (in seconds) (Default:= 60 seconds).
249
268
 
250
269
  Returns
251
270
  -------
@@ -254,10 +273,10 @@ class AsyncUserManagementService(AsyncServiceAPIClient):
254
273
  """
255
274
  url: str = f"{self.service_base_url}{AsyncUserManagementService.USER_ENDPOINT}"
256
275
  headers: Dict[str, str] = {USER_AGENT_TAG: self.user_agent, TENANT_API_KEY_FLAG: tenant_key}
257
- params: Dict[str, str] = {OFFSET_TAG: offset, LIMIT_TAG: limit}
276
+ params: Dict[str, int] = {OFFSET_TAG: offset, LIMIT_TAG: limit}
258
277
  async with self.__async_session__() as session:
259
278
  async with session.get(
260
- url, headers=headers, params=params, timeout=DEFAULT_TIMEOUT, verify_ssl=self.verify_calls
279
+ url, headers=headers, params=params, timeout=timeout, verify_ssl=self.verify_calls
261
280
  ) as response:
262
281
  if response.ok:
263
282
  users: List[Dict[str, Any]] = await response.json(loads=orjson.loads)