Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/adamant-black-perch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stagehand": patch
---

Remove nest-asyncio dependency
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description = "Python SDK for Stagehand"
readme = "README.md"
classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent",]
requires-python = ">=3.9"
dependencies = [ "httpx>=0.24.0", "python-dotenv>=1.0.0", "pydantic>=1.10.0", "playwright>=1.42.1", "requests>=2.31.0", "browserbase>=1.4.0", "rich>=13.7.0", "openai>=1.99.6", "anthropic>=0.51.0", "litellm>=1.72.0,<=1.80.0", "nest-asyncio>=1.6.0", "google-genai>=1.40.0",]
dependencies = [ "httpx>=0.24.0", "python-dotenv>=1.0.0", "pydantic>=1.10.0", "playwright>=1.42.1", "requests>=2.31.0", "browserbase>=1.4.0", "rich>=13.7.0", "openai>=1.99.6", "anthropic>=0.51.0", "litellm>=1.72.0,<=1.80.0", "google-genai>=1.40.0",]
[[project.authors]]
name = "Browserbase, Inc."
email = "support@browserbase.com"
Expand Down
9 changes: 3 additions & 6 deletions stagehand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import Any, Optional

import httpx
import nest_asyncio
from dotenv import load_dotenv
from playwright.async_api import (
BrowserContext,
Expand Down Expand Up @@ -782,12 +781,10 @@ def __getattribute__(self, name):
# Try to get current event loop
try:
asyncio.get_running_loop()
# We're in an async context, need to handle this carefully
# Create a new task and wait for it
nest_asyncio.apply()
return asyncio.run(get_replay_metrics())
# Already in async context, return empty metrics
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
return StagehandMetrics()
except RuntimeError:
# No event loop running, we can use asyncio.run directly
# No event loop running, safe to use asyncio.run
return asyncio.run(get_replay_metrics())
except Exception as e:
# Log error and return empty metrics
Expand Down