simplex 1.0.0__py3-none-any.whl → 1.0.8__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/__init__.py +34 -3
- simplex/client.py +355 -0
- simplex/errors.py +160 -0
- simplex/http_client.py +403 -0
- simplex/resources/__init__.py +10 -0
- simplex/resources/workflow.py +502 -0
- simplex/resources/workflow_session.py +333 -0
- simplex/types.py +276 -0
- simplex-1.0.8.dist-info/METADATA +408 -0
- simplex-1.0.8.dist-info/RECORD +13 -0
- {simplex-1.0.0.dist-info → simplex-1.0.8.dist-info}/WHEEL +1 -1
- {simplex-1.0.0.dist-info → simplex-1.0.8.dist-info/licenses}/LICENSE +2 -2
- simplex/constants.py +0 -1
- simplex/simplex.py +0 -187
- simplex/utils.py +0 -12
- simplex-1.0.0.dist-info/METADATA +0 -29
- simplex-1.0.0.dist-info/RECORD +0 -10
- simplex-1.0.0.dist-info/entry_points.txt +0 -2
- {simplex-1.0.0.dist-info → simplex-1.0.8.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simplex
|
|
3
|
+
Version: 1.0.8
|
|
4
|
+
Summary: Official Python SDK for the Simplex API
|
|
5
|
+
Home-page: https://github.com/yourusername/simplex-python-sdk
|
|
6
|
+
Author: Simplex
|
|
7
|
+
Author-email: Simplex <support@simplex.sh>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/yourusername/simplex-python-sdk
|
|
10
|
+
Project-URL: Documentation, https://docs.simplex.sh
|
|
11
|
+
Project-URL: Repository, https://github.com/yourusername/simplex-python-sdk
|
|
12
|
+
Project-URL: Bug Tracker, https://github.com/yourusername/simplex-python-sdk/issues
|
|
13
|
+
Keywords: simplex,api,sdk,workflow,automation,browser
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Operating System :: OS Independent
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: requests>=2.25.0
|
|
29
|
+
Requires-Dist: urllib3>=1.26.0
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: flake8>=4.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: mypy>=0.950; extra == "dev"
|
|
36
|
+
Requires-Dist: python-dotenv>=0.19.0; extra == "dev"
|
|
37
|
+
Dynamic: author
|
|
38
|
+
Dynamic: home-page
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
Dynamic: requires-python
|
|
41
|
+
|
|
42
|
+
# Simplex Python SDK
|
|
43
|
+
|
|
44
|
+
Official Python SDK for the [Simplex API](https://simplex.sh) - A powerful workflow automation platform for browser-based tasks.
|
|
45
|
+
|
|
46
|
+
[](https://www.python.org/downloads/)
|
|
47
|
+
[](https://opensource.org/licenses/MIT)
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- 🚀 Simple and intuitive API
|
|
52
|
+
- 🔄 Automatic retry logic with exponential backoff
|
|
53
|
+
- 🎯 Type hints for better IDE support
|
|
54
|
+
- 🔐 Built-in error handling
|
|
55
|
+
- 📦 Context manager support for automatic cleanup
|
|
56
|
+
- 🤖 Support for agentic workflows and named agents
|
|
57
|
+
- 📁 File download capabilities
|
|
58
|
+
- 🔑 2FA configuration management
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
Install the Simplex SDK using pip:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install simplex
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Quick Start
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from simplex import SimplexClient
|
|
72
|
+
|
|
73
|
+
# Initialize the client
|
|
74
|
+
client = SimplexClient(api_key='your-api-key')
|
|
75
|
+
|
|
76
|
+
# Run a workflow with variables
|
|
77
|
+
result = client.workflows.run(
|
|
78
|
+
'workflow-id',
|
|
79
|
+
variables={'username': 'user@example.com'}
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
print(f"Workflow started: {result['session_id']}")
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Usage Examples
|
|
86
|
+
|
|
87
|
+
### Creating a Workflow Session
|
|
88
|
+
|
|
89
|
+
Use workflow sessions for more control over browser automation:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from simplex import SimplexClient
|
|
93
|
+
|
|
94
|
+
client = SimplexClient(api_key='your-api-key')
|
|
95
|
+
|
|
96
|
+
# Using context manager for automatic cleanup
|
|
97
|
+
with client.create_workflow_session(
|
|
98
|
+
name='my-workflow',
|
|
99
|
+
url='https://example.com'
|
|
100
|
+
) as session:
|
|
101
|
+
print(f'Session ID: {session.session_id}')
|
|
102
|
+
print(f'Livestream URL: {session.livestream_url}')
|
|
103
|
+
|
|
104
|
+
# Navigate to a page
|
|
105
|
+
session.goto('https://example.com/login')
|
|
106
|
+
|
|
107
|
+
# Run a named agent
|
|
108
|
+
session.run_agent('Login Agent', variables={
|
|
109
|
+
'username': 'user@example.com',
|
|
110
|
+
'password': 'secret'
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
# Execute an agentic task
|
|
114
|
+
session.agentic('Click the submit button and wait for confirmation')
|
|
115
|
+
|
|
116
|
+
# Session automatically closes when exiting the with block
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Running a Workflow
|
|
120
|
+
|
|
121
|
+
Execute pre-built workflows with variables:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from simplex import SimplexClient, WorkflowError
|
|
125
|
+
|
|
126
|
+
client = SimplexClient(api_key='your-api-key')
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
# Run workflow with variables
|
|
130
|
+
result = client.workflows.run(
|
|
131
|
+
'workflow-id',
|
|
132
|
+
variables={
|
|
133
|
+
'email': 'user@example.com',
|
|
134
|
+
'product_id': '12345'
|
|
135
|
+
},
|
|
136
|
+
metadata='Order processing workflow'
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
print(f"Success: {result['succeeded']}")
|
|
140
|
+
print(f"Session ID: {result['session_id']}")
|
|
141
|
+
|
|
142
|
+
# Check workflow status
|
|
143
|
+
status = client.workflows.get_status(result['session_id'])
|
|
144
|
+
print(f"Completed: {status['completed']}")
|
|
145
|
+
print(f"Total actions: {status['total_actions']}")
|
|
146
|
+
|
|
147
|
+
except WorkflowError as e:
|
|
148
|
+
print(f"Workflow failed: {e.message}")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Using Agentic Tasks
|
|
152
|
+
|
|
153
|
+
Execute natural language instructions:
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
# Within a workflow session
|
|
157
|
+
session.agentic(
|
|
158
|
+
'Navigate to the invoices page and download the latest invoice',
|
|
159
|
+
max_steps=10
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
# Or using the workflows resource
|
|
163
|
+
client.workflows.agentic(
|
|
164
|
+
task='Find and click the login button',
|
|
165
|
+
session_id='session-id',
|
|
166
|
+
max_steps=5
|
|
167
|
+
)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Downloading Session Files
|
|
171
|
+
|
|
172
|
+
Download files created during workflow execution:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from simplex import SimplexClient
|
|
176
|
+
|
|
177
|
+
client = SimplexClient(api_key='your-api-key')
|
|
178
|
+
|
|
179
|
+
# Download all files as a zip
|
|
180
|
+
zip_data = client.download_session_files('session-id')
|
|
181
|
+
with open('session_files.zip', 'wb') as f:
|
|
182
|
+
f.write(zip_data)
|
|
183
|
+
|
|
184
|
+
# Download a specific file
|
|
185
|
+
file_data = client.download_session_files('session-id', filename='report.pdf')
|
|
186
|
+
with open('report.pdf', 'wb') as f:
|
|
187
|
+
f.write(file_data)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Adding 2FA Configuration
|
|
191
|
+
|
|
192
|
+
Configure automatic 2FA handling:
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
from simplex import SimplexClient
|
|
196
|
+
|
|
197
|
+
client = SimplexClient(api_key='your-api-key')
|
|
198
|
+
|
|
199
|
+
result = client.add_2fa_config(
|
|
200
|
+
seed='JBSWY3DPEHPK3PXP',
|
|
201
|
+
name='My Service',
|
|
202
|
+
partial_url='example.com'
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
print(f"Total configs: {result['total_configs']}")
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Error Handling
|
|
209
|
+
|
|
210
|
+
The SDK provides specific exception types for different error scenarios:
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
from simplex import (
|
|
214
|
+
SimplexClient,
|
|
215
|
+
SimplexError,
|
|
216
|
+
WorkflowError,
|
|
217
|
+
AuthenticationError,
|
|
218
|
+
RateLimitError,
|
|
219
|
+
NetworkError
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
client = SimplexClient(api_key='your-api-key')
|
|
223
|
+
|
|
224
|
+
try:
|
|
225
|
+
result = client.workflows.run('workflow-id')
|
|
226
|
+
except AuthenticationError as e:
|
|
227
|
+
print(f"Authentication failed: {e.message}")
|
|
228
|
+
except RateLimitError as e:
|
|
229
|
+
print(f"Rate limit exceeded. Retry after {e.retry_after} seconds")
|
|
230
|
+
except WorkflowError as e:
|
|
231
|
+
print(f"Workflow error: {e.message}")
|
|
232
|
+
print(f"Workflow ID: {e.workflow_id}")
|
|
233
|
+
print(f"Session ID: {e.session_id}")
|
|
234
|
+
except NetworkError as e:
|
|
235
|
+
print(f"Network error: {e.message}")
|
|
236
|
+
except SimplexError as e:
|
|
237
|
+
print(f"General error: {e.message}")
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Configuration
|
|
241
|
+
|
|
242
|
+
### Environment Variables
|
|
243
|
+
|
|
244
|
+
You can use environment variables for configuration:
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
import os
|
|
248
|
+
from simplex import SimplexClient
|
|
249
|
+
|
|
250
|
+
api_key = os.getenv('SIMPLEX_API_KEY')
|
|
251
|
+
client = SimplexClient(api_key=api_key)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Example `.env` file:
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
SIMPLEX_API_KEY=your-api-key
|
|
258
|
+
WORKFLOW_ID=your-workflow-id
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Client Options
|
|
262
|
+
|
|
263
|
+
Customize client behavior with initialization parameters:
|
|
264
|
+
|
|
265
|
+
```python
|
|
266
|
+
from simplex import SimplexClient
|
|
267
|
+
|
|
268
|
+
client = SimplexClient(
|
|
269
|
+
api_key='your-api-key',
|
|
270
|
+
timeout=60, # Request timeout in seconds
|
|
271
|
+
max_retries=5, # Maximum retry attempts
|
|
272
|
+
retry_delay=2, # Delay between retries in seconds
|
|
273
|
+
base_url='https://api.simplex.sh' # API base URL
|
|
274
|
+
)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## API Reference
|
|
278
|
+
|
|
279
|
+
### SimplexClient
|
|
280
|
+
|
|
281
|
+
Main client class for interacting with the Simplex API.
|
|
282
|
+
|
|
283
|
+
**Methods:**
|
|
284
|
+
- `create_workflow_session(name, url, proxies=False, session_data=None)` - Create a new workflow session
|
|
285
|
+
- `get_session_store(session_id)` - Retrieve session store data
|
|
286
|
+
- `download_session_files(session_id, filename=None)` - Download files from a session
|
|
287
|
+
- `add_2fa_config(seed, name=None, partial_url=None)` - Add 2FA configuration
|
|
288
|
+
- `update_api_key(api_key)` - Update the API key
|
|
289
|
+
- `set_custom_header(key, value)` - Set a custom header
|
|
290
|
+
- `remove_custom_header(key)` - Remove a custom header
|
|
291
|
+
|
|
292
|
+
### Workflow Resource
|
|
293
|
+
|
|
294
|
+
Access via `client.workflows`
|
|
295
|
+
|
|
296
|
+
**Methods:**
|
|
297
|
+
- `run(workflow_id, variables=None, metadata=None, webhook_url=None)` - Execute a workflow
|
|
298
|
+
- `get_status(session_id)` - Get workflow execution status
|
|
299
|
+
- `create_workflow_session(workflow_name, url, proxies=False, session_data=None)` - Create a session
|
|
300
|
+
- `agentic(task, session_id, max_steps=None, actions_to_exclude=None, variables=None)` - Run agentic task
|
|
301
|
+
- `run_agent(agent_name, session_id, variables=None)` - Run a named agent
|
|
302
|
+
- `start_segment(workflow_id, segment_name)` - Start a workflow segment
|
|
303
|
+
- `finish_segment(workflow_id)` - Finish the current segment
|
|
304
|
+
- `start_capture(session_id)` - Start capture mode
|
|
305
|
+
- `stop_capture(session_id)` - Stop capture mode
|
|
306
|
+
- `close_workflow_session(session_id)` - Close a session
|
|
307
|
+
|
|
308
|
+
### WorkflowSession
|
|
309
|
+
|
|
310
|
+
Created via `client.create_workflow_session()`. Supports context manager protocol.
|
|
311
|
+
|
|
312
|
+
**Properties:**
|
|
313
|
+
- `session_id` - Unique session identifier
|
|
314
|
+
- `workflow_id` - Associated workflow ID
|
|
315
|
+
- `livestream_url` - URL to view live browser session
|
|
316
|
+
- `connect_url` - Connection URL
|
|
317
|
+
- `vnc_url` - VNC access URL
|
|
318
|
+
- `is_closed` - Whether the session is closed
|
|
319
|
+
|
|
320
|
+
**Methods:**
|
|
321
|
+
- `goto(url)` - Navigate to a URL
|
|
322
|
+
- `agentic(task, max_steps=None, actions_to_exclude=None, variables=None)` - Execute agentic task
|
|
323
|
+
- `run_agent(agent_name, variables=None)` - Run a named agent
|
|
324
|
+
- `start_capture()` - Start capture mode
|
|
325
|
+
- `stop_capture()` - Stop capture mode
|
|
326
|
+
- `close()` - Close the session
|
|
327
|
+
|
|
328
|
+
## Development
|
|
329
|
+
|
|
330
|
+
### Setup Development Environment
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
# Create a virtual environment
|
|
334
|
+
python -m venv venv
|
|
335
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
336
|
+
|
|
337
|
+
# Install the package
|
|
338
|
+
pip install simplex
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Running Tests
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
pytest tests/
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### Code Formatting
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
black simplex/
|
|
351
|
+
flake8 simplex/
|
|
352
|
+
mypy simplex/
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## Examples
|
|
356
|
+
|
|
357
|
+
Check out the [examples](./examples) directory for more usage examples:
|
|
358
|
+
|
|
359
|
+
- `login_example.py` - Basic login workflow
|
|
360
|
+
- `create_workflow.py` - Creating and controlling sessions
|
|
361
|
+
- `run_workflow.py` - Running workflows with variables
|
|
362
|
+
- `download_file.py` - Downloading session files
|
|
363
|
+
- `add_2fa_config.py` - Adding 2FA configuration
|
|
364
|
+
|
|
365
|
+
## Requirements
|
|
366
|
+
|
|
367
|
+
- Python 3.8 or higher
|
|
368
|
+
- `requests>=2.25.0`
|
|
369
|
+
- `urllib3>=1.26.0`
|
|
370
|
+
|
|
371
|
+
## Contributing
|
|
372
|
+
|
|
373
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
374
|
+
|
|
375
|
+
1. Fork the repository
|
|
376
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
377
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
378
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
379
|
+
5. Open a Pull Request
|
|
380
|
+
|
|
381
|
+
## License
|
|
382
|
+
|
|
383
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
384
|
+
|
|
385
|
+
## Support
|
|
386
|
+
|
|
387
|
+
- Documentation: [https://docs.simplex.sh](https://docs.simplex.sh)
|
|
388
|
+
- Email: support@simplex.sh
|
|
389
|
+
- GitHub Issues: [https://github.com/yourusername/simplex-python-sdk/issues](https://github.com/yourusername/simplex-python-sdk/issues)
|
|
390
|
+
|
|
391
|
+
## Changelog
|
|
392
|
+
|
|
393
|
+
### Version 1.0.0 (2024)
|
|
394
|
+
|
|
395
|
+
- Initial release
|
|
396
|
+
- Full feature parity with TypeScript SDK
|
|
397
|
+
- Support for workflow execution and session management
|
|
398
|
+
- Agentic task execution
|
|
399
|
+
- Named agent support
|
|
400
|
+
- File download capabilities
|
|
401
|
+
- 2FA configuration management
|
|
402
|
+
- Comprehensive error handling
|
|
403
|
+
- Type hints throughout
|
|
404
|
+
- Context manager support
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
Made with ❤️ by [Simplex](https://simplex.sh)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
simplex/__init__.py,sha256=brGWID41NoRNE_bquA7G_Neij4zbY826ZdNmOgrnnPY,802
|
|
2
|
+
simplex/client.py,sha256=SqxjcAZ1dpXUmj-DawGxRdx61Wxrhd-tT1pd84iuEcM,11956
|
|
3
|
+
simplex/errors.py,sha256=_IHJhhvFWWPFywjzXNxbVr2S8WOqThkhc2KzCZiN6i8,4653
|
|
4
|
+
simplex/http_client.py,sha256=-khQqgIenG71oTV73chsbu-uY16NQCgbidiiTVLdIRk,12440
|
|
5
|
+
simplex/types.py,sha256=8pPLJyQPDLuLFuCPRlYJajuJLZbvitE6v27zPkmV6IU,7546
|
|
6
|
+
simplex/resources/__init__.py,sha256=yx_Ubd2LBrXbTwFrhhPgpu3jIy4JqUtb7BJvLnbkGwg,277
|
|
7
|
+
simplex/resources/workflow.py,sha256=FP1c9uTXTgzaggZ485QIhktPKZQW9sOg6d2nbNrywPw,16250
|
|
8
|
+
simplex/resources/workflow_session.py,sha256=3zjwQ55SI1sEP_VncE7w0_jyPrxthMYPJm5O3Uya8p8,10981
|
|
9
|
+
simplex-1.0.8.dist-info/licenses/LICENSE,sha256=TyxVTRp5rBigFCL8EDC9Bv7AZfb4JBMVUZUeCs4Pk6Y,1063
|
|
10
|
+
simplex-1.0.8.dist-info/METADATA,sha256=aB5s0VycncILa2q4shPlJl0FKm-APkjPrQPYjK3NMYY,11161
|
|
11
|
+
simplex-1.0.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
simplex-1.0.8.dist-info/top_level.txt,sha256=cbMH1bYpN0A3gP-ecibPRHasHoqB-01T_2BUFS8p0CE,8
|
|
13
|
+
simplex-1.0.8.dist-info/RECORD,,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2024 Simplex
|
|
3
|
+
Copyright (c) 2024 Simplex
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
simplex/constants.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
BASE_URL = "https://u3mvtbirxf.us-east-1.awsapprunner.com"
|
simplex/simplex.py
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
from playwright.sync_api import Page, sync_playwright
|
|
2
|
-
from PIL import Image
|
|
3
|
-
import requests
|
|
4
|
-
from typing import List
|
|
5
|
-
import io
|
|
6
|
-
|
|
7
|
-
from .utils import center_bbox, screenshot_to_image
|
|
8
|
-
|
|
9
|
-
BASE_URL = "https://u3mvtbirxf.us-east-1.awsapprunner.com"
|
|
10
|
-
|
|
11
|
-
class Simplex:
|
|
12
|
-
def __init__(self, api_key: str, driver: Page = None):
|
|
13
|
-
"""
|
|
14
|
-
Initialize Simplex instance
|
|
15
|
-
|
|
16
|
-
Args:
|
|
17
|
-
api_key (str): API key for authentication
|
|
18
|
-
driver (playwright.sync_api.Page, optional): Playwright page object. If not provided,
|
|
19
|
-
a new headless browser instance will be created.
|
|
20
|
-
"""
|
|
21
|
-
self.api_key = api_key
|
|
22
|
-
|
|
23
|
-
if driver is None:
|
|
24
|
-
self.playwright = sync_playwright().start()
|
|
25
|
-
self.browser = self.playwright.chromium.launch(headless=True)
|
|
26
|
-
self.driver = self.browser.new_page()
|
|
27
|
-
else:
|
|
28
|
-
self.driver = driver
|
|
29
|
-
self.browser = None
|
|
30
|
-
self.playwright = None
|
|
31
|
-
|
|
32
|
-
def __del__(self):
|
|
33
|
-
"""Cleanup Playwright resources"""
|
|
34
|
-
if self.browser:
|
|
35
|
-
self.browser.close()
|
|
36
|
-
if self.playwright:
|
|
37
|
-
self.playwright.stop()
|
|
38
|
-
|
|
39
|
-
def find_element(self, element_description: str, state: Image.Image | None = None) -> List[int]:
|
|
40
|
-
"""
|
|
41
|
-
Find an element in the screenshot using the element description
|
|
42
|
-
|
|
43
|
-
Args:
|
|
44
|
-
element_description (str): Description of the element to find
|
|
45
|
-
screenshot (PIL.Image.Image): Screenshot of the page
|
|
46
|
-
|
|
47
|
-
Returns:
|
|
48
|
-
bounding_box (tuple): [x1, y1, x2, y2] bounding box of the found element
|
|
49
|
-
"""
|
|
50
|
-
if state is None:
|
|
51
|
-
state = self.take_stable_screenshot()
|
|
52
|
-
|
|
53
|
-
endpoint = f"{BASE_URL}/find-element"
|
|
54
|
-
|
|
55
|
-
# Convert PIL Image to bytes
|
|
56
|
-
img_byte_arr = io.BytesIO()
|
|
57
|
-
state.save(img_byte_arr, format='PNG')
|
|
58
|
-
img_byte_arr = img_byte_arr.getvalue()
|
|
59
|
-
|
|
60
|
-
# Prepare multipart form data
|
|
61
|
-
files = {
|
|
62
|
-
'image_data': ('screenshot.png', img_byte_arr, 'image/png'),
|
|
63
|
-
'element_description': (None, element_description),
|
|
64
|
-
'api_key': (None, self.api_key)
|
|
65
|
-
}
|
|
66
|
-
# Make the request
|
|
67
|
-
response = requests.post(
|
|
68
|
-
endpoint,
|
|
69
|
-
files=files
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
# Print the results
|
|
73
|
-
print(f"Status Code: {response.status_code}")
|
|
74
|
-
if response.status_code == 200:
|
|
75
|
-
res = response.json()
|
|
76
|
-
bbox = [int(res['x1']), int(res['y1']), int(res['x2']), int(res['y2'])]
|
|
77
|
-
return bbox
|
|
78
|
-
else:
|
|
79
|
-
print("Error:", response.text)
|
|
80
|
-
|
|
81
|
-
def step_to_action(self, step_description: str, state: Image.Image | None = None) -> List[List[str]]:
|
|
82
|
-
"""
|
|
83
|
-
Convert a step description to an action
|
|
84
|
-
|
|
85
|
-
Args:
|
|
86
|
-
step_description (str): Description of the step to convert to action
|
|
87
|
-
screenshot (PIL.Image.Image): Screenshot of the page
|
|
88
|
-
|
|
89
|
-
Returns:
|
|
90
|
-
action (List[List[str, str]]): List of actions to perform
|
|
91
|
-
"""
|
|
92
|
-
if state is None:
|
|
93
|
-
state = self.take_stable_screenshot()
|
|
94
|
-
|
|
95
|
-
endpoint = f"{BASE_URL}/step_to_action"
|
|
96
|
-
|
|
97
|
-
# Convert PIL Image to bytes
|
|
98
|
-
img_byte_arr = io.BytesIO()
|
|
99
|
-
state.save(img_byte_arr, format='PNG')
|
|
100
|
-
img_byte_arr = img_byte_arr.getvalue()
|
|
101
|
-
|
|
102
|
-
# Prepare form data
|
|
103
|
-
files = {
|
|
104
|
-
'image_data': ('screenshot.png', img_byte_arr, 'image/png'),
|
|
105
|
-
'step': (None, step_description),
|
|
106
|
-
'api_key': (None, self.api_key)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
# Make the request
|
|
110
|
-
response = requests.post(
|
|
111
|
-
endpoint,
|
|
112
|
-
files=files
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
# Handle response
|
|
116
|
-
if response.status_code == 200:
|
|
117
|
-
res = response.json()
|
|
118
|
-
actions = res.split('\n')
|
|
119
|
-
actions = [action.split(',') for action in actions]
|
|
120
|
-
actions = [[action.strip() for action in action_pair] for action_pair in actions]
|
|
121
|
-
return actions
|
|
122
|
-
else:
|
|
123
|
-
print(f"Error: {response.status_code}")
|
|
124
|
-
print(response.text)
|
|
125
|
-
return []
|
|
126
|
-
|
|
127
|
-
def goto(self, url: str) -> None:
|
|
128
|
-
"""
|
|
129
|
-
Navigate to a URL
|
|
130
|
-
"""
|
|
131
|
-
self.driver.goto(url)
|
|
132
|
-
|
|
133
|
-
def execute_action(self, action: List[List[str]], state: Image.Image | None = None) -> None:
|
|
134
|
-
"""
|
|
135
|
-
Execute an action with playwright driver
|
|
136
|
-
|
|
137
|
-
Args:
|
|
138
|
-
action (List[List[str]]): List of actions to perform
|
|
139
|
-
"""
|
|
140
|
-
action_type, description = action
|
|
141
|
-
if state is None:
|
|
142
|
-
state = self.take_stable_screenshot()
|
|
143
|
-
|
|
144
|
-
try:
|
|
145
|
-
if action_type == "CLICK":
|
|
146
|
-
bbox = self.find_element(description, state)
|
|
147
|
-
center_x, center_y = center_bbox(bbox)
|
|
148
|
-
self.driver.mouse.click(center_x, center_y)
|
|
149
|
-
|
|
150
|
-
elif action_type == "HOVER":
|
|
151
|
-
bbox = self.find_element(description, state)
|
|
152
|
-
center_x, center_y = center_bbox(bbox)
|
|
153
|
-
self.driver.mouse.move(center_x, center_y)
|
|
154
|
-
|
|
155
|
-
elif action_type == "TYPE":
|
|
156
|
-
self.driver.keyboard.type(description)
|
|
157
|
-
|
|
158
|
-
elif action_type == "SCROLL":
|
|
159
|
-
self.driver.mouse.wheel(0, int(description))
|
|
160
|
-
|
|
161
|
-
elif action_type == "WAIT":
|
|
162
|
-
self.driver.wait_for_timeout(int(description))
|
|
163
|
-
|
|
164
|
-
except Exception as e:
|
|
165
|
-
print(f"Error executing action: {e}")
|
|
166
|
-
return None
|
|
167
|
-
|
|
168
|
-
def do(self, step_description: str) -> None:
|
|
169
|
-
"""
|
|
170
|
-
Execute a step description
|
|
171
|
-
"""
|
|
172
|
-
state = self.take_stable_screenshot()
|
|
173
|
-
actions = self.step_to_action(step_description, state)
|
|
174
|
-
for action in actions:
|
|
175
|
-
self.execute_action(action)
|
|
176
|
-
|
|
177
|
-
def take_stable_screenshot(self) -> Image.Image:
|
|
178
|
-
"""
|
|
179
|
-
Take a screenshot after ensuring the page is in a stable state.
|
|
180
|
-
|
|
181
|
-
Returns:
|
|
182
|
-
PIL.Image.Image: Screenshot of the current page
|
|
183
|
-
"""
|
|
184
|
-
self.driver.wait_for_load_state('networkidle')
|
|
185
|
-
return screenshot_to_image(self.driver.screenshot())
|
|
186
|
-
|
|
187
|
-
|
simplex/utils.py
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
from typing import List
|
|
2
|
-
from PIL import Image
|
|
3
|
-
import io
|
|
4
|
-
def center_bbox(bbox: List[int]) -> List[int]:
|
|
5
|
-
"""
|
|
6
|
-
Calculate the center coordinates of a bounding box
|
|
7
|
-
"""
|
|
8
|
-
return [(bbox[0] + bbox[2]) // 2, (bbox[1] + bbox[3]) // 2]
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def screenshot_to_image(screenshot: bytes) -> Image:
|
|
12
|
-
return Image.open(io.BytesIO(screenshot))
|
simplex-1.0.0.dist-info/METADATA
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: simplex
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: Official Python SDK for Simplex API
|
|
5
|
-
Home-page: https://github.com/shreyka/simplex-python
|
|
6
|
-
Author: Simplex Labs, Inc.
|
|
7
|
-
Author-email: founders@simplex.sh
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Requires-Python: >=3.6
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
License-File: LICENSE
|
|
16
|
-
Requires-Dist: openai>=1.0.0
|
|
17
|
-
Requires-Dist: python-dotenv>=0.19.0
|
|
18
|
-
Requires-Dist: tiktoken>=0.5.0
|
|
19
|
-
Requires-Dist: click>=8.0.0
|
|
20
|
-
Requires-Dist: rich>=13.0.0
|
|
21
|
-
Requires-Dist: prompt_toolkit>=3.0.0
|
|
22
|
-
Requires-Dist: playwright>=1.0.0
|
|
23
|
-
Requires-Dist: Pillow>=9.0.0
|
|
24
|
-
|
|
25
|
-
# Simplex AI Python SDK
|
|
26
|
-
|
|
27
|
-
A Python SDK for Simplex AI that enables browser automation using natural language commands.
|
|
28
|
-
|
|
29
|
-
## Installation
|
simplex-1.0.0.dist-info/RECORD
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
simplex/__init__.py,sha256=1mbM4XUk0FNW161WOkM4ayC1s_QSsaBEls6PZ0iBScY,74
|
|
2
|
-
simplex/constants.py,sha256=nIXF2oVNNNknXweXAlmE-KBM9QjJtYw9osXVYjvloN0,59
|
|
3
|
-
simplex/simplex.py,sha256=p3dGJFdyQReW2qHX-yFn9Vi6Bm8-QJ_x6RK66s1KkM8,6246
|
|
4
|
-
simplex/utils.py,sha256=UrD4Ena3yk0POmxxyiqMszzPbTscTCJpMP4xZFDAuOc,339
|
|
5
|
-
simplex-1.0.0.dist-info/LICENSE,sha256=Xh0SJjYZfNI71pCNMB40aKlBLLuOB0blx5xkTtufFNQ,1075
|
|
6
|
-
simplex-1.0.0.dist-info/METADATA,sha256=4BL_hKn_yaVMoCpGSsUxTdVwwb2trncuwu7QyEFyE_M,917
|
|
7
|
-
simplex-1.0.0.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
|
|
8
|
-
simplex-1.0.0.dist-info/entry_points.txt,sha256=3veL2w3c5vxb3dm8I_M8Fs-370n1ZnvD8uu1nSsL7z8,45
|
|
9
|
-
simplex-1.0.0.dist-info/top_level.txt,sha256=cbMH1bYpN0A3gP-ecibPRHasHoqB-01T_2BUFS8p0CE,8
|
|
10
|
-
simplex-1.0.0.dist-info/RECORD,,
|
|
File without changes
|