simplex 1.2.57__py3-none-any.whl → 1.2.59__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 simplex might be problematic. Click here for more details.

simplex/simplex.py CHANGED
@@ -4,7 +4,7 @@ from typing import Optional, Union
4
4
  import os
5
5
  import json
6
6
  import warnings
7
-
7
+ import time
8
8
  # Try to import playwright, but don't fail if it's not available (lite version)
9
9
  try:
10
10
  from playwright.sync_api import sync_playwright
@@ -17,8 +17,8 @@ except ImportError:
17
17
  ImportWarning
18
18
  )
19
19
 
20
+ # BASE_URL = "https://simplex-dev--api-server-fastapi-app.modal.run"
20
21
  BASE_URL = "https://api.simplex.sh"
21
-
22
22
  class Playwright:
23
23
  def __init__(self, simplex_instance):
24
24
  self.simplex = simplex_instance
@@ -61,7 +61,7 @@ class Playwright:
61
61
  print(response.json())
62
62
  raise ValueError(f"It looks like the click action with playwright failed to return a response. Did you set your api_key when creating the Simplex class?")
63
63
 
64
- if response.json()["succeeded"]:
64
+ if "succeeded" in response.json():
65
65
  return
66
66
  else:
67
67
  raise ValueError(f"Failed to click element: {response.json()['error']}")
@@ -81,6 +81,7 @@ class Simplex:
81
81
  self.pw = None
82
82
 
83
83
  def close_session(self):
84
+ time.sleep(30)
84
85
  if PLAYWRIGHT_AVAILABLE and self.pw_browser:
85
86
  try:
86
87
  self.pw_browser.close()
@@ -105,7 +106,7 @@ class Simplex:
105
106
  self.session_id = None
106
107
  if 'succeeded' not in response.json():
107
108
  raise ValueError(f"It looks like the close_session action failed to return a response. Did you set your api_key when creating the Simplex class?")
108
- if response.json()["succeeded"]:
109
+ if "succeeded" in response.json():
109
110
  return
110
111
  else:
111
112
  raise ValueError(f"Failed to close session: {response.json()['error']}")
@@ -158,7 +159,9 @@ class Simplex:
158
159
  self.pw = sync_playwright().start()
159
160
  self.connect_url = response_json['connect_url']
160
161
  # self.pw_browser = self.pw.chromium.connect_over_cdp(response_json['connect_url'])
161
-
162
+ if not "api.simplex.sh" in BASE_URL:
163
+ livestream_url = f"http://localhost:3000/session/{self.session_id}"
164
+
162
165
  if show_in_console:
163
166
  print(f"Livestream URL: {livestream_url}")
164
167
 
@@ -188,12 +191,14 @@ class Simplex:
188
191
  if 'succeeded' not in response.json():
189
192
  raise ValueError(f"It looks like the goto action failed to return a response. Did you set your api_key when creating the Simplex class?")
190
193
 
191
- if response.json()["succeeded"]:
194
+ if "succeeded" in response.json():
192
195
  return
193
196
  else:
194
197
  raise ValueError(f"Failed to goto url: {response.json()['error']}")
195
198
 
196
199
  def click(self, element_description: str, cdp_url: str = None):
200
+ if not element_description or not element_description.strip():
201
+ raise ValueError("element_description cannot be empty")
197
202
  if not cdp_url and not self.session_id:
198
203
  raise ValueError(f"Must call create_session before calling action click with element_description='{element_description}'")
199
204
 
@@ -213,12 +218,14 @@ class Simplex:
213
218
  )
214
219
  if 'succeeded' not in response.json():
215
220
  raise ValueError(f"It looks like the click action failed to return a response. Did you set your api_key when creating the Simplex class?")
216
- if response.json()["succeeded"]:
221
+ if "succeeded" in response.json():
217
222
  return response.json()["element_clicked"]
218
223
  else:
219
224
  raise ValueError(f"Failed to click element: {response.json()['error']}")
220
225
 
221
226
  def type(self, text: str, cdp_url: str = None):
227
+ if not text or not text.strip():
228
+ raise ValueError("text cannot be empty")
222
229
  if not cdp_url and not self.session_id:
223
230
  raise ValueError(f"Must call create_session before calling action type with text='{text}'")
224
231
 
@@ -236,11 +243,38 @@ class Simplex:
236
243
  },
