create-browser-app 0.1.3__py3-none-any.whl → 0.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- create_browser_app/__init__.py +3 -0
- main.py → create_browser_app/main.py +2 -2
- create_browser_app/template_fetcher.py +75 -0
- create_browser_app/templates.py +131 -0
- {create_browser_app-0.1.3.dist-info → create_browser_app-0.1.4.dist-info}/METADATA +2 -1
- create_browser_app-0.1.4.dist-info/RECORD +9 -0
- create_browser_app-0.1.4.dist-info/entry_points.txt +2 -0
- create_browser_app-0.1.4.dist-info/top_level.txt +1 -0
- create_browser_app-0.1.3.dist-info/RECORD +0 -6
- create_browser_app-0.1.3.dist-info/entry_points.txt +0 -2
- create_browser_app-0.1.3.dist-info/top_level.txt +0 -1
- {create_browser_app-0.1.3.dist-info → create_browser_app-0.1.4.dist-info}/WHEEL +0 -0
|
@@ -9,8 +9,8 @@ from rich.prompt import Prompt, Confirm
|
|
|
9
9
|
from rich.panel import Panel
|
|
10
10
|
from rich.text import Text
|
|
11
11
|
import shutil
|
|
12
|
-
from templates import TEMPLATE_BASIC, TEMPLATE_REQUIREMENTS, TEMPLATE_ENV, TEMPLATE_README, TEMPLATE_GITIGNORE
|
|
13
|
-
from template_fetcher import get_template_by_name, fetch_template_content
|
|
12
|
+
from .templates import TEMPLATE_BASIC, TEMPLATE_REQUIREMENTS, TEMPLATE_ENV, TEMPLATE_README, TEMPLATE_GITIGNORE
|
|
13
|
+
from .template_fetcher import get_template_by_name, fetch_template_content
|
|
14
14
|
|
|
15
15
|
console = Console()
|
|
16
16
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import urllib.request
|
|
3
|
+
import json
|
|
4
|
+
from typing import Dict, List, Optional
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import base64
|
|
7
|
+
|
|
8
|
+
GITHUB_API_BASE = "https://api.github.com"
|
|
9
|
+
REPO_OWNER = "browserbase"
|
|
10
|
+
REPO_NAME = "stagehand-python"
|
|
11
|
+
EXAMPLES_PATH = "examples"
|
|
12
|
+
|
|
13
|
+
def get_available_templates() -> List[Dict[str, str]]:
|
|
14
|
+
"""Fetch list of available templates from GitHub repository."""
|
|
15
|
+
try:
|
|
16
|
+
url = f"{GITHUB_API_BASE}/repos/{REPO_OWNER}/{REPO_NAME}/contents/{EXAMPLES_PATH}"
|
|
17
|
+
req = urllib.request.Request(url)
|
|
18
|
+
req.add_header("Accept", "application/vnd.github.v3+json")
|
|
19
|
+
req.add_header("User-Agent", "create-browser-app-py")
|
|
20
|
+
|
|
21
|
+
with urllib.request.urlopen(req) as response:
|
|
22
|
+
data = json.loads(response.read().decode())
|
|
23
|
+
|
|
24
|
+
templates = []
|
|
25
|
+
for item in data:
|
|
26
|
+
if item["type"] == "file" and item["name"].endswith(".py"):
|
|
27
|
+
# Keep the original name without replacing underscores
|
|
28
|
+
template_name = item["name"].replace(".py", "")
|
|
29
|
+
templates.append({
|
|
30
|
+
"name": template_name,
|
|
31
|
+
"filename": item["name"],
|
|
32
|
+
"url": item["download_url"],
|
|
33
|
+
"api_url": item["url"]
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return templates
|
|
37
|
+
except Exception as e:
|
|
38
|
+
print(f"Error fetching templates: {e}")
|
|
39
|
+
return []
|
|
40
|
+
|
|
41
|
+
def fetch_template_content(template_info: Dict[str, str]) -> Optional[str]:
|
|
42
|
+
"""Fetch the content of a specific template from GitHub."""
|
|
43
|
+
try:
|
|
44
|
+
url = template_info.get("api_url", template_info.get("url"))
|
|
45
|
+
req = urllib.request.Request(url)
|
|
46
|
+
req.add_header("Accept", "application/vnd.github.v3+json")
|
|
47
|
+
req.add_header("User-Agent", "create-browser-app-py")
|
|
48
|
+
|
|
49
|
+
with urllib.request.urlopen(req) as response:
|
|
50
|
+
data = json.loads(response.read().decode())
|
|
51
|
+
|
|
52
|
+
if "content" in data:
|
|
53
|
+
content = base64.b64decode(data["content"]).decode("utf-8")
|
|
54
|
+
else:
|
|
55
|
+
# Fallback to direct download
|
|
56
|
+
with urllib.request.urlopen(template_info["url"]) as response:
|
|
57
|
+
content = response.read().decode("utf-8")
|
|
58
|
+
|
|
59
|
+
return content
|
|
60
|
+
except Exception as e:
|
|
61
|
+
print(f"Error fetching template content: {e}")
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
def get_template_by_name(name: str) -> Optional[Dict[str, str]]:
|
|
65
|
+
"""Get a specific template by name."""
|
|
66
|
+
templates = get_available_templates()
|
|
67
|
+
for template in templates:
|
|
68
|
+
if template["name"] == name:
|
|
69
|
+
return template
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
def list_templates() -> List[str]:
|
|
73
|
+
"""Get a list of template names."""
|
|
74
|
+
templates = get_available_templates()
|
|
75
|
+
return [t["name"] for t in templates]
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
TEMPLATE_BASIC = '''from stagehand import Stagehand
|
|
2
|
+
import asyncio
|
|
3
|
+
import os
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
load_dotenv()
|
|
7
|
+
|
|
8
|
+
async def main():
|
|
9
|
+
"""Basic Stagehand browser automation example."""
|
|
10
|
+
|
|
11
|
+
# Check all the configurations in StagehandConfig
|
|
12
|
+
stagehand = Stagehand(
|
|
13
|
+
env="LOCAL", # or "BROWSERBASE"
|
|
14
|
+
verbose=1, # 0: silent, 1: info, 2: debug
|
|
15
|
+
model_name="gpt-4.1",
|
|
16
|
+
model_api_key=os.getenv("OPENAI_API_KEY"),
|
|
17
|
+
)
|
|
18
|
+
await stagehand.init()
|
|
19
|
+
|
|
20
|
+
page = stagehand.page
|
|
21
|
+
await page.goto("https://docs.stagehand.dev")
|
|
22
|
+
result = await page.extract("In a few words, what is Stagehand?")
|
|
23
|
+
print("\n", result, "\n")
|
|
24
|
+
|
|
25
|
+
await page.act("click on models")
|
|
26
|
+
await page.act({
|
|
27
|
+
"method": "click",
|
|
28
|
+
"selector": "/html/body[1]/div[2]/div[2]/div[3]/div[2]/div[2]/a[1]",
|
|
29
|
+
"description": "the model evaluation card",
|
|
30
|
+
"args": []
|
|
31
|
+
})
|
|
32
|
+
elements = await page.observe("find the graph with the list of most accurate models")
|
|
33
|
+
print("\n", elements, "\n")
|
|
34
|
+
|
|
35
|
+
class Model(BaseModel):
|
|
36
|
+
name: str
|
|
37
|
+
provider: str
|
|
38
|
+
accuracy: float
|
|
39
|
+
|
|
40
|
+
extraction = await page.extract(
|
|
41
|
+
"the most accurate model",
|
|
42
|
+
schema=Model
|
|
43
|
+
)
|
|
44
|
+
print("\n", extraction, "\n")
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
asyncio.run(main())
|
|
48
|
+
|
|
49
|
+
'''
|
|
50
|
+
|
|
51
|
+
TEMPLATE_REQUIREMENTS = '''stagehand
|
|
52
|
+
python-dotenv
|
|
53
|
+
'''
|
|
54
|
+
|
|
55
|
+
TEMPLATE_ENV = '''# Add your environment variables here
|
|
56
|
+
# BROWSERBASE_API_KEY=your_api_key_here
|
|
57
|
+
# BROWSERBASE_PROJECT_ID=your_project_id_here
|
|
58
|
+
'''
|
|
59
|
+
|
|
60
|
+
TEMPLATE_README = '''# {project_name}
|
|
61
|
+
|
|
62
|
+
A Stagehand browser automation project.
|
|
63
|
+
|
|
64
|
+
## Setup
|
|
65
|
+
|
|
66
|
+
1. Install dependencies:
|
|
67
|
+
```bash
|
|
68
|
+
pip install -r requirements.txt
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
2. Configure your environment variables in `.env`:
|
|
72
|
+
```bash
|
|
73
|
+
BROWSERBASE_API_KEY=your_api_key_here
|
|
74
|
+
BROWSERBASE_PROJECT_ID=your_project_id_here
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
3. Run the project:
|
|
78
|
+
```bash
|
|
79
|
+
python main.py
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## About Stagehand
|
|
83
|
+
|
|
84
|
+
Stagehand is a Python library for browser automation built on Playwright. Learn more at:
|
|
85
|
+
- [Stagehand Documentation](https://github.com/browserbase/stagehand)
|
|
86
|
+
- [Browserbase](https://browserbase.com)
|
|
87
|
+
'''
|
|
88
|
+
|
|
89
|
+
TEMPLATE_GITIGNORE = '''# Python
|
|
90
|
+
__pycache__/
|
|
91
|
+
*.py[cod]
|
|
92
|
+
*$py.class
|
|
93
|
+
*.so
|
|
94
|
+
.Python
|
|
95
|
+
build/
|
|
96
|
+
develop-eggs/
|
|
97
|
+
dist/
|
|
98
|
+
downloads/
|
|
99
|
+
eggs/
|
|
100
|
+
.eggs/
|
|
101
|
+
lib/
|
|
102
|
+
lib64/
|
|
103
|
+
parts/
|
|
104
|
+
sdist/
|
|
105
|
+
var/
|
|
106
|
+
wheels/
|
|
107
|
+
*.egg-info/
|
|
108
|
+
.installed.cfg
|
|
109
|
+
*.egg
|
|
110
|
+
|
|
111
|
+
# Virtual Environment
|
|
112
|
+
venv/
|
|
113
|
+
ENV/
|
|
114
|
+
env/
|
|
115
|
+
.venv
|
|
116
|
+
|
|
117
|
+
# Environment variables
|
|
118
|
+
.env
|
|
119
|
+
.env.local
|
|
120
|
+
|
|
121
|
+
# IDE
|
|
122
|
+
.vscode/
|
|
123
|
+
.idea/
|
|
124
|
+
*.swp
|
|
125
|
+
*.swo
|
|
126
|
+
*~
|
|
127
|
+
.DS_Store
|
|
128
|
+
|
|
129
|
+
# Logs
|
|
130
|
+
*.log
|
|
131
|
+
'''
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: create-browser-app
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: Start your Stagehand project with a single command
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -8,6 +8,7 @@ Requires-Dist: stagehand
|
|
|
8
8
|
Requires-Dist: click>=8.0
|
|
9
9
|
Requires-Dist: rich>=13.0
|
|
10
10
|
Requires-Dist: inquirer>=3.0
|
|
11
|
+
Requires-Dist: requests>=2.25.0
|
|
11
12
|
|
|
12
13
|
# create-browser-app (Python)
|
|
13
14
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
create_browser_app/__init__.py,sha256=izlkaSvrxNqPnulbHlD8VYldR618NxRQRlKQFgQn0Gk,42
|
|
2
|
+
create_browser_app/main.py,sha256=eY3dEQK_Qop07SCPNdkOtZKUyX9RnoBJZpmpU_Y1oQI,4789
|
|
3
|
+
create_browser_app/template_fetcher.py,sha256=kfNOFdJlBPjgtAuroVsD-zuXWd04wSpQHTBmYXHDJAc,2723
|
|
4
|
+
create_browser_app/templates.py,sha256=f2YhewO6lStBO-46mfrDXdSQVhGLY0jUgRwjbZG1UpU,2482
|
|
5
|
+
create_browser_app-0.1.4.dist-info/METADATA,sha256=aD65Xl5VoCh0_qRCbhjVkEV7wLnCw3BxcqonxKOr5UA,648
|
|
6
|
+
create_browser_app-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
+
create_browser_app-0.1.4.dist-info/entry_points.txt,sha256=yyAKhFZs2kraGA_ixwnRZeStL0uxWvBCMzysg8S-0VE,68
|
|
8
|
+
create_browser_app-0.1.4.dist-info/top_level.txt,sha256=sLW8imVtlXvOy1D5aGPBDxbMP3Yvonif7VxcLu_Izy4,19
|
|
9
|
+
create_browser_app-0.1.4.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
create_browser_app
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
main.py,sha256=g-0fa4qfu_70nT4k_qbH1f6554jtSjVaseTSUi7HDSo,4787
|
|
2
|
-
create_browser_app-0.1.3.dist-info/METADATA,sha256=XkoXHE8dFTQ7yRPyOpPwNuam6u36nvW9S-pzHmYEshM,616
|
|
3
|
-
create_browser_app-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
4
|
-
create_browser_app-0.1.3.dist-info/entry_points.txt,sha256=S7VEMgVttj-lbn3gh_gPTJJpwczelIrb5fZgo5ecKHs,49
|
|
5
|
-
create_browser_app-0.1.3.dist-info/top_level.txt,sha256=ZAMgPdWghn6xTRBO6Kc3ML1y3ZrZLnjZlqbboKXc_AE,5
|
|
6
|
-
create_browser_app-0.1.3.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
main
|
|
File without changes
|