Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions docs/first-steps/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ main().catch((err) => {

<Tab title="Python">

<Tip>
For uv installation instructions see the [uv installation guide](https://docs.astral.sh/uv/getting-started/installation/#__tabbed_1_1).
</Tip>

### Initialize virtual environment

<CodeGroup>

```bash uv
uv init my-stagehand-project
cd my-stagehand-project
```

```bash pip
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```

</CodeGroup>

### Add dependencies

<CodeGroup>
Expand Down Expand Up @@ -128,6 +148,10 @@ BROWSERBASE_PROJECT_ID=your_project_id
import os
import asyncio
from stagehand import Stagehand
from pydantic import BaseModel

class PageData(BaseModel):
title: str

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

# Extract structured data
result = await page.extract({
"instruction": "extract the page title",
"schema": {
"title": {
"type": "string"
}
}
})
result = await page.extract(
instruction = "extract the page title",
schema = PageData
)

print(result["title"])
print(result.title)
await stagehand.close()

if __name__ == "__main__":
Expand Down