Skip to content

Commit 5145788

Browse files
filip-michalskyKylejeong2miguelg719
authored
add python docs (#787)
# why its about time! # what changed added python docs to mintlify # test plan n/a --------- Co-authored-by: Kylejeong2 <[email protected]> Co-authored-by: miguel <[email protected]>
1 parent 64c1072 commit 5145788

24 files changed

+1490
-332
lines changed

docs/concepts/act.mdx

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,91 @@ Stagehand has an `act()` function that can be used to execute actions on a page
1111
![Take actions with Stagehand](/media/linkedin.gif)
1212

1313
This workflow is as simple as the following lines of code:
14-
```js
14+
15+
<CodeGroup>
16+
```typescript TypeScript
1517
const page = stagehand.page
1618
// Navigate to the URL
1719
await page.goto("https://linkedin.com");
18-
20+
// Click on jobs menu selection
1921
await page.act("click 'jobs'");
22+
// Click on first posting
2023
await page.act("click the first job posting");
2124
```
25+
```python Python
26+
page = stagehand.page
27+
# Navigate to the URL
28+
await page.goto("https://linkedin.com")
29+
# Click on jobs menu selection
30+
await page.act("click 'jobs'")
31+
# Click on first posting
32+
await page.act("click the first job posting")
33+
```
34+
</CodeGroup>
2235

2336
The `page` object extends the Playwright page object, so you can use any of the [Playwright page methods](https://playwright.dev/docs/api/class-page) with it.
2437

25-
## Read structured data from the page
38+
## Get structured data from the page
2639

27-
You can use the `extract()` method to extract structured data from the page. Here's an example of how to extract the job title from the job posting:
40+
You can use `extract()` to get structured data from the page.
41+
Here's an example of how to extract the job title from the job posting:
2842

29-
```js
43+
<CodeGroup>
44+
```typescript TypeScript
3045
const { jobTitle } = await page.extract({
3146
instruction: "Extract the job title from the job posting",
3247
schema: z.object({
3348
jobTitle: z.string(),
3449
}),
3550
});
3651
```
52+
```python Python
53+
result = await page.extract("Extract the job title from the job posting")
54+
```
55+
</CodeGroup>
3756

38-
Stagehand uses [Zod](https://zod.dev/) to help you define the schema of the data to be extracted.
57+
<Info>
58+
Stagehand uses [Zod](https://zod.dev/) for TypeScript and [Pydantic](https://docs.pydantic.dev/) for Python to help you define the schema of the data to be extracted.
59+
</Info>
3960

4061
## Preview/Cache an action
4162

4263
Sometimes you want to preview an action before it's executed. You can do this by calling `page.observe()` before `act()`.
4364

44-
```js
65+
<CodeGroup>
66+
```typescript TypeScript
4567
const [action] = await page.observe("click 'jobs'");
4668

4769
console.log("Going to execute action:", action)
4870
// You can add extra logic here to validate/cache the action
4971

5072
await page.act(action)
5173
```
74+
```python Python
75+
actions = await page.observe("click 'jobs'")
76+
action = actions[0]
77+
78+
print("Going to execute action:", action)
79+
# You can add extra logic here to validate/cache the action
80+
81+
await page.act(action)
82+
```
83+
</CodeGroup>
5284

5385
`action` will be a JSON object that describes the action to be taken.
5486

55-
```javascript
56-
/** action is a JSON-ified version of a Playwright action:
87+
88+
```TypeScript
89+
// action is a JSON-ified version of a Playwright action:
5790
{
5891
description: "The jobs link",
59-
action: "click",
92+
method: "click",
6093
selector: "/html/body/div[1]/div[1]/a",
6194
arguments: [],
6295
}
63-
**/
6496
```
6597

98+
6699
For more on caching, see the [caching docs](/examples/caching).
67100

68101
## What actions can I take?
@@ -83,10 +116,18 @@ We generally support the following actions:
83116
| `prevChunk` | Scrolls the height of the viewport by -100% |
84117

85118
Each of these actions can be triggered using natural language commands. For example:
86-
```js
119+
120+
<CodeGroup>
121+
```typescript TypeScript
122+
await page.act("scroll to the bottom of the page")
123+
await page.act("fill in the username field with 'john_doe'")
124+
await page.act("scroll the modal to the next chunk")
125+
```
126+
```python Python
87127
await page.act("scroll to the bottom of the page")
88128
await page.act("fill in the username field with 'john_doe'")
89129
await page.act("scroll the modal to the next chunk")
90130
```
131+
</CodeGroup>
91132

92133

docs/concepts/agent.mdx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ icon: 'robot'
55
---
66
import { Excalidraw } from '/snippets/excalidraw.mdx';
77

8-
<Tip>
9-
Stagehand agents are brand new in Stagehand 2.0.
10-
</Tip>
11-
128
Stagehand gives AI agents powerful tools to control a browser completely autonomously. Watch below as a Stagehand agent autonomously navigates to a URL, takes actions on the page, and extracts structured data to answer a question.
139
There's quite a few ways to build an agent with Stagehand. Let's look at a few of them.
1410

@@ -20,8 +16,8 @@ The above example is a Claude agent that uses Stagehand to control a browser. At
2016
This means Claude is intelligent enough to know when to request a browser screenshot, and it can then use that screenshot to make decisions about what actions to take next.
2117

2218
<CardGroup>
23-
<Card title="Stagehand MCP" href="https://github.com/browserbase/mcp-server-browserbase/tree/main/stagehand" icon="hand-horns">
24-
Have Claude control a browser with Stagehand MCP.
19+
<Card title="Browserbase MCP" href="https://github.com/browserbase/mcp-server-browserbase/" icon="hand-horns">
20+
Control a browser with Browserbase MCP powered by Stagehand
2521
</Card>
2622
</CardGroup>
2723

@@ -38,7 +34,8 @@ While MCP is really nascent, we're excited to see where it goes.
3834

3935
Stagehand lets you leverage powerful computer use APIs from OpenAI and Anthropic with just one line of code.
4036

41-
```typescript
37+
<CodeGroup>
38+
```typescript TypeScript
4239
await page.goto("https://github.com/browserbase/stagehand");
4340

4441
// Create a Computer Use agent with just one line of code!
@@ -51,6 +48,19 @@ const agent = stagehand.agent({
5148
const result = await agent.execute("Extract the top contributor's username");
5249
console.log(result);
5350
```
51+
```python Python
52+
await page.goto("https://github.com/browserbase/stagehand-python")
53+
54+
# Create a Computer Use agent with just one line of code!
55+
agent = stagehand.agent(
56+
model="computer-use-preview"
57+
)
58+
59+
# Use the agent to execute a task
60+
result = await agent.execute("Extract the top contributor's username")
61+
print(result)
62+
```
63+
</CodeGroup>
5464

5565
<CardGroup>
5666
<Card title="Stagehand + Computer Use Docs" href="/examples/computer_use" icon="scroll">
@@ -74,9 +84,14 @@ It works by calling Stagehand tools in sequence:
7484

7585
<Excalidraw className="w-full" url="https://link.excalidraw.com/readonly/dKh5sB1gEM1EjVqRCGKn" />
7686

77-
Incorporating Open Operator into your browser automation is as easy as adding a single line of code:
87+
Incorporating `stagehand.agent` into your browser automation is as easy as adding a single line of code:
7888

79-
```typescript
89+
<Note>
90+
Python currently supports `stagehand.agent` with Computer Use Agent (CUA) models. The default implementation is coming soon.
91+
</Note>
92+
93+
<CodeGroup>
94+
```typescript TypeScript
8095
await stagehand.page.goto("https://github.com/browserbase/stagehand");
8196

8297
// Open Operator will use the default LLM from Stagehand config
@@ -87,6 +102,7 @@ const { message, actions } = await operator.execute(
87102

88103
console.log(message);
89104
```
105+
</CodeGroup>
90106

91107
### Replay the agent's actions
92108

docs/docs.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@
3535
"examples/contributing"
3636
]
3737
},
38+
{
39+
"group": "Reference",
40+
"pages": [
41+
"reference/initialization_config",
42+
"reference/agent",
43+
"reference/act",
44+
"reference/extract",
45+
"reference/observe",
46+
"reference/playwright_interop",
47+
"integrations/guides"
48+
]
49+
},
3850
{
3951
"group": "Integrations",
4052
"pages": [
@@ -46,17 +58,6 @@
4658
"integrations/claude-code",
4759
"integrations/crew-ai"
4860
]
49-
},
50-
{
51-
"group": "Reference",
52-
"pages": [
53-
"reference/initialization_config",
54-
"reference/agent",
55-
"reference/act",
56-
"reference/extract",
57-
"reference/observe",
58-
"reference/playwright_interop"
59-
]
6061
}
6162
],
6263
"global": {
@@ -77,7 +78,7 @@
7778
"logo": {
7879
"light": "/logo/light_logo.png",
7980
"dark": "/logo/dark_logo.png",
80-
"href": "https://docs.stagehand.dev"
81+
"href": "https://stagehand.dev"
8182
},
8283
"navbar": {
8384
"links": [

0 commit comments

Comments
 (0)