You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-10Lines changed: 54 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,11 @@ client = Stagehand(
41
41
model_api_key=os.environ.get("MODEL_API_KEY"), # This is the default and can be omitted
42
42
)
43
43
44
-
response = client.sessions.start()
44
+
response = client.sessions.act(
45
+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
46
+
input="Click the login button",
47
+
)
48
+
print(response.data)
45
49
```
46
50
47
51
While you can provide a `browserbase_api_key` keyword argument,
@@ -70,7 +74,11 @@ client = AsyncStagehand(
70
74
71
75
72
76
asyncdefmain() -> None:
73
-
response =await client.sessions.start()
77
+
response =await client.sessions.act(
78
+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
79
+
input="Click the login button",
80
+
)
81
+
print(response.data)
74
82
75
83
76
84
asyncio.run(main())
@@ -109,7 +117,11 @@ async def main() -> None:
109
117
model_api_key=os.environ.get("MODEL_API_KEY"), # This is the default and can be omitted
110
118
http_client=DefaultAioHttpClient(),
111
119
) as client:
112
-
response =await client.sessions.start()
120
+
response =await client.sessions.act(
121
+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
122
+
input="Click the login button",
123
+
)
124
+
print(response.data)
113
125
114
126
115
127
asyncio.run(main())
@@ -124,6 +136,23 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
124
136
125
137
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
126
138
139
+
## Nested params
140
+
141
+
Nested parameters are dictionaries, typed using `TypedDict`, for example:
142
+
143
+
```python
144
+
from stagehand import Stagehand
145
+
146
+
client = Stagehand()
147
+
148
+
response = client.sessions.act(
149
+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
150
+
input="Click the login button",
151
+
options={},
152
+
)
153
+
print(response.options)
154
+
```
155
+
127
156
## Handling errors
128
157
129
158
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `stagehand.APIConnectionError` is raised.
@@ -140,7 +169,10 @@ from stagehand import Stagehand
140
169
client = Stagehand()
141
170
142
171
try:
143
-
client.sessions.start()
172
+
client.sessions.act(
173
+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
174
+
input="Click the login button",
175
+
)
144
176
except stagehand.APIConnectionError as e:
145
177
print("The server could not be reached")
146
178
print(e.__cause__) # an underlying Exception, likely raised within httpx.
session = response.parse() # get the object that `sessions.start()` would have returned
254
-
print(session)
294
+
session = response.parse() # get the object that `sessions.act()` would have returned
295
+
print(session.data)
255
296
```
256
297
257
298
These methods return an [`APIResponse`](https://github.com/browserbase/stagehand-python/tree/stainless/src/stagehand/_response.py) object.
@@ -265,7 +306,10 @@ The above interface eagerly reads the full response body when you make the reque
265
306
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
266
307
267
308
```python
268
-
with client.sessions.with_streaming_response.start() as response:
0 commit comments