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, browserbase, 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. Calling close() on the browser handle releases the Browserbase session. To keep a keep_alive=True session for later, call stagehand.close() without browser.close().

The same browserbase facade exposes Browserbase Search and Fetch without launching a browser:

import asyncio
import os

from stagehand import browserbase


async def search_and_fetch() -> None:
    results = await browserbase.search(
        api_key=os.environ["BROWSERBASE_API_KEY"],
        query="browser agent frameworks",
        num_results=5,
    )
    fetched = await browserbase.fetch(
        api_key=os.environ["BROWSERBASE_API_KEY"],
        url=results.results[0].url,
        format="markdown",
    )
    print(fetched.content)


asyncio.run(search_and_fetch())

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

Metadata

Release files for stagehand 4.3.1a0.dev1655

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.3.1a0.dev1655
File Size Uploaded Provenance Actions
stagehand-4.3.1a0.dev1655.tar.gz 532.7 kB Without provenance Details for stagehand-4.3.1a0.dev1655.tar.gz

Built distribution (wheel)

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

Total release size: 1.1 MB

Release files / stagehand-4.3.1a0.dev1655.tar.gz

Download URL stagehand-4.3.1a0.dev1655.tar.gz
Size 532.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2342a67f9c3917f9e879e5951337053cadb0abdd191683879728b8e1bedeb78b
BLAKE2b-256 checksum
How to use checksums
bb53aea2056bbc09916ed2f212fa121d034e8d3cbfea672824bf06746263a0ff
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.3.1a0.dev1655-py3-none-any.whl

Download URL stagehand-4.3.1a0.dev1655-py3-none-any.whl
Size 546.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f03a58c690d0d79544740acd597556e476a946efef32969b39abcbda441cc5dd
BLAKE2b-256 checksum
How to use checksums
d12805042ef880fcf6a650dec2066311645c512511b68e25fd7837c63605b527
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}

Security for stagehand 4.3.1a0.dev1655

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
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