Skip to content

Commit de5966f

Browse files
committed
Remove nest-asyncio dependency
1 parent 9823ad3 commit de5966f

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

.changeset/adamant-black-perch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stagehand": patch
3+
---
4+
5+
Remove nest-asyncio dependency

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "Python SDK for Stagehand"
99
readme = "README.md"
1010
classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent",]
1111
requires-python = ">=3.9"
12-
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",]
12+
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",]
1313
[[project.authors]]
1414
name = "Browserbase, Inc."
1515
email = "support@browserbase.com"

stagehand/main.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typing import Any, Optional
88

99
import httpx
10-
import nest_asyncio
1110
from dotenv import load_dotenv
1211
from playwright.async_api import (
1312
BrowserContext,
@@ -782,12 +781,10 @@ def __getattribute__(self, name):
782781
# Try to get current event loop
783782
try:
784783
asyncio.get_running_loop()
785-
# We're in an async context, need to handle this carefully
786-
# Create a new task and wait for it
787-
nest_asyncio.apply()
788-
return asyncio.run(get_replay_metrics())
784+
# Already in async context, return empty metrics
785+
return StagehandMetrics()
789786
except RuntimeError:
790-
# No event loop running, we can use asyncio.run directly
787+
# No event loop running, safe to use asyncio.run
791788
return asyncio.run(get_replay_metrics())
792789
except Exception as e:
793790
# Log error and return empty metrics

0 commit comments

Comments
 (0)