Skip to content

Commit df76f7a

Browse files
authored
Fix python installation instructions (#1087)
# why Initial instructions didn't mention uv or pip prerequisites and also didn't mention venv. Fix reduces friction on first timers. # what changed - added link to install uv - added details for initializing venv - adjusted code example respectively # test plan docs change
1 parent b7be89e commit df76f7a

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

docs/first-steps/installation.mdx

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ main().catch((err) => {
9595

9696
<Tab title="Python">
9797

98+
<Tip>
99+
For uv installation instructions see the [uv installation guide](https://docs.astral.sh/uv/getting-started/installation/#__tabbed_1_1).
100+
</Tip>
101+
102+
### Initialize virtual environment
103+
104+
<CodeGroup>
105+
106+
```bash uv
107+
uv init my-stagehand-project
108+
cd my-stagehand-project
109+
```
110+
111+
```bash pip
112+
python -m venv venv
113+
source venv/bin/activate # On Windows: venv\Scripts\activate
114+
```
115+
116+
</CodeGroup>
117+
98118
### Add dependencies
99119

100120
<CodeGroup>
@@ -128,6 +148,10 @@ BROWSERBASE_PROJECT_ID=your_project_id
128148
import os
129149
import asyncio
130150
from stagehand import Stagehand
151+
from pydantic import BaseModel
152+
153+
class PageData(BaseModel):
154+
title: str
131155

132156
async def main():
133157
stagehand = Stagehand(
@@ -143,16 +167,12 @@ async def main():
143167
await page.act("Click the sign in button")
144168

145169
# Extract structured data
146-
result = await page.extract({
147-
"instruction": "extract the page title",
148-
"schema": {
149-
"title": {
150-
"type": "string"
151-
}
152-
}
153-
})
170+
result = await page.extract(
171+
instruction = "extract the page title",
172+
schema = PageData
173+
)
154174

155-
print(result["title"])
175+
print(result.title)
156176
await stagehand.close()
157177

158178
if __name__ == "__main__":

0 commit comments

Comments
 (0)