237
244
  data=data
238
245
  )
239
- if response.json()["succeeded"]:
246
+ if "succeeded" in response.json():
240
247
  return
241
248
  else:
249
+ print(response.json())
242
250
  raise ValueError(f"Failed to type text: {response.json()['error']}")
251
+
243
252
 
253
+ def reload(self, cdp_url: str = None):
254
+ if not cdp_url and not self.session_id:
255
+ raise ValueError("Must call create_session before calling action reload")
256
+
257
+ data = {}
258
+
259
+ if cdp_url:
260
+ data['cdp_url'] = cdp_url
261
+ else:
262
+ data['session_id'] = self.session_id
263
+
264
+ response = requests.post(
265
+ f"{BASE_URL}/reload",
266
+ headers={
267
+ 'x-api-key': self.api_key
268
+ },
269
+ data=data
270
+ )
271
+ if 'succeeded' not in response.json():
272
+ raise ValueError(f"It looks like the reload action failed to return a response. Did you set your api_key when creating the Simplex class?")
273
+ if "succeeded" in response.json():
274
+ return
275
+ else:
276
+ raise ValueError(f"Failed to reload: {response.json()['error']}")
277
+
244
278
  def press_enter(self, cdp_url: str = None):
245
279
  if not cdp_url and not self.session_id:
246
280
  raise ValueError("Must call create_session before calling action press_enter")
@@ -261,7 +295,7 @@ class Simplex:
261
295
  )
262
296
  if 'succeeded' not in response.json():
263
297
  raise ValueError(f"It looks like the press_enter action failed to return a response. Did you set your api_key when creating the Simplex class?")
264
- if response.json()["succeeded"]:
298
+ if "succeeded" in response.json():
265
299
  return
266
300
  else:
267
301
  raise ValueError(f"Failed to press enter: {response.json()['error']}")
@@ -286,7 +320,7 @@ class Simplex:
286
320
  )
287
321
  if 'succeeded' not in response.json():
288
322
  raise ValueError(f"It looks like the press_tab action failed to return a response. Did you set your api_key when creating the Simplex class?")
289
- if response.json()["succeeded"]:
323
+ if "succeeded" in response.json():
290
324
  return
291
325
  else:
292
326
  raise ValueError(f"Failed to press tab: {response.json()['error']}")
@@ -311,12 +345,14 @@ class Simplex:
311
345
  )
312
346
  if 'succeeded' not in response.json():
313
347
  raise ValueError(f"It looks like the delete_text action failed to return a response. Did you set your api_key when creating the Simplex class?")
314
- if response.json()["succeeded"]:
348
+ if "succeeded" in response.json():
315
349
  return
316
350
  else:
317
351
  raise ValueError(f"Failed to delete text: {response.json()['error']}")
318
352
 
319
353
  def extract_bbox(self, element_description: str, cdp_url: str = None):
354
+ if not element_description or not element_description.strip():
355
+ raise ValueError("element_description cannot be empty")
320
356
  if not cdp_url and not self.session_id:
321
357
  raise ValueError(f"Must call create_session before calling action extract_bbox with element_description='{element_description}'")
322
358
 
@@ -336,12 +372,14 @@ class Simplex:
336
372
  )
337
373
  if 'succeeded' not in response.json():
338
374
  raise ValueError(f"It looks like the extract_bbox action failed to return a response. Did you set your api_key when creating the Simplex class?")
339
- if response.json()["succeeded"]:
375
+ if "succeeded" in response.json():
340
376
  return response.json()["bbox"]
341
377
  else:
342
378
  raise ValueError(f"Failed to extract bbox: {response.json()['error']}")
343
379
 
344
380
  def extract_text(self, element_description: str, cdp_url: str = None):
381
+ if not element_description or not element_description.strip():
382
+ raise ValueError("element_description cannot be empty")
345
383
  if not cdp_url and not self.session_id:
346
384
  raise ValueError(f"Must call create_session before calling action extract_text with element_description='{element_description}'")
347
385
 
@@ -362,12 +400,14 @@ class Simplex:
362
400
  response_json = response.json()
363
401
  if 'succeeded' not in response_json:
364
402
  raise ValueError(f"It looks like the extract_text action failed to return a response. Did you set your api_key when creating the Simplex class?")
