We use uv to manage dependencies because it will automatically provision a Python environment with the expected Python version. To set it up, run:
$ ./scripts/bootstrapOr install uv manually and run:
$ uv sync --all-extrasYou can then run scripts using uv run python script.py:
uv run python script.pyMost of the SDK is generated code. Modifications to code will be persisted between generations, but may
result in merge conflicts between manual patches and changes from the generator. The generator will never
modify the contents of the src/stagehand/lib/ and examples/ directories.
The SDK supports running a local Stagehand server for development and testing. To use this feature, you need to download the appropriate binary for your platform.
Run the download script to automatically download the correct binary:
$ uv run python scripts/download-binary.pyThis will:
- Detect your platform (macOS, Linux, Windows) and architecture (x64, arm64)
- Download the latest stagehand-server binary from GitHub releases
- Place it in
bin/sea/where the SDK expects to find it
You can also manually download from GitHub releases:
- Find the latest
stagehand/server vX.X.Xrelease - Download the binary for your platform:
- macOS ARM:
stagehand-server-darwin-arm64 - macOS Intel:
stagehand-server-darwin-x64 - Linux:
stagehand-server-linux-x64orstagehand-server-linux-arm64 - Windows:
stagehand-server-win32-x64.exeorstagehand-server-win32-arm64.exe
- macOS ARM:
- Rename it to match the expected format (remove
-serverfrom the name):stagehand-darwin-arm64,stagehand-linux-x64,stagehand-win32-x64.exe, etc.
- Place it in
bin/sea/directory - Make it executable (Unix only):
chmod +x bin/sea/stagehand-*
Instead of placing the binary in bin/sea/, you can point to any binary location:
$ export STAGEHAND_SEA_BINARY=/path/to/your/stagehand-binary
$ uv run python test_local_mode.pyAll files in the examples/ directory are not modified by the generator and can be freely edited or added to.
# add an example to examples/<your-example>.py
#!/usr/bin/env -S uv run python
…$ chmod +x examples/<your-example>.py
# run the example against your api
$ ./examples/<your-example>.pyIf you’d like to use the repository from source, you can either install from git or link to a cloned repository:
To install via git:
$ uv run pip install git+ssh://git@github.com/browserbase/stagehand-python.gitAlternatively, you can build from source and install the wheel file:
Building this package will create two files in the dist/ directory, a .tar.gz containing the source files and a .whl that can be used to install the package efficiently.
To create a distributable version of the library, all you have to do is run this command:
$ uv build
# or
$ uv run python -m buildThen to install:
uv run pip install ./path-to-wheel-file.whl$ uv run -- ./scripts/testThis repository uses ruff and black to format the code in the repository.
To lint:
$ uv run -- ./scripts/lintTo format and fix all ruff issues automatically:
$ uv run -- ./scripts/formatChanges made to this repository via the automated release PR pipeline should publish to PyPI automatically. If the changes aren't made through the automated pipeline, you may want to make releases manually.
You can release to package managers by using the Publish PyPI GitHub action. This requires a setup organization or repository secret to be set up.
If you need to manually release a package, you can run the bin/publish-pypi script with a PYPI_TOKEN set on
the environment.