create-browser-app 0.1.3__tar.gz → 0.1.4__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: create-browser-app
3
- Version: 0.1.3
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,3 @@
1
+ from .main import main
2
+
3
+ __all__ = ["main"]
@@ -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
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
 
@@ -1,6 +1,9 @@
1
1
  README.md
2
- main.py
3
2
  pyproject.toml
3
+ create_browser_app/__init__.py
4
+ create_browser_app/main.py
5
+ create_browser_app/template_fetcher.py
6
+ create_browser_app/templates.py
4
7
  create_browser_app.egg-info/PKG-INFO
5
8
  create_browser_app.egg-info/SOURCES.txt
6
9
  create_browser_app.egg-info/dependency_links.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ create-browser-app = create_browser_app.main:main
@@ -2,3 +2,4 @@ stagehand
2
2
  click>=8.0
3
3
  rich>=13.0
4
4
  inquirer>=3.0
5
+ requests>=2.25.0
@@ -0,0 +1,2 @@
1
+ create_browser_app
2
+ dist
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "create-browser-app"
7
+ version = "0.1.4"
8
+ description = "Start your Stagehand project with a single command"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ dependencies = [
12
+ "stagehand",
13
+ "click>=8.0",
14
+ "rich>=13.0",
15
+ "inquirer>=3.0",
16
+ "requests>=2.25.0"
17
+ ]
18
+
19
+ [project.scripts]
20
+ create-browser-app = "create_browser_app.main:main"
21
+
22
+ [tool.setuptools.packages]
23
+ find = {}
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- create-browser-app = main:main
@@ -1,15 +0,0 @@
1
- [project]
2
- name = "create-browser-app"
3
- version = "0.1.3"
4
- description = "Start your Stagehand project with a single command"
5
- readme = "README.md"
6
- requires-python = ">=3.10"
7
- dependencies = [
8
- "stagehand",
9
- "click>=8.0",
10
- "rich>=13.0",
11
- "inquirer>=3.0"
12
- ]
13
-
14
- [project.scripts]
15
- create-browser-app = "main:main"