365
- if response_json["succeeded"]:
403
+ if "succeeded" in response_json:
366
404
  return response_json["text"]
367
405
  else:
368
406
  raise ValueError(f"Failed to extract text: {response_json['error']}")
369
407
 
370
408
  def extract_image(self, element_description: str, cdp_url: str = None):
409
+ if not element_description or not element_description.strip():
410
+ raise ValueError("element_description cannot be empty")
371
411
  if not cdp_url and not self.session_id:
372
412
  raise ValueError(f"Must call create_session before calling action extract_image with element_description='{element_description}'")
373
413
 
@@ -387,7 +427,7 @@ class Simplex:
387
427
  )
388
428
  if 'succeeded' not in response.json():
389
429
  raise ValueError(f"It looks like the extract_image action failed to return a response. Did you set your api_key when creating the Simplex class?")
390
- if response.json()["succeeded"]:
430
+ if "succeeded" in response.json():
391
431
  return response.json()["image"]
392
432
  else:
393
433
  raise ValueError(f"Failed to extract image: {response.json()['error']}")
@@ -412,7 +452,7 @@ class Simplex:
412
452
  )
413
453
  if 'succeeded' not in response.json():
414
454
  raise ValueError(f"It looks like the scroll action failed to return a response. Did you set your api_key when creating the Simplex class?")
415
- if response.json()["succeeded"]:
455
+ if "succeeded" in response.json():
416
456
  return
417
457
  else:
418
458
  raise ValueError(f"Failed to scroll: {response.json()['error']}")
@@ -437,7 +477,7 @@ class Simplex:
437
477
  )
438
478
  if 'succeeded' not in response.json():
439
479
  raise ValueError(f"It looks like the wait action failed to return a response. Did you set your api_key when creating the Simplex class?")
440
- if response.json()["succeeded"]:
480
+ if "succeeded" in response.json():
441
481
  return
442
482
  else:
443
483
  raise ValueError(f"Failed to wait: {response.json()['error']}")
@@ -554,7 +594,7 @@ class Simplex:
554
594
  )
555
595
  if 'succeeded' not in response.json():
556
596
  raise ValueError(f"It looks like the restore_login_session action failed to return a response. Did you set your api_key when creating the Simplex class?")
557
- if response.json()["succeeded"]:
597
+ if "succeeded" in response.json():
558
598
  return
559
599
  else:
560
600
  raise ValueError(f"Failed to restore login session: {response.json()['error']}")
@@ -565,6 +605,8 @@ class Simplex:
565
605
  element_description: Description of the element to click and upload to
566
606
  file_path_or_callable: Either a path to the file to be uploaded or a callable that returns a file-like object in 'rb' mode
