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
<strong>NOTE:</strong> This is a Python SDK for Stagehand. The original implementation is in TypeScript and is available <ahref="https://github.com/browserbase/stagehand"style="color: blue;">here</a>.
39
+
This is a Python SDK for Stagehand. We also have a TypeScript SDK available <ahref="https://github.com/browserbase/stagehand"style="color: blue;">here</a>.
40
40
</div>
41
41
42
-
---
42
+
> Stagehand Python SDK is currently available as an early release, and we're actively seeking feedback from the community. Please join our [Slack community](https://stagehand.dev/slack) to stay updated on the latest developments and provide feedback.
43
43
44
-
Stagehand is the easiest way to build browser automations with AI-powered interactions.
44
+
## Why Stagehand?
45
+
46
+
*Stagehand is the easiest way to build browser automations with AI-powered interactions.*
47
+
48
+
Most existing browser automation tools either require you to write low-level code in a framework like Selenium, Playwright, or Puppeteer, or use high-level agents that can be unpredictable in production. By letting developers choose what to write in code vs. natural language, Stagehand is the natural choice for browser automations in production.
49
+
50
+
1.**Choose when to write code vs. natural language**: use AI when you want to navigate unfamiliar pages, and use code ([Playwright](https://playwright.dev/)) when you know exactly what you want to do.
51
+
52
+
2.**Preview and cache actions**: Stagehand lets you preview AI actions before running them, and also helps you easily cache repeatable actions to save time and tokens.
53
+
54
+
3.**Computer use models with one line of code**: Stagehand lets you integrate SOTA computer use models from OpenAI and Anthropic into the browser with one line of code.
55
+
56
+
-----
57
+
58
+
### TL;DR Automate the web *reliably* with natural language:
45
59
46
60
-**act** — Instruct the AI to perform actions (e.g. click a button or scroll).
47
61
```python
@@ -60,6 +74,12 @@ await stagehand.page.observe("find the search bar")
60
74
await stagehand.agent.execute("book a reservation for 2 people for a trip to the Maldives")
61
75
```
62
76
77
+
78
+
## Installation:
79
+
80
+
`pip install stagehand`
81
+
82
+
63
83
## Quickstart
64
84
65
85
```python
@@ -145,174 +165,9 @@ if __name__ == "__main__":
145
165
asyncio.run(main())
146
166
```
147
167
148
-
## Installation
149
-
150
-
### Creating a Virtual Environment (Recommended)
151
-
152
-
First, create and activate a virtual environment to keep your project dependencies isolated:
153
-
154
-
```bash
155
-
# Create a virtual environment
156
-
python -m venv stagehand-env
157
-
158
-
# Activate the environment
159
-
# On macOS/Linux:
160
-
source stagehand-env/bin/activate
161
-
# On Windows:
162
-
stagehand-env\Scripts\activate
163
-
```
164
-
165
-
### Install Stagehand
166
-
167
-
**Normal Installation:**
168
-
```bash
169
-
pip install stagehand
170
-
```
168
+
## Documentation
171
169
172
-
**Local Development Installation:**
173
-
If you're contributing to Stagehand or want to modify the source code:
The `ActOptions` model takes an `action` field that tells the AI what to do on the page, plus optional fields such as `useVision` and `variables`:
280
-
```python
281
-
from stagehand.schemas import ActOptions
282
-
283
-
# Example:
284
-
await page.act(ActOptions(action="click on the 'Quickstart' button"))
285
-
```
286
-
287
-
-**ObserveOptions**
288
-
289
-
The `ObserveOptions` model lets you find elements on the page using natural language. The `onlyVisible` option helps limit the results:
290
-
```python
291
-
from stagehand.schemas import ObserveOptions
292
-
293
-
# Example:
294
-
await page.observe(ObserveOptions(instruction="find the button labeled 'News'", onlyVisible=True))
295
-
```
296
-
297
-
-**ExtractOptions**
298
-
299
-
The `ExtractOptions` model extracts structured data from the page. Pass your instructions and a schema defining your expected data format. **Note:** If you are using a Pydantic model for the schema, call its `.model_json_schema()` method to ensure JSON serializability.
300
-
```python
301
-
from stagehand.schemas import ExtractOptions
302
-
from pydantic import BaseModel
303
-
304
-
classDescriptionSchema(BaseModel):
305
-
description: str
306
-
307
-
# Example:
308
-
data =await page.extract(
309
-
ExtractOptions(
310
-
instruction="extract the description of the page",
You can now use `act_with_cache` to run an action with caching:
397
-
398
-
```python
399
-
prompt ="Click the quickstart link"
400
-
key = prompt # Simple cache key
401
-
await act_with_cache(page, key, prompt)
402
-
```
403
-
404
-
405
-
## Why?
406
-
**Stagehand adds determinism to otherwise unpredictable agents.**
407
-
408
-
While there's no limit to what you could instruct Stagehand to do, our primitives allow you to control how much you want to leave to an AI. It works best when your code is a sequence of atomic actions. Instead of writing a single script for a single website, Stagehand allows you to write durable, self-healing, and repeatable web automation workflows that actually work.
409
-
410
-
> [!NOTE]
411
-
> `Stagehand` is currently available as an early release, and we're actively seeking feedback from the community. Please join our [Slack community](https://join.slack.com/t/stagehand-dev/shared_invite/zt-2tdncfgkk-fF8y5U0uJzR2y2_M9c9OJA) to stay updated on the latest developments and provide feedback.
412
-
413
196
414
197
## Configuration
415
198
@@ -449,6 +232,33 @@ config = StagehandConfig(
449
232
)
450
233
```
451
234
235
+
## Contributing
236
+
237
+
First, create and activate a virtual environment to keep your project dependencies isolated:
0 commit comments