Skip to content

Commit 37041b2

Browse files
Add sync and async computer-action examples
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent bccb68b commit 37041b2

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ Ready-to-run examples are available in `examples/`:
260260
- `examples/async_batch_fetch.py`
261261
- `examples/async_browser_use_task.py`
262262
- `examples/async_claude_computer_use_task.py`
263+
- `examples/async_computer_action.py`
263264
- `examples/async_crawl.py`
264265
- `examples/async_cua_task.py`
265266
- `examples/async_extension_create.py`
@@ -277,6 +278,7 @@ Ready-to-run examples are available in `examples/`:
277278
- `examples/sync_batch_fetch.py`
278279
- `examples/sync_browser_use_task.py`
279280
- `examples/sync_claude_computer_use_task.py`
281+
- `examples/sync_computer_action.py`
280282
- `examples/sync_crawl.py`
281283
- `examples/sync_cua_task.py`
282284
- `examples/sync_extension_create.py`

examples/async_computer_action.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Asynchronous computer action example.
3+
4+
Run:
5+
export HYPERBROWSER_API_KEY="your_api_key"
6+
export HYPERBROWSER_SESSION_ID="session_id"
7+
python3 examples/async_computer_action.py
8+
"""
9+
10+
import asyncio
11+
import os
12+
13+
from hyperbrowser import AsyncHyperbrowser
14+
from hyperbrowser.exceptions import HyperbrowserError
15+
16+
17+
async def main() -> None:
18+
session_id = os.getenv("HYPERBROWSER_SESSION_ID")
19+
if session_id is None:
20+
raise HyperbrowserError("Set HYPERBROWSER_SESSION_ID before running")
21+
22+
async with AsyncHyperbrowser() as client:
23+
response = await client.computer_action.screenshot(session_id)
24+
print(f"Action successful: {response.success}")
25+
26+
27+
if __name__ == "__main__":
28+
asyncio.run(main())

examples/sync_computer_action.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Synchronous computer action example.
3+
4+
Run:
5+
export HYPERBROWSER_API_KEY="your_api_key"
6+
export HYPERBROWSER_SESSION_ID="session_id"
7+
python3 examples/sync_computer_action.py
8+
"""
9+
10+
import os
11+
12+
from hyperbrowser import Hyperbrowser
13+
from hyperbrowser.exceptions import HyperbrowserError
14+
15+
16+
def main() -> None:
17+
session_id = os.getenv("HYPERBROWSER_SESSION_ID")
18+
if session_id is None:
19+
raise HyperbrowserError("Set HYPERBROWSER_SESSION_ID before running")
20+
21+
with Hyperbrowser() as client:
22+
response = client.computer_action.screenshot(session_id)
23+
print(f"Action successful: {response.success}")
24+
25+
26+
if __name__ == "__main__":
27+
main()

0 commit comments

Comments
 (0)