567
607
  """
608
+ if not element_description or not element_description.strip():
609
+ raise ValueError("element_description cannot be empty")
568
610
  if not self.session_id:
569
611
  raise ValueError(f"Must call create_session before calling action click_and_upload with element_description='{element_description}'")
570
612
 
@@ -596,12 +638,14 @@ class Simplex:
596
638
  )
597
639
  if 'succeeded' not in response.json():
598
640
  raise ValueError(f"It looks like the click_and_upload action failed to return a response. Did you set your api_key when creating the Simplex class?")
599
- if response.json()["succeeded"]:
641
+ if "succeeded" in response.json():
600
642
  return
601
643
  else:
602
644
  raise ValueError(f"Failed to click and upload: {response.json()['error']}")
603
645
 
604
646
  def click_and_download(self, element_description: str):
647
+ if not element_description or not element_description.strip():
648
+ raise ValueError("element_description cannot be empty")
605
649
  if not self.session_id:
606
650
  raise ValueError(f"Must call create_session before calling action click_and_download with element_description='{element_description}'")
607
651
 
@@ -620,12 +664,14 @@ class Simplex:
620
664
  )
621
665
  if 'succeeded' not in response.json():
622
666
  raise ValueError(f"It looks like the click_and_download action failed to return a response. Did you set your api_key when creating the Simplex class?")
623
- if response.json()["succeeded"]:
667
+ if "succeeded" in response.json():
624
668
  return response.json()["b64"], response.json()["filename"]
625
669
  else:
626
670
  raise ValueError(f"Failed to click and download: {response.json()['error']}")
627
671
 
628
672
  def exists(self, element_description: str, cdp_url: str = None):
673
+ if not element_description or not element_description.strip():
674
+ raise ValueError("element_description cannot be empty")
629
675
  if not cdp_url and not self.session_id:
630
676
  raise ValueError(f"Must call create_session before calling action exists with element_description='{element_description}'")
631
677
 
@@ -646,7 +692,7 @@ class Simplex:
646
692
  if 'succeeded' not in response.json():
647
693
  raise ValueError(f"It looks like the exists action failed to return a response. Did you set your api_key when creating the Simplex class?")
648
694
  response_json = response.json()
649
- if response_json['succeeded']:
695
+ if "succeeded" in response_json:
650
696
  return response_json['exists'], response_json['reasoning']
651
697
  else:
652
698
  raise ValueError(f"Failed to check if element exists: {response_json['error']}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: simplex
3
- Version: 1.2.57
3
+ Version: 1.2.59
4
4
  Summary: Official Python SDK for Simplex API
5
5
  Home-page: https://simplex.sh
6
6
  Author: Simplex Labs, Inc.
@@ -0,0 +1,11 @@
1
+ simplex/__init__.py,sha256=L_5i__xt_ZDkr6e-Wx9cr84t9sXpioOT7j01NJYJCTE,75
2
+ simplex/cli.py,sha256=0K_pzoVdF7vfTJPUONhFzzTvjZk2M7FZPpEONjZWJC8,2268
3
+ simplex/simplex.py,sha256=1rHcnBxP9KGXAARMg0R-sHpvWHha3oqvVUQIv4qvzIY,27649
4
+ simplex/deploy/__init__.py,sha256=_JQ81F_Nu7hSAfMA691gzs6a4-8oZ-buJ9h3Au12BKw,96
5
+ simplex/deploy/push.py,sha256=hRAbtFZaECKnBljaOLQ5nzJ6hk7tZgc1c7QdgxKQFoY,6123
6
+ simplex-1.2.59.dist-info/LICENSE,sha256=Xh0SJjYZfNI71pCNMB40aKlBLLuOB0blx5xkTtufFNQ,1075
7
+ simplex-1.2.59.dist-info/METADATA,sha256=8xkCml-KguHqLpQomJJ697nvIPpiHJIBJJYmOsIOPqw,1045
8
+ simplex-1.2.59.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
9
+ simplex-1.2.59.dist-info/entry_points.txt,sha256=3veL2w3c5vxb3dm8I_M8Fs-370n1ZnvD8uu1nSsL7z8,45
10
+ simplex-1.2.59.dist-info/top_level.txt,sha256=cbMH1bYpN0A3gP-ecibPRHasHoqB-01T_2BUFS8p0CE,8
11
+ simplex-1.2.59.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- simplex/__init__.py,sha256=L_5i__xt_ZDkr6e-Wx9cr84t9sXpioOT7j01NJYJCTE,75
2
- simplex/cli.py,sha256=0K_pzoVdF7vfTJPUONhFzzTvjZk2M7FZPpEONjZWJC8,2268
3
- simplex/simplex.py,sha256=qz9vUcp0HVIN_weBxv_sBCY1pw8LTObR3fcHcU_0gZQ,25413
4
- simplex/deploy/__init__.py,sha256=_JQ81F_Nu7hSAfMA691gzs6a4-8oZ-buJ9h3Au12BKw,96
5
- simplex/deploy/push.py,sha256=hRAbtFZaECKnBljaOLQ5nzJ6hk7tZgc1c7QdgxKQFoY,6123
6
- simplex-1.2.57.dist-info/LICENSE,sha256=Xh0SJjYZfNI71pCNMB40aKlBLLuOB0blx5xkTtufFNQ,1075
7
- simplex-1.2.57.dist-info/METADATA,sha256=actbMwYSlAmBFJC9spU_A845aGqUEd3VhUhYJWV42os,1045
8
- simplex-1.2.57.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
9
- simplex-1.2.57.dist-info/entry_points.txt,sha256=3veL2w3c5vxb3dm8I_M8Fs-370n1ZnvD8uu1nSsL7z8,45
10
- simplex-1.2.57.dist-info/top_level.txt,sha256=cbMH1bYpN0A3gP-ecibPRHasHoqB-01T_2BUFS8p0CE,8
11
- simplex-1.2.57.dist-info/RECORD,,