Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Stagehand is the SDK for browser agents.
Read the Docs

MIT License Discord Community

browserbase%2Fstagehand | Trendshift

Ask DeepWiki

Stagehand Python SDK

What is Stagehand?

Stagehand is the SDK for browser agents. Playwright was built for testing, Stagehand is built for agents. Use familiar APIs, self-healing actions, and network-level security across TypeScript, Python, and Go.

Why Stagehand?

Stagehand gives browser agents an interface built for how they actually work. It combines familiar Playwright-style APIs with self-healing actions, agent-optimized page context, and native support for complex DOM structures like out-of-process iframes and closed Shadow DOMs.

Agents use fewer tokens, recover when websites change, and complete tasks more reliably. With a complete browser driver across TypeScript, Python, and Go, Stagehand delivers the flexibility of AI without sacrificing the speed, control, determinism, reliability, and observability required in production.

For the full overview, examples, and contributing guide, see the main README.

Example

The async Python SDK for Stagehand browser automation:

import asyncio
import os

from pydantic import BaseModel

from stagehand import Stagehand, local_browser


class PullRequest(BaseModel):
    author: str
    title: str


async def main() -> None:
    browser = await local_browser.launch(headless=True)
    try:
        stagehand = await Stagehand.create(
            browser=browser,
            model="openai/gpt-5.4-mini",
            model_api_key=os.environ["OPENAI_API_KEY"],
        )
        try:
            page = (await browser.context.pages())[0]
            await page.goto("https://github.com/browserbase")

            # act() executes individual actions
            await stagehand.act("click on the stagehand repo")

            # observe() reports what is actionable on the page
            observed = await stagehand.observe("find the latest PR")

            # Locators give deterministic, Playwright-style actions
            await page.locator(observed.data[0].selector).click()

            # extract() returns structured data validated by a pydantic model
            result = await stagehand.extract(
                "extract the author and title of the PR",
                PullRequest,
            )
            print(result.data.author, result.data.title)
        finally:
            await stagehand.close()
    finally:
        await browser.close()


asyncio.run(main())

See examples for action, extraction, observation, and custom LLM usage.

For hosted browsers, import browserbase from stagehand and use browserbase.launch(api_key=...) or browserbase.connect(api_key=..., session_id=...) instead of local_browser. A launched session is released when you close() the browser handle, except with keep_alive=True: that handle's close() only disconnects, and the session keeps running until it is released out of band (Browserbase dashboard or API) or reaches its configured timeout. The Stagehand extension that launch() uploaded for that session is retained on the account for the same reason, so a keep_alive=True workflow that launches repeatedly accumulates extensions until they are deleted out of band. Sessions reached through browserbase.connect() are never released by close() — whoever created the session owns it.

Stagehand.act(), Stagehand.observe(), and Stagehand.extract() use the active page by default. Pass page=page to target a specific SDK Page.

Page.goto(), reload(), go_back(), and go_forward() return the main-document Response, or None when navigation does not produce one. Response bodies and complete headers are retrieved lazily while the Stagehand session remains open.

When contributing examples or tests, keep browser ownership explicit: launch or connect a browser handle, pass it to Stagehand.create(), close Stagehand first, and close the browser in the outermost finally block.

Contributing

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install just
brew install just

just install
just generate
just check
just test
just build

Release files for stagehand 4.0.3a0.dev1475

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stagehand 4.0.3a0.dev1475
File Size Uploaded
stagehand-4.0.3a0.dev1475.tar.gz 484.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stagehand 4.0.3a0.dev1475
File Interpreter ABI Platform
stagehand-4.0.3a0.dev1475-py3-none-any.whl Python 3 none any Details

Total release size: 980.7 kB

Release files / stagehand-4.0.3a0.dev1475.tar.gz

Download URL stagehand-4.0.3a0.dev1475.tar.gz
Size 484.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f7a53d4a6dda1bece4a6a1a99edece700c010998c1c966644df8765f6b889e7e
BLAKE2b-256 checksum
How to use checksums
c7aa2a6911059185dad0599699eac9b470769cd293d45f08d5c74904a47e9e62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / stagehand-4.0.3a0.dev1475-py3-none-any.whl

Download URL stagehand-4.0.3a0.dev1475-py3-none-any.whl
Size 496.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f7fc4edb72f5272325bff3f99b3ff8a5397920e0c7e764c01250d7ad8232d13
BLAKE2b-256 checksum
How to use checksums
399f9741903c4ee58609c1d5d326055f3ba2d3a683bb2c39e084e62cbf103f65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

4.1.0

2 release files

4.0.3

2 release files

This release

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.23.0

5 release files

3.22.0

5 release files

3.21.0

5 release files

3.19.1

5 release files

3.19.0

5 release files

3.18.0

5 release files

3.7.0

5 release files

3.6.0

5 release files

3.5.0

5 release files

3.4.8

5 release files

3.4.7

5 release files

3.4.6

5 release files

3.4.2

5 release files

3.4.1

5 release files

3.4.0

2 release files

0.5.14

2 release files

0.5.13

2 release files

0.5.12

2 release files

0.5.11

2 release files

0.5.10

1 release file

0.5.9

2 release files

0.5.8

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

3 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page