exa-py 1.15.0__py3-none-any.whl → 1.15.2__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 exa-py might be problematic. Click here for more details.
- exa_py/api.py +3 -0
- exa_py/websets/__init__.py +2 -1
- exa_py/websets/async_client.py +153 -0
- exa_py/websets/client.py +140 -7
- exa_py/websets/core/__init__.py +4 -2
- exa_py/websets/core/async_base.py +77 -0
- exa_py/websets/enrichments/__init__.py +2 -2
- exa_py/websets/enrichments/client.py +89 -0
- exa_py/websets/events/__init__.py +2 -2
- exa_py/websets/events/client.py +103 -0
- exa_py/websets/imports/__init__.py +3 -3
- exa_py/websets/imports/client.py +169 -1
- exa_py/websets/items/__init__.py +2 -2
- exa_py/websets/items/client.py +74 -1
- exa_py/websets/monitors/__init__.py +3 -3
- exa_py/websets/monitors/client.py +36 -0
- exa_py/websets/monitors/runs/__init__.py +2 -2
- exa_py/websets/monitors/runs/client.py +18 -0
- exa_py/websets/searches/__init__.py +2 -2
- exa_py/websets/searches/client.py +47 -0
- exa_py/websets/types.py +151 -7
- exa_py/websets/webhooks/__init__.py +2 -2
- exa_py/websets/webhooks/client.py +63 -1
- {exa_py-1.15.0.dist-info → exa_py-1.15.2.dist-info}/METADATA +1 -1
- exa_py-1.15.2.dist-info/RECORD +37 -0
- exa_py-1.15.0.dist-info/RECORD +0 -35
- {exa_py-1.15.0.dist-info → exa_py-1.15.2.dist-info}/WHEEL +0 -0
exa_py/websets/events/client.py
CHANGED
|
@@ -15,8 +15,16 @@ from ..types import (
|
|
|
15
15
|
WebsetSearchUpdatedEvent,
|
|
16
16
|
WebsetSearchCanceledEvent,
|
|
17
17
|
WebsetSearchCompletedEvent,
|
|
18
|
+
ImportCreatedEvent,
|
|
19
|
+
ImportCompletedEvent,
|
|
20
|
+
MonitorCreatedEvent,
|
|
21
|
+
MonitorUpdatedEvent,
|
|
22
|
+
MonitorDeletedEvent,
|
|
23
|
+
MonitorRunCreatedEvent,
|
|
24
|
+
MonitorRunCompletedEvent,
|
|
18
25
|
)
|
|
19
26
|
from ..core.base import WebsetsBaseClient
|
|
27
|
+
from ..core.async_base import WebsetsAsyncBaseClient
|
|
20
28
|
|
|
21
29
|
# Type alias for all event types
|
|
22
30
|
Event = Union[
|
|
@@ -30,6 +38,13 @@ Event = Union[
|
|
|
30
38
|
WebsetSearchUpdatedEvent,
|
|
31
39
|
WebsetSearchCanceledEvent,
|
|
32
40
|
WebsetSearchCompletedEvent,
|
|
41
|
+
ImportCreatedEvent,
|
|
42
|
+
ImportCompletedEvent,
|
|
43
|
+
MonitorCreatedEvent,
|
|
44
|
+
MonitorUpdatedEvent,
|
|
45
|
+
MonitorDeletedEvent,
|
|
46
|
+
MonitorRunCreatedEvent,
|
|
47
|
+
MonitorRunCompletedEvent,
|
|
33
48
|
]
|
|
34
49
|
|
|
35
50
|
class EventsClient(WebsetsBaseClient):
|
|
@@ -89,6 +104,94 @@ class EventsClient(WebsetsBaseClient):
|
|
|
89
104
|
'webset.search.updated': WebsetSearchUpdatedEvent,
|
|
90
105
|
'webset.search.canceled': WebsetSearchCanceledEvent,
|
|
91
106
|
'webset.search.completed': WebsetSearchCompletedEvent,
|
|
107
|
+
'import.created': ImportCreatedEvent,
|
|
108
|
+
'import.completed': ImportCompletedEvent,
|
|
109
|
+
'monitor.created': MonitorCreatedEvent,
|
|
110
|
+
'monitor.updated': MonitorUpdatedEvent,
|
|
111
|
+
'monitor.deleted': MonitorDeletedEvent,
|
|
112
|
+
'monitor.run.created': MonitorRunCreatedEvent,
|
|
113
|
+
'monitor.run.completed': MonitorRunCompletedEvent,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
event_class = event_type_map.get(event_type)
|
|
117
|
+
if event_class:
|
|
118
|
+
return event_class.model_validate(response)
|
|
119
|
+
else:
|
|
120
|
+
# Fallback - try each type until one validates
|
|
121
|
+
# This shouldn't happen in normal operation
|
|
122
|
+
for event_class in event_type_map.values():
|
|
123
|
+
try:
|
|
124
|
+
return event_class.model_validate(response)
|
|
125
|
+
except Exception:
|
|
126
|
+
continue
|
|
127
|
+
|
|
128
|
+
raise ValueError(f"Unknown event type: {event_type}")
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class AsyncEventsClient(WebsetsAsyncBaseClient):
|
|
132
|
+
"""Async client for managing Events."""
|
|
133
|
+
|
|
134
|
+
def __init__(self, client):
|
|
135
|
+
super().__init__(client)
|
|
136
|
+
|
|
137
|
+
async def list(self, *, cursor: Optional[str] = None, limit: Optional[int] = None,
|
|
138
|
+
types: Optional[List[EventType]] = None) -> ListEventsResponse:
|
|
139
|
+
"""List all Events.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
cursor (str, optional): The cursor to paginate through the results.
|
|
143
|
+
limit (int, optional): The number of results to return.
|
|
144
|
+
types (List[EventType], optional): The types of events to filter by.
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
ListEventsResponse: List of events.
|
|
148
|
+
"""
|
|
149
|
+
params = {}
|
|
150
|
+
if cursor is not None:
|
|
151
|
+
params["cursor"] = cursor
|
|
152
|
+
if limit is not None:
|
|
153
|
+
params["limit"] = limit
|
|
154
|
+
if types is not None:
|
|
155
|
+
# Convert EventType enums to their string values
|
|
156
|
+
params["types"] = [t.value if hasattr(t, 'value') else t for t in types]
|
|
157
|
+
|
|
158
|
+
response = await self.request("/v0/events", params=params, method="GET")
|
|
159
|
+
return ListEventsResponse.model_validate(response)
|
|
160
|
+
|
|
161
|
+
async def get(self, id: str) -> Event:
|
|
162
|
+
"""Get an Event by ID.
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
id (str): The ID of the Event.
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
Event: The retrieved event.
|
|
169
|
+
"""
|
|
170
|
+
response = await self.request(f"/v0/events/{id}", method="GET")
|
|
171
|
+
|
|
172
|
+
# The response should contain a 'type' field that helps us determine
|
|
173
|
+
# which specific event class to use for validation
|
|
174
|
+
event_type = response.get('type')
|
|
175
|
+
|
|
176
|
+
# Map event types to their corresponding classes
|
|
177
|
+
event_type_map = {
|
|
178
|
+
'webset.created': WebsetCreatedEvent,
|
|
179
|
+
'webset.deleted': WebsetDeletedEvent,
|
|
180
|
+
'webset.idle': WebsetIdleEvent,
|
|
181
|
+
'webset.paused': WebsetPausedEvent,
|
|
182
|
+
'webset.item.created': WebsetItemCreatedEvent,
|
|
183
|
+
'webset.item.enriched': WebsetItemEnrichedEvent,
|
|
184
|
+
'webset.search.created': WebsetSearchCreatedEvent,
|
|
185
|
+
'webset.search.updated': WebsetSearchUpdatedEvent,
|
|
186
|
+
'webset.search.canceled': WebsetSearchCanceledEvent,
|
|
187
|
+
'webset.search.completed': WebsetSearchCompletedEvent,
|
|
188
|
+
'import.created': ImportCreatedEvent,
|
|
189
|
+
'import.completed': ImportCompletedEvent,
|
|
190
|
+
'monitor.created': MonitorCreatedEvent,
|
|
191
|
+
'monitor.updated': MonitorUpdatedEvent,
|
|
192
|
+
'monitor.deleted': MonitorDeletedEvent,
|
|
193
|
+
'monitor.run.created': MonitorRunCreatedEvent,
|
|
194
|
+
'monitor.run.completed': MonitorRunCompletedEvent,
|
|
92
195
|
}
|
|
93
196
|
|
|
94
197
|
event_class = event_type_map.get(event_type)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
from .client import ImportsClient
|
|
2
|
-
|
|
3
|
-
__all__ = ["ImportsClient"]
|
|
1
|
+
from .client import ImportsClient, AsyncImportsClient
|
|
2
|
+
|
|
3
|
+
__all__ = ["ImportsClient", "AsyncImportsClient"]
|
exa_py/websets/imports/client.py
CHANGED
|
@@ -4,7 +4,9 @@ import time
|
|
|
4
4
|
import os
|
|
5
5
|
import csv
|
|
6
6
|
import io
|
|
7
|
+
import asyncio
|
|
7
8
|
import requests
|
|
9
|
+
import httpx
|
|
8
10
|
from typing import Dict, Any, Union, Optional
|
|
9
11
|
from pathlib import Path
|
|
10
12
|
|
|
@@ -16,6 +18,7 @@ from ..types import (
|
|
|
16
18
|
UpdateImport,
|
|
17
19
|
)
|
|
18
20
|
from ..core.base import WebsetsBaseClient
|
|
21
|
+
from ..core.async_base import WebsetsAsyncBaseClient
|
|
19
22
|
|
|
20
23
|
class ImportsClient(WebsetsBaseClient):
|
|
21
24
|
"""Client for managing Imports."""
|
|
@@ -176,4 +179,169 @@ class ImportsClient(WebsetsBaseClient):
|
|
|
176
179
|
if time.time() - start_time > timeout:
|
|
177
180
|
raise TimeoutError(f"Import {import_id} did not complete within {timeout} seconds")
|
|
178
181
|
|
|
179
|
-
time.sleep(poll_interval)
|
|
182
|
+
time.sleep(poll_interval)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class AsyncImportsClient(WebsetsAsyncBaseClient):
|
|
186
|
+
"""Async client for managing Imports."""
|
|
187
|
+
|
|
188
|
+
def __init__(self, client):
|
|
189
|
+
super().__init__(client)
|
|
190
|
+
|
|
191
|
+
async def create(
|
|
192
|
+
self,
|
|
193
|
+
params: Union[Dict[str, Any], CreateImportParameters],
|
|
194
|
+
*,
|
|
195
|
+
csv_data: Optional[Union[str, Path]] = None
|
|
196
|
+
) -> Union[CreateImportResponse, Import]:
|
|
197
|
+
"""Create a new import to upload your data into Websets.
|
|
198
|
+
|
|
199
|
+
Imports can be used to:
|
|
200
|
+
- Enrich: Enhance your data with additional information using our AI-powered enrichment engine
|
|
201
|
+
- Search: Query your data using Websets' agentic search with natural language filters
|
|
202
|
+
- Exclude: Prevent duplicate or already known results from appearing in your searches
|
|
203
|
+
|
|
204
|
+
Args:
|
|
205
|
+
params (CreateImportParameters): The parameters for creating an import.
|
|
206
|
+
csv_data (Union[str, Path], optional): CSV data to upload. Can be raw CSV string or file path.
|
|
207
|
+
When provided, size and count will be automatically calculated
|
|
208
|
+
if not specified in params.
|
|
209
|
+
|
|
210
|
+
Returns:
|
|
211
|
+
CreateImportResponse: If csv_data is None (traditional usage with upload URL).
|
|
212
|
+
Import: If csv_data is provided (uploaded and processing).
|
|
213
|
+
"""
|
|
214
|
+
if csv_data is not None:
|
|
215
|
+
if isinstance(csv_data, (str, Path)) and os.path.isfile(csv_data):
|
|
216
|
+
# Use synchronous file reading for simplicity (file reading is typically fast)
|
|
217
|
+
with open(csv_data, 'r', encoding='utf-8') as f:
|
|
218
|
+
csv_content = f.read()
|
|
219
|
+
else:
|
|
220
|
+
csv_content = str(csv_data)
|
|
221
|
+
|
|
222
|
+
if isinstance(params, dict):
|
|
223
|
+
current_size = params.get('size')
|
|
224
|
+
current_count = params.get('count')
|
|
225
|
+
else:
|
|
226
|
+
current_size = getattr(params, 'size', None)
|
|
227
|
+
current_count = getattr(params, 'count', None)
|
|
228
|
+
|
|
229
|
+
if current_size is None or current_count is None:
|
|
230
|
+
calculated_size = len(csv_content.encode('utf-8'))
|
|
231
|
+
csv_reader = csv.reader(io.StringIO(csv_content))
|
|
232
|
+
rows = list(csv_reader)
|
|
233
|
+
calculated_count = max(0, len(rows) - 1)
|
|
234
|
+
|
|
235
|
+
if isinstance(params, dict):
|
|
236
|
+
params = params.copy()
|
|
237
|
+
if current_size is None:
|
|
238
|
+
params['size'] = calculated_size
|
|
239
|
+
if current_count is None:
|
|
240
|
+
params['count'] = calculated_count
|
|
241
|
+
else:
|
|
242
|
+
params_dict = params.model_dump()
|
|
243
|
+
if current_size is None:
|
|
244
|
+
params_dict['size'] = calculated_size
|
|
245
|
+
if current_count is None:
|
|
246
|
+
params_dict['count'] = calculated_count
|
|
247
|
+
params = CreateImportParameters.model_validate(params_dict)
|
|
248
|
+
|
|
249
|
+
response = await self.request("/v0/imports", data=params)
|
|
250
|
+
import_response = CreateImportResponse.model_validate(response)
|
|
251
|
+
|
|
252
|
+
if csv_data is None:
|
|
253
|
+
return import_response
|
|
254
|
+
|
|
255
|
+
# Use httpx for async HTTP requests
|
|
256
|
+
async with httpx.AsyncClient() as http_client:
|
|
257
|
+
upload_response = await http_client.put(
|
|
258
|
+
import_response.upload_url,
|
|
259
|
+
data=csv_content,
|
|
260
|
+
headers={'Content-Type': 'text/csv'}
|
|
261
|
+
)
|
|
262
|
+
upload_response.raise_for_status()
|
|
263
|
+
|
|
264
|
+
return await self.get(import_response.id)
|
|
265
|
+
|
|
266
|
+
async def get(self, import_id: str) -> Import:
|
|
267
|
+
"""Get a specific import.
|
|
268
|
+
|
|
269
|
+
Args:
|
|
270
|
+
import_id (str): The id of the Import.
|
|
271
|
+
|
|
272
|
+
Returns:
|
|
273
|
+
Import: The retrieved import.
|
|
274
|
+
"""
|
|
275
|
+
response = await self.request(f"/v0/imports/{import_id}", method="GET")
|
|
276
|
+
return Import.model_validate(response)
|
|
277
|
+
|
|
278
|
+
async def list(self, *, cursor: Optional[str] = None, limit: Optional[int] = None) -> ListImportsResponse:
|
|
279
|
+
"""List all imports.
|
|
280
|
+
|
|
281
|
+
Args:
|
|
282
|
+
cursor (str, optional): The cursor to paginate through the results.
|
|
283
|
+
limit (int, optional): The number of results to return (1-200, default 25).
|
|
284
|
+
|
|
285
|
+
Returns:
|
|
286
|
+
ListImportsResponse: List of imports with pagination info.
|
|
287
|
+
"""
|
|
288
|
+
params = {
|
|
289
|
+
k: v
|
|
290
|
+
for k, v in {
|
|
291
|
+
"cursor": cursor,
|
|
292
|
+
"limit": limit
|
|
293
|
+
}.items()
|
|
294
|
+
if v is not None
|
|
295
|
+
}
|
|
296
|
+
response = await self.request("/v0/imports", params=params, method="GET")
|
|
297
|
+
return ListImportsResponse.model_validate(response)
|
|
298
|
+
|
|
299
|
+
async def update(self, import_id: str, params: Union[Dict[str, Any], UpdateImport]) -> Import:
|
|
300
|
+
"""Update an import configuration.
|
|
301
|
+
|
|
302
|
+
Args:
|
|
303
|
+
import_id (str): The id of the Import.
|
|
304
|
+
params (UpdateImport): The parameters for updating an import.
|
|
305
|
+
|
|
306
|
+
Returns:
|
|
307
|
+
Import: The updated import.
|
|
308
|
+
"""
|
|
309
|
+
response = await self.request(f"/v0/imports/{import_id}", data=params, method="PATCH")
|
|
310
|
+
return Import.model_validate(response)
|
|
311
|
+
|
|
312
|
+
async def delete(self, import_id: str) -> Import:
|
|
313
|
+
"""Delete an import.
|
|
314
|
+
|
|
315
|
+
Args:
|
|
316
|
+
import_id (str): The id of the Import.
|
|
317
|
+
|
|
318
|
+
Returns:
|
|
319
|
+
Import: The deleted import.
|
|
320
|
+
"""
|
|
321
|
+
response = await self.request(f"/v0/imports/{import_id}", method="DELETE")
|
|
322
|
+
return Import.model_validate(response)
|
|
323
|
+
|
|
324
|
+
async def wait_until_completed(self, import_id: str, *, timeout: int = 1800, poll_interval: int = 5) -> Import:
|
|
325
|
+
"""Wait until an import is completed or failed.
|
|
326
|
+
|
|
327
|
+
Args:
|
|
328
|
+
import_id (str): The id of the Import.
|
|
329
|
+
timeout (int, optional): Maximum time to wait in seconds. Defaults to 1800 (30 minutes).
|
|
330
|
+
poll_interval (int, optional): Time to wait between polls in seconds. Defaults to 5.
|
|
331
|
+
|
|
332
|
+
Returns:
|
|
333
|
+
Import: The import once it's completed or failed.
|
|
334
|
+
|
|
335
|
+
Raises:
|
|
336
|
+
TimeoutError: If the import does not complete within the timeout period.
|
|
337
|
+
"""
|
|
338
|
+
start_time = asyncio.get_event_loop().time()
|
|
339
|
+
while True:
|
|
340
|
+
import_obj = await self.get(import_id)
|
|
341
|
+
if import_obj.status in ['completed', 'failed']:
|
|
342
|
+
return import_obj
|
|
343
|
+
|
|
344
|
+
if asyncio.get_event_loop().time() - start_time > timeout:
|
|
345
|
+
raise TimeoutError(f"Import {import_id} did not complete within {timeout} seconds")
|
|
346
|
+
|
|
347
|
+
await asyncio.sleep(poll_interval)
|
exa_py/websets/items/__init__.py
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
from .client import WebsetItemsClient
|
|
1
|
+
from .client import WebsetItemsClient, AsyncWebsetItemsClient
|
|
2
2
|
|
|
3
|
-
__all__ = ["WebsetItemsClient"]
|
|
3
|
+
__all__ = ["WebsetItemsClient", "AsyncWebsetItemsClient"]
|
exa_py/websets/items/client.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import Optional, Iterator, AsyncIterator
|
|
4
4
|
|
|
5
5
|
from ..types import (
|
|
6
6
|
WebsetItem,
|
|
7
7
|
ListWebsetItemResponse,
|
|
8
8
|
)
|
|
9
9
|
from ..core.base import WebsetsBaseClient
|
|
10
|
+
from ..core.async_base import WebsetsAsyncBaseClient
|
|
10
11
|
|
|
11
12
|
class WebsetItemsClient(WebsetsBaseClient):
|
|
12
13
|
"""Client for managing Webset Items."""
|
|
@@ -77,4 +78,76 @@ class WebsetItemsClient(WebsetsBaseClient):
|
|
|
77
78
|
WebsetItem: The deleted item.
|
|
78
79
|
"""
|
|
79
80
|
response = self.request(f"/v0/websets/{webset_id}/items/{id}", method="DELETE")
|
|
81
|
+
return WebsetItem.model_validate(response)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class AsyncWebsetItemsClient(WebsetsAsyncBaseClient):
|
|
85
|
+
"""Async client for managing Webset Items."""
|
|
86
|
+
|
|
87
|
+
def __init__(self, client):
|
|
88
|
+
super().__init__(client)
|
|
89
|
+
|
|
90
|
+
async def list(self, webset_id: str, *, cursor: Optional[str] = None,
|
|
91
|
+
limit: Optional[int] = None, source_id: Optional[str] = None) -> ListWebsetItemResponse:
|
|
92
|
+
"""List all Items for a Webset.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
webset_id (str): The id or externalId of the Webset.
|
|
96
|
+
cursor (str, optional): The cursor to paginate through the results.
|
|
97
|
+
limit (int, optional): The number of results to return (max 200).
|
|
98
|
+
source_id (str, optional): Filter items by source ID.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
ListWebsetItemResponse: List of webset items.
|
|
102
|
+
"""
|
|
103
|
+
params = {k: v for k, v in {"cursor": cursor, "limit": limit, "sourceId": source_id}.items() if v is not None}
|
|
104
|
+
response = await self.request(f"/v0/websets/{webset_id}/items", params=params, method="GET")
|
|
105
|
+
return ListWebsetItemResponse.model_validate(response)
|
|
106
|
+
|
|
107
|
+
async def list_all(self, webset_id: str, *, limit: Optional[int] = None, source_id: Optional[str] = None) -> AsyncIterator[WebsetItem]:
|
|
108
|
+
"""Iterate through all Items in a Webset, handling pagination automatically.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
webset_id (str): The id or externalId of the Webset.
|
|
112
|
+
limit (int, optional): The number of results to return per page (max 200).
|
|
113
|
+
source_id (str, optional): Filter items by source ID.
|
|
114
|
+
|
|
115
|
+
Yields:
|
|
116
|
+
WebsetItem: Each item in the webset.
|
|
117
|
+
"""
|
|
118
|
+
cursor = None
|
|
119
|
+
while True:
|
|
120
|
+
response = await self.list(webset_id, cursor=cursor, limit=limit, source_id=source_id)
|
|
121
|
+
for item in response.data:
|
|
122
|
+
yield item
|
|
123
|
+
|
|
124
|
+
if not response.has_more or not response.next_cursor:
|
|
125
|
+
break
|
|
126
|
+
|
|
127
|
+
cursor = response.next_cursor
|
|
128
|
+
|
|
129
|
+
async def get(self, webset_id: str, id: str) -> WebsetItem:
|
|
130
|
+
"""Get an Item by ID.
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
webset_id (str): The id or externalId of the Webset.
|
|
134
|
+
id (str): The id of the Webset item.
|
|
135
|
+
|
|
136
|
+
Returns:
|
|
137
|
+
WebsetItem: The retrieved item.
|
|
138
|
+
"""
|
|
139
|
+
response = await self.request(f"/v0/websets/{webset_id}/items/{id}", method="GET")
|
|
140
|
+
return WebsetItem.model_validate(response)
|
|
141
|
+
|
|
142
|
+
async def delete(self, webset_id: str, id: str) -> WebsetItem:
|
|
143
|
+
"""Delete an Item.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
webset_id (str): The id or externalId of the Webset.
|
|
147
|
+
id (str): The id of the Webset item.
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
WebsetItem: The deleted item.
|
|
151
|
+
"""
|
|
152
|
+
response = await self.request(f"/v0/websets/{webset_id}/items/{id}", method="DELETE")
|
|
80
153
|
return WebsetItem.model_validate(response)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from .client import MonitorsClient
|
|
2
|
-
from .runs import MonitorRunsClient
|
|
1
|
+
from .client import MonitorsClient, AsyncMonitorsClient
|
|
2
|
+
from .runs import MonitorRunsClient, AsyncMonitorRunsClient
|
|
3
3
|
|
|
4
|
-
__all__ = ["MonitorsClient", "MonitorRunsClient"]
|
|
4
|
+
__all__ = ["MonitorsClient", "AsyncMonitorsClient", "MonitorRunsClient", "AsyncMonitorRunsClient"]
|
|
@@ -9,6 +9,7 @@ from ..types import (
|
|
|
9
9
|
ListMonitorsResponse,
|
|
10
10
|
)
|
|
11
11
|
from ..core.base import WebsetsBaseClient
|
|
12
|
+
from ..core.async_base import WebsetsAsyncBaseClient
|
|
12
13
|
from .runs import MonitorRunsClient
|
|
13
14
|
|
|
14
15
|
class MonitorsClient(WebsetsBaseClient):
|
|
@@ -93,4 +94,39 @@ class MonitorsClient(WebsetsBaseClient):
|
|
|
93
94
|
Monitor: The deleted monitor.
|
|
94
95
|
"""
|
|
95
96
|
response = self.request(f"/v0/monitors/{monitor_id}", method="DELETE")
|
|
97
|
+
return Monitor.model_validate(response)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class AsyncMonitorsClient(WebsetsAsyncBaseClient):
|
|
101
|
+
"""Async client for managing Monitors."""
|
|
102
|
+
|
|
103
|
+
def __init__(self, client):
|
|
104
|
+
super().__init__(client)
|
|
105
|
+
from .runs import AsyncMonitorRunsClient
|
|
106
|
+
self.runs = AsyncMonitorRunsClient(client)
|
|
107
|
+
|
|
108
|
+
async def create(self, params: Union[Dict[str, Any], CreateMonitorParameters]) -> Monitor:
|
|
109
|
+
"""Create a new Monitor to continuously keep your Websets updated with fresh data."""
|
|
110
|
+
response = await self.request("/v0/monitors", data=params)
|
|
111
|
+
return Monitor.model_validate(response)
|
|
112
|
+
|
|
113
|
+
async def get(self, monitor_id: str) -> Monitor:
|
|
114
|
+
"""Get a specific monitor."""
|
|
115
|
+
response = await self.request(f"/v0/monitors/{monitor_id}", method="GET")
|
|
116
|
+
return Monitor.model_validate(response)
|
|
117
|
+
|
|
118
|
+
async def list(self, *, cursor: Optional[str] = None, limit: Optional[int] = None, webset_id: Optional[str] = None) -> ListMonitorsResponse:
|
|
119
|
+
"""List all monitors."""
|
|
120
|
+
params = {k: v for k, v in {"cursor": cursor, "limit": limit, "websetId": webset_id}.items() if v is not None}
|
|
121
|
+
response = await self.request("/v0/monitors", params=params, method="GET")
|
|
122
|
+
return ListMonitorsResponse.model_validate(response)
|
|
123
|
+
|
|
124
|
+
async def update(self, monitor_id: str, params: Union[Dict[str, Any], UpdateMonitor]) -> Monitor:
|
|
125
|
+
"""Update a monitor configuration."""
|
|
126
|
+
response = await self.request(f"/v0/monitors/{monitor_id}", data=params, method="PATCH")
|
|
127
|
+
return Monitor.model_validate(response)
|
|
128
|
+
|
|
129
|
+
async def delete(self, monitor_id: str) -> Monitor:
|
|
130
|
+
"""Delete a monitor."""
|
|
131
|
+
response = await self.request(f"/v0/monitors/{monitor_id}", method="DELETE")
|
|
96
132
|
return Monitor.model_validate(response)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
from .client import MonitorRunsClient
|
|
1
|
+
from .client import MonitorRunsClient, AsyncMonitorRunsClient
|
|
2
2
|
|
|
3
|
-
__all__ = ["MonitorRunsClient"]
|
|
3
|
+
__all__ = ["MonitorRunsClient", "AsyncMonitorRunsClient"]
|
|
@@ -5,6 +5,7 @@ from ...types import (
|
|
|
5
5
|
ListMonitorRunsResponse,
|
|
6
6
|
)
|
|
7
7
|
from ...core.base import WebsetsBaseClient
|
|
8
|
+
from ...core.async_base import WebsetsAsyncBaseClient
|
|
8
9
|
|
|
9
10
|
class MonitorRunsClient(WebsetsBaseClient):
|
|
10
11
|
"""Client for managing Monitor Runs."""
|
|
@@ -35,4 +36,21 @@ class MonitorRunsClient(WebsetsBaseClient):
|
|
|
35
36
|
MonitorRun: The monitor run details.
|
|
36
37
|
"""
|
|
37
38
|
response = self.request(f"/v0/monitors/{monitor_id}/runs/{run_id}", method="GET")
|
|
39
|
+
return MonitorRun.model_validate(response)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class AsyncMonitorRunsClient(WebsetsAsyncBaseClient):
|
|
43
|
+
"""Async client for managing Monitor Runs."""
|
|
44
|
+
|
|
45
|
+
def __init__(self, client):
|
|
46
|
+
super().__init__(client)
|
|
47
|
+
|
|
48
|
+
async def list(self, monitor_id: str) -> ListMonitorRunsResponse:
|
|
49
|
+
"""List all runs for the Monitor."""
|
|
50
|
+
response = await self.request(f"/v0/monitors/{monitor_id}/runs", method="GET")
|
|
51
|
+
return ListMonitorRunsResponse.model_validate(response)
|
|
52
|
+
|
|
53
|
+
async def get(self, monitor_id: str, run_id: str) -> MonitorRun:
|
|
54
|
+
"""Get a specific monitor run."""
|
|
55
|
+
response = await self.request(f"/v0/monitors/{monitor_id}/runs/{run_id}", method="GET")
|
|
38
56
|
return MonitorRun.model_validate(response)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
from .client import WebsetSearchesClient
|
|
1
|
+
from .client import WebsetSearchesClient, AsyncWebsetSearchesClient
|
|
2
2
|
|
|
3
|
-
__all__ = ["WebsetSearchesClient"]
|
|
3
|
+
__all__ = ["WebsetSearchesClient", "AsyncWebsetSearchesClient"]
|
|
@@ -7,6 +7,7 @@ from ..types import (
|
|
|
7
7
|
WebsetSearch,
|
|
8
8
|
)
|
|
9
9
|
from ..core.base import WebsetsBaseClient
|
|
10
|
+
from ..core.async_base import WebsetsAsyncBaseClient
|
|
10
11
|
|
|
11
12
|
class WebsetSearchesClient(WebsetsBaseClient):
|
|
12
13
|
"""Client for managing Webset Searches."""
|
|
@@ -51,4 +52,50 @@ class WebsetSearchesClient(WebsetsBaseClient):
|
|
|
51
52
|
WebsetSearch: The canceled search.
|
|
52
53
|
"""
|
|
53
54
|
response = self.request(f"/v0/websets/{webset_id}/searches/{id}/cancel", method="POST")
|
|
55
|
+
return WebsetSearch.model_validate(response)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class AsyncWebsetSearchesClient(WebsetsAsyncBaseClient):
|
|
59
|
+
"""Async client for managing Webset Searches."""
|
|
60
|
+
|
|
61
|
+
def __init__(self, client):
|
|
62
|
+
super().__init__(client)
|
|
63
|
+
|
|
64
|
+
async def create(self, webset_id: str, params: Union[Dict[str, Any], CreateWebsetSearchParameters]) -> WebsetSearch:
|
|
65
|
+
"""Create a new Search for the Webset.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
webset_id (str): The id of the Webset.
|
|
69
|
+
params (CreateWebsetSearchParameters): The parameters for creating a search.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
WebsetSearch: The created search.
|
|
73
|
+
"""
|
|
74
|
+
response = await self.request(f"/v0/websets/{webset_id}/searches", data=params)
|
|
75
|
+
return WebsetSearch.model_validate(response)
|
|
76
|
+
|
|
77
|
+
async def get(self, webset_id: str, id: str) -> WebsetSearch:
|
|
78
|
+
"""Get a Search by ID.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
webset_id (str): The id of the Webset.
|
|
82
|
+
id (str): The id of the Search.
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
WebsetSearch: The retrieved search.
|
|
86
|
+
"""
|
|
87
|
+
response = await self.request(f"/v0/websets/{webset_id}/searches/{id}", method="GET")
|
|
88
|
+
return WebsetSearch.model_validate(response)
|
|
89
|
+
|
|
90
|
+
async def cancel(self, webset_id: str, id: str) -> WebsetSearch:
|
|
91
|
+
"""Cancel a running Search.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
webset_id (str): The id of the Webset.
|
|
95
|
+
id (str): The id of the Search.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
WebsetSearch: The canceled search.
|
|
99
|
+
"""
|
|
100
|
+
response = await self.request(f"/v0/websets/{webset_id}/searches/{id}/cancel", method="POST")
|
|
54
101
|
return WebsetSearch.model_validate(response)
|