fastweb-sdk 0.1.0__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.
- fastweb/__init__.py +19 -0
- fastweb/__main__.py +144 -0
- fastweb/browser.py +344 -0
- fastweb/errors.py +15 -0
- fastweb_sdk-0.1.0.dist-info/METADATA +184 -0
- fastweb_sdk-0.1.0.dist-info/RECORD +10 -0
- fastweb_sdk-0.1.0.dist-info/WHEEL +5 -0
- fastweb_sdk-0.1.0.dist-info/entry_points.txt +2 -0
- fastweb_sdk-0.1.0.dist-info/licenses/LICENSE +21 -0
- fastweb_sdk-0.1.0.dist-info/top_level.txt +1 -0
fastweb/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""
|
|
2
|
+
FastWeb Python SDK
|
|
3
|
+
Zero-overhead, high-speed web execution for sovereign AI agents.
|
|
4
|
+
|
|
5
|
+
NOTE: The FastWeb binary must be installed separately via:
|
|
6
|
+
python -m fastweb install
|
|
7
|
+
|
|
8
|
+
Or manually:
|
|
9
|
+
curl -sL https://fastweb.b4n1.com/install | bash
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from .browser import AgentBrowser, BrowserMode, Page
|
|
13
|
+
from .errors import BinaryNotFoundError
|
|
14
|
+
|
|
15
|
+
__version__ = "0.1.0"
|
|
16
|
+
__author__ = "Bani Montoya"
|
|
17
|
+
__email__ = "banimontoya@gmail.com"
|
|
18
|
+
|
|
19
|
+
__all__ = ["AgentBrowser", "BrowserMode", "Page", "BinaryNotFoundError"]
|
fastweb/__main__.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"""
|
|
2
|
+
FastWeb CLI Entry Point
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def install_command():
|
|
7
|
+
"""Handle the 'python -m fastweb install' command."""
|
|
8
|
+
import sys
|
|
9
|
+
import os
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
print("FastWeb Binary Installer")
|
|
13
|
+
print("=" * 30)
|
|
14
|
+
|
|
15
|
+
# Import local modules to avoid circular imports
|
|
16
|
+
from .browser import get_fastweb_binary, get_fastweb_version
|
|
17
|
+
|
|
18
|
+
# Check if already installed
|
|
19
|
+
existing = get_fastweb_binary()
|
|
20
|
+
if existing:
|
|
21
|
+
version = get_fastweb_version()
|
|
22
|
+
print(f"FastWeb already installed at: {existing}")
|
|
23
|
+
print(f"Version: {version}")
|
|
24
|
+
response = input("Reinstall? (y/N): ").lower().strip()
|
|
25
|
+
if response not in ("y", "yes"):
|
|
26
|
+
print("Installation cancelled.")
|
|
27
|
+
return
|
|
28
|
+
|
|
29
|
+
# Determine install location
|
|
30
|
+
if os.access("/usr/local/bin", os.W_OK):
|
|
31
|
+
install_dir = Path("/usr/local/bin")
|
|
32
|
+
use_sudo = False
|
|
33
|
+
elif os.access(str(Path.home() / ".local/bin"), os.W_OK):
|
|
34
|
+
install_dir = Path.home() / ".local/bin"
|
|
35
|
+
use_sudo = False
|
|
36
|
+
else:
|
|
37
|
+
install_dir = Path.home() / ".fastweb" / "bin"
|
|
38
|
+
use_sudo = False # User directory, no sudo needed
|
|
39
|
+
|
|
40
|
+
install_dir.mkdir(parents=True, exist_ok=True)
|
|
41
|
+
binary_path = install_dir / "fastweb"
|
|
42
|
+
|
|
43
|
+
# Download binary
|
|
44
|
+
version_url = "https://fastweb.b4n1.com/latest-version"
|
|
45
|
+
print(f"\nChecking latest version...")
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
import requests
|
|
49
|
+
|
|
50
|
+
resp = requests.get(version_url, timeout=10)
|
|
51
|
+
version_info = resp.json()
|
|
52
|
+
download_url = version_info.get("url")
|
|
53
|
+
version = version_info.get("version", "unknown")
|
|
54
|
+
print(f"Latest version: {version}")
|
|
55
|
+
print(f"Downloading from: {download_url}")
|
|
56
|
+
except Exception as e:
|
|
57
|
+
print(f"Error getting version info: {e}")
|
|
58
|
+
sys.exit(1)
|
|
59
|
+
|
|
60
|
+
print(f"\nDownloading FastWeb {version}...")
|
|
61
|
+
try:
|
|
62
|
+
resp = requests.get(download_url, timeout=60)
|
|
63
|
+
resp.raise_for_status()
|
|
64
|
+
|
|
65
|
+
import tarfile
|
|
66
|
+
|
|
67
|
+
with tempfile.NamedTemporaryFile(suffix=".tar.gz", delete=False) as tmp_tar:
|
|
68
|
+
tmp_tar.write(resp.content)
|
|
69
|
+
tmp_tar_path = tmp_tar.name
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
# Extract and install binary
|
|
73
|
+
with tarfile.open(tmp_tar_path, "r:gz") as tar:
|
|
74
|
+
# Find the binary in the tar
|
|
75
|
+
for member in tar.getmembers():
|
|
76
|
+
if member.isfile() and member.name.endswith(
|
|
77
|
+
"/fastweb-v0.1.0-x86_64"
|
|
78
|
+
):
|
|
79
|
+
# Extract the binary
|
|
80
|
+
binary_data = tar.extractfile(member)
|
|
81
|
+
if binary_data:
|
|
82
|
+
with open(binary_path, "wb") as f:
|
|
83
|
+
f.write(binary_data.read())
|
|
84
|
+
break
|
|
85
|
+
else:
|
|
86
|
+
# Fallback: look for any executable
|
|
87
|
+
for member in tar.getmembers():
|
|
88
|
+
if member.isfile():
|
|
89
|
+
binary_data = tar.extractfile(member)
|
|
90
|
+
if binary_data:
|
|
91
|
+
with open(binary_path, "wb") as f:
|
|
92
|
+
f.write(binary_data.read())
|
|
93
|
+
break
|
|
94
|
+
|
|
95
|
+
# Make executable
|
|
96
|
+
if use_sudo:
|
|
97
|
+
import subprocess
|
|
98
|
+
|
|
99
|
+
subprocess.run(["chmod", "+x", str(binary_path)], check=True)
|
|
100
|
+
if str(binary_path).startswith("/usr/local/bin") or str(
|
|
101
|
+
binary_path
|
|
102
|
+
).startswith("/usr/bin"):
|
|
103
|
+
subprocess.run(
|
|
104
|
+
["sudo", "chmod", "+x", str(binary_path)], check=True
|
|
105
|
+
)
|
|
106
|
+
else:
|
|
107
|
+
os.chmod(binary_path, 0o755)
|
|
108
|
+
|
|
109
|
+
# Verify installation
|
|
110
|
+
installed_version = get_fastweb_version()
|
|
111
|
+
print(f"✓ FastWeb {installed_version} installed to: {binary_path}")
|
|
112
|
+
|
|
113
|
+
if not use_sudo:
|
|
114
|
+
# Add to PATH instructions
|
|
115
|
+
rc_file = Path.home() / (
|
|
116
|
+
".bashrc"
|
|
117
|
+
if os.environ.get("SHELL", "").endswith("bash")
|
|
118
|
+
else ".zshrc"
|
|
119
|
+
)
|
|
120
|
+
path_line = f'export PATH="{install_dir}:$PATH"'
|
|
121
|
+
if rc_file.exists():
|
|
122
|
+
content = rc_file.read_text()
|
|
123
|
+
if path_line not in content:
|
|
124
|
+
print(f"\nTo use FastWeb, add this to your {rc_file.name}:")
|
|
125
|
+
print(f" {path_line}")
|
|
126
|
+
else:
|
|
127
|
+
print(
|
|
128
|
+
f"\nTo use FastWeb, add this to your shell rc file (~/.bashrc or ~/.zshrc):"
|
|
129
|
+
)
|
|
130
|
+
print(f" {path_line}")
|
|
131
|
+
|
|
132
|
+
finally:
|
|
133
|
+
try:
|
|
134
|
+
os.unlink(tmp_tar_path)
|
|
135
|
+
except:
|
|
136
|
+
pass
|
|
137
|
+
|
|
138
|
+
except Exception as e:
|
|
139
|
+
print(f"Error installing FastWeb: {e}")
|
|
140
|
+
sys.exit(1)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
if __name__ == "__main__":
|
|
144
|
+
install_command()
|
fastweb/browser.py
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"""
|
|
2
|
+
FastWeb Python SDK - Browser automation for AI agents
|
|
3
|
+
|
|
4
|
+
This module provides a Python interface to the FastWeb Rust engine.
|
|
5
|
+
The FastWeb binary must be installed separately via: python -m fastweb install
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import subprocess
|
|
10
|
+
import tempfile
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from enum import Enum
|
|
13
|
+
from typing import List, Optional
|
|
14
|
+
import requests
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class BrowserMode(Enum):
|
|
18
|
+
"""Browser execution modes."""
|
|
19
|
+
|
|
20
|
+
LIGHT = "light"
|
|
21
|
+
RENDER = "render"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class Page:
|
|
26
|
+
"""Structured page data returned by FastWeb."""
|
|
27
|
+
|
|
28
|
+
url: str
|
|
29
|
+
markdown: str
|
|
30
|
+
links: List[str]
|
|
31
|
+
screenshot: Optional[str] = None
|
|
32
|
+
|
|
33
|
+
def get_main_content(self) -> str:
|
|
34
|
+
"""Extract main content from markdown."""
|
|
35
|
+
lines = self.markdown.split("\n")
|
|
36
|
+
content_lines = lines[2:] if len(lines) > 2 else lines
|
|
37
|
+
return "\n".join(content_lines).strip()
|
|
38
|
+
|
|
39
|
+
def find_links_by_text(self, text: str) -> List[str]:
|
|
40
|
+
"""Find links containing specific text."""
|
|
41
|
+
return [link for link in self.links if text.lower() in link.lower()]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_fastweb_binary() -> Optional[str]:
|
|
45
|
+
"""Find fastweb binary in common install locations."""
|
|
46
|
+
import os
|
|
47
|
+
from pathlib import Path
|
|
48
|
+
import shutil
|
|
49
|
+
|
|
50
|
+
# Check standard locations where the install script puts it
|
|
51
|
+
possible_locations = [
|
|
52
|
+
"/usr/local/bin/fastweb",
|
|
53
|
+
"/usr/bin/fastweb",
|
|
54
|
+
str(Path.home() / ".local/bin/fastweb"),
|
|
55
|
+
str(Path.home() / ".fastweb/bin/fastweb"),
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
for loc in possible_locations:
|
|
59
|
+
if os.path.isfile(loc) and os.access(loc, os.X_OK):
|
|
60
|
+
return loc
|
|
61
|
+
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class BinaryNotFoundError(RuntimeError):
|
|
66
|
+
"""Raised when FastWeb binary is not found and needs to be installed."""
|
|
67
|
+
|
|
68
|
+
def __init__(self):
|
|
69
|
+
super().__init__(
|
|
70
|
+
"FastWeb binary not found. Please install it first:\n"
|
|
71
|
+
" python -m fastweb install\n"
|
|
72
|
+
"Or manually:\n"
|
|
73
|
+
" curl -sL https://fastweb.b4n1.com/install | bash"
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class AgentBrowser:
|
|
78
|
+
"""
|
|
79
|
+
FastWeb Agent Browser
|
|
80
|
+
|
|
81
|
+
A browser instance optimized for AI agent workflows.
|
|
82
|
+
Requires FastWeb binary to be installed via: python -m fastweb install
|
|
83
|
+
|
|
84
|
+
Example:
|
|
85
|
+
>>> browser = AgentBrowser(mode=BrowserMode.LIGHT)
|
|
86
|
+
>>> page = browser.goto("https://example.com")
|
|
87
|
+
>>> print(page.markdown)
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
def __init__(
|
|
91
|
+
self,
|
|
92
|
+
mode: BrowserMode = BrowserMode.LIGHT,
|
|
93
|
+
timeout: int = 30,
|
|
94
|
+
user_agent: str = "FastWeb-Agent/1.0",
|
|
95
|
+
):
|
|
96
|
+
self.mode = mode
|
|
97
|
+
self.timeout = timeout
|
|
98
|
+
self.user_agent = user_agent
|
|
99
|
+
self.session = requests.Session()
|
|
100
|
+
self.session.headers.update(
|
|
101
|
+
{
|
|
102
|
+
"User-Agent": user_agent,
|
|
103
|
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
104
|
+
"Accept-Language": "en-US,en;q=0.5",
|
|
105
|
+
"Accept-Encoding": "gzip, deflate",
|
|
106
|
+
"DNT": "1",
|
|
107
|
+
"Connection": "keep-alive",
|
|
108
|
+
"Upgrade-Insecure-Requests": "1",
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
# Verify binary is available - will raise BinaryNotFoundError if not found
|
|
112
|
+
from .errors import BinaryNotFoundError
|
|
113
|
+
|
|
114
|
+
binary_path = get_fastweb_binary()
|
|
115
|
+
if not binary_path:
|
|
116
|
+
raise BinaryNotFoundError()
|
|
117
|
+
|
|
118
|
+
@property
|
|
119
|
+
def binary_path(self) -> str:
|
|
120
|
+
"""Get fastweb binary path."""
|
|
121
|
+
binary_path = get_fastweb_binary()
|
|
122
|
+
if not binary_path:
|
|
123
|
+
from .errors import BinaryNotFoundError
|
|
124
|
+
|
|
125
|
+
raise BinaryNotFoundError()
|
|
126
|
+
return binary_path
|
|
127
|
+
|
|
128
|
+
def goto(self, url: str) -> Page:
|
|
129
|
+
"""Navigate to a URL and extract structured content."""
|
|
130
|
+
try:
|
|
131
|
+
response = self.session.get(url, timeout=self.timeout)
|
|
132
|
+
response.raise_for_status()
|
|
133
|
+
|
|
134
|
+
content_type = response.headers.get("content-type", "")
|
|
135
|
+
if "text/html" not in content_type:
|
|
136
|
+
raise ValueError(f"Not HTML content: {content_type}")
|
|
137
|
+
|
|
138
|
+
html = response.text
|
|
139
|
+
|
|
140
|
+
# Use Rust binary for parsing
|
|
141
|
+
return self._parse_with_rust(url, html)
|
|
142
|
+
|
|
143
|
+
except requests.RequestException as e:
|
|
144
|
+
raise requests.RequestException(f"Failed to fetch {url}: {e}")
|
|
145
|
+
|
|
146
|
+
def _parse_with_rust(self, url: str, html: str) -> Page:
|
|
147
|
+
"""Parse HTML using Rust binary."""
|
|
148
|
+
# Write HTML to temp file
|
|
149
|
+
with tempfile.NamedTemporaryFile(mode="w", suffix=".html", delete=False) as tmp:
|
|
150
|
+
tmp.write(html)
|
|
151
|
+
tmp_path = tmp.name
|
|
152
|
+
|
|
153
|
+
try:
|
|
154
|
+
# Run fastweb CLI
|
|
155
|
+
result = subprocess.run(
|
|
156
|
+
[self.binary_path, "fetch", url, "--text", "--links"],
|
|
157
|
+
capture_output=True,
|
|
158
|
+
timeout=30,
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
if result.returncode == 0 and result.stdout:
|
|
162
|
+
try:
|
|
163
|
+
data = json.loads(result.stdout)
|
|
164
|
+
return Page(
|
|
165
|
+
url=url,
|
|
166
|
+
markdown=data.get("text", ""),
|
|
167
|
+
links=data.get("links", []),
|
|
168
|
+
)
|
|
169
|
+
except json.JSONDecodeError:
|
|
170
|
+
pass
|
|
171
|
+
|
|
172
|
+
raise RuntimeError(f"Binary parse failed: {result.stderr.decode()}")
|
|
173
|
+
finally:
|
|
174
|
+
try:
|
|
175
|
+
os.unlink(tmp_path)
|
|
176
|
+
except:
|
|
177
|
+
pass
|
|
178
|
+
|
|
179
|
+
def close(self):
|
|
180
|
+
"""Close the browser session."""
|
|
181
|
+
self.session.close()
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def get_fastweb_version() -> str:
|
|
185
|
+
"""Get FastWeb binary version."""
|
|
186
|
+
try:
|
|
187
|
+
result = subprocess.run(
|
|
188
|
+
[get_fastweb_binary(), "--version"],
|
|
189
|
+
capture_output=True,
|
|
190
|
+
text=True,
|
|
191
|
+
timeout=5,
|
|
192
|
+
)
|
|
193
|
+
if result.returncode == 0:
|
|
194
|
+
return result.stdout.strip()
|
|
195
|
+
except Exception:
|
|
196
|
+
pass
|
|
197
|
+
return "unknown"
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
# CLI command implementation
|
|
201
|
+
def install_command():
|
|
202
|
+
"""Handle the 'python -m fastweb install' command."""
|
|
203
|
+
import sys
|
|
204
|
+
import os
|
|
205
|
+
from pathlib import Path
|
|
206
|
+
|
|
207
|
+
print("FastWeb Binary Installer")
|
|
208
|
+
print("=" * 30)
|
|
209
|
+
|
|
210
|
+
# Check if already installed
|
|
211
|
+
existing = get_fastweb_binary()
|
|
212
|
+
if existing:
|
|
213
|
+
version = get_fastweb_version()
|
|
214
|
+
print(f"FastWeb already installed at: {existing}")
|
|
215
|
+
print(f"Version: {version}")
|
|
216
|
+
response = input("Reinstall? (y/N): ").lower().strip()
|
|
217
|
+
if response not in ("y", "yes"):
|
|
218
|
+
print("Installation cancelled.")
|
|
219
|
+
return
|
|
220
|
+
|
|
221
|
+
# Determine install location
|
|
222
|
+
if os.access("/usr/local/bin", os.W_OK):
|
|
223
|
+
install_dir = Path("/usr/local/bin")
|
|
224
|
+
use_sudo = False
|
|
225
|
+
elif os.access(str(Path.home() / ".local/bin"), os.W_OK):
|
|
226
|
+
install_dir = Path.home() / ".local/bin"
|
|
227
|
+
use_sudo = False
|
|
228
|
+
else:
|
|
229
|
+
install_dir = Path.home() / ".fastweb" / "bin"
|
|
230
|
+
use_sudo = False # User directory, no sudo needed
|
|
231
|
+
|
|
232
|
+
install_dir.mkdir(parents=True, exist_ok=True)
|
|
233
|
+
binary_path = install_dir / "fastweb"
|
|
234
|
+
|
|
235
|
+
# Download binary
|
|
236
|
+
version_url = "https://fastweb.b4n1.com/latest-version"
|
|
237
|
+
print(f"\nChecking latest version...")
|
|
238
|
+
|
|
239
|
+
try:
|
|
240
|
+
resp = requests.get(version_url, timeout=10)
|
|
241
|
+
version_info = resp.json()
|
|
242
|
+
download_url = version_info.get("url")
|
|
243
|
+
version = version_info.get("version", "unknown")
|
|
244
|
+
print(f"Latest version: {version}")
|
|
245
|
+
print(f"Downloading from: {download_url}")
|
|
246
|
+
except Exception as e:
|
|
247
|
+
print(f"Error getting version info: {e}")
|
|
248
|
+
sys.exit(1)
|
|
249
|
+
|
|
250
|
+
print(f"\nDownloading FastWeb {version}...")
|
|
251
|
+
try:
|
|
252
|
+
resp = requests.get(download_url, timeout=60)
|
|
253
|
+
resp.raise_for_status()
|
|
254
|
+
|
|
255
|
+
import tarfile
|
|
256
|
+
|
|
257
|
+
with tempfile.NamedTemporaryFile(suffix=".tar.gz", delete=False) as tmp_tar:
|
|
258
|
+
tmp_tar.write(resp.content)
|
|
259
|
+
tmp_tar_path = tmp_tar.name
|
|
260
|
+
|
|
261
|
+
try:
|
|
262
|
+
# Extract and install binary
|
|
263
|
+
with tarfile.open(tmp_tar_path, "r:gz") as tar:
|
|
264
|
+
# Find the binary in the tar
|
|
265
|
+
for member in tar.getmembers():
|
|
266
|
+
if member.isfile() and member.name.endswith(
|
|
267
|
+
"/fastweb-v0.1.0-x86_64"
|
|
268
|
+
):
|
|
269
|
+
# Extract the binary
|
|
270
|
+
binary_data = tar.extractfile(member)
|
|
271
|
+
if binary_data:
|
|
272
|
+
with open(binary_path, "wb") as f:
|
|
273
|
+
f.write(binary_data.read())
|
|
274
|
+
break
|
|
275
|
+
else:
|
|
276
|
+
# Fallback: look for any executable
|
|
277
|
+
for member in tar.getmembers():
|
|
278
|
+
if member.isfile():
|
|
279
|
+
binary_data = tar.extractfile(member)
|
|
280
|
+
if binary_data:
|
|
281
|
+
with open(binary_path, "wb") as f:
|
|
282
|
+
f.write(binary_data.read())
|
|
283
|
+
break
|
|
284
|
+
|
|
285
|
+
# Make executable
|
|
286
|
+
if use_sudo:
|
|
287
|
+
import subprocess
|
|
288
|
+
|
|
289
|
+
subprocess.run(["chmod", "+x", str(binary_path)], check=True)
|
|
290
|
+
if str(binary_path).startswith("/usr/local/bin") or str(
|
|
291
|
+
binary_path
|
|
292
|
+
).startswith("/usr/bin"):
|
|
293
|
+
subprocess.run(
|
|
294
|
+
["sudo", "chmod", "+x", str(binary_path)], check=True
|
|
295
|
+
)
|
|
296
|
+
else:
|
|
297
|
+
os.chmod(binary_path, 0o755)
|
|
298
|
+
|
|
299
|
+
# Verify installation
|
|
300
|
+
installed_version = get_fastweb_version()
|
|
301
|
+
print(f"✓ FastWeb {installed_version} installed to: {binary_path}")
|
|
302
|
+
|
|
303
|
+
if not use_sudo:
|
|
304
|
+
# Add to PATH instructions
|
|
305
|
+
rc_file = Path.home() / (
|
|
306
|
+
".bashrc"
|
|
307
|
+
if os.environ.get("SHELL", "").endswith("bash")
|
|
308
|
+
else ".zshrc"
|
|
309
|
+
)
|
|
310
|
+
path_line = f'export PATH="{install_dir}:$PATH"'
|
|
311
|
+
if rc_file.exists():
|
|
312
|
+
content = rc_file.read_text()
|
|
313
|
+
if path_line not in content:
|
|
314
|
+
print(f"\nTo use FastWeb, add this to your {rc_file.name}:")
|
|
315
|
+
print(f" {path_line}")
|
|
316
|
+
else:
|
|
317
|
+
print(
|
|
318
|
+
f"\nTo use FastWeb, add this to your shell rc file (~/.bashrc or ~/.zshrc):"
|
|
319
|
+
)
|
|
320
|
+
print(f" {path_line}")
|
|
321
|
+
|
|
322
|
+
finally:
|
|
323
|
+
try:
|
|
324
|
+
os.unlink(tmp_tar_path)
|
|
325
|
+
except:
|
|
326
|
+
pass
|
|
327
|
+
|
|
328
|
+
except Exception as e:
|
|
329
|
+
print(f"Error installing FastWeb: {e}")
|
|
330
|
+
sys.exit(1)
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
if __name__ == "__main__":
|
|
334
|
+
# Allow running as module: python -m fastweb install
|
|
335
|
+
if len(sys.argv) > 1 and sys.argv[1] == "install":
|
|
336
|
+
install_command()
|
|
337
|
+
else:
|
|
338
|
+
print("FastWeb Python SDK")
|
|
339
|
+
print("Usage: python -m fastweb install")
|
|
340
|
+
print(" (to install the FastWeb binary)")
|
|
341
|
+
print("")
|
|
342
|
+
print("Once installed, use in your code:")
|
|
343
|
+
print(" from fastweb import BrowserMode, AgentBrowser")
|
|
344
|
+
print(" browser = AgentBrowser(mode=BrowserMode.LIGHT)")
|
fastweb/errors.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""
|
|
2
|
+
FastWeb SDK Exceptions
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BinaryNotFoundError(RuntimeError):
|
|
7
|
+
"""Raised when FastWeb binary is not found."""
|
|
8
|
+
|
|
9
|
+
def __init__(self):
|
|
10
|
+
super().__init__(
|
|
11
|
+
"FastWeb binary not found. Please install it first:\n"
|
|
12
|
+
" python -m fastweb install\n"
|
|
13
|
+
"Or manually:\n"
|
|
14
|
+
" curl -sL https://fastweb.b4n1.com/install | bash"
|
|
15
|
+
)
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastweb-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for FastWeb Agentic Browser Engine - Requires explicit binary installation
|
|
5
|
+
Author-email: Bani Montoya <banimontoya@gmail.com>
|
|
6
|
+
License-Expression: MIT OR Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/B4N1-com/fastweb
|
|
8
|
+
Project-URL: Repository, https://github.com/B4N1-com/fastweb
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: requests>=2.28.0
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# FastWeb Python SDK
|
|
25
|
+
|
|
26
|
+
Python bindings for FastWeb: The Agentic Browser Engine.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
### 1. Install the Python SDK
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install fastweb-sdk
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Install the FastWeb Binary (Required)
|
|
37
|
+
|
|
38
|
+
The SDK requires the FastWeb Rust binary to function. Install it explicitly:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
python -m fastweb install
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Or manually:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
curl -sL https://fastweb.b4n1.com/install | bash
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Quick Start
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from fastweb import BrowserMode, AgentBrowser
|
|
54
|
+
|
|
55
|
+
# Create a browser instance
|
|
56
|
+
browser = AgentBrowser(mode=BrowserMode.LIGHT)
|
|
57
|
+
|
|
58
|
+
# Navigate to a page
|
|
59
|
+
page = browser.goto("https://example.com")
|
|
60
|
+
|
|
61
|
+
# Access structured data
|
|
62
|
+
print("Page content:")
|
|
63
|
+
print(page.markdown)
|
|
64
|
+
|
|
65
|
+
print(f"Found {len(page.links)} links")
|
|
66
|
+
print("First 5 links:", page.links[:5])
|
|
67
|
+
|
|
68
|
+
# Extract main content
|
|
69
|
+
main_content = page.get_main_content()
|
|
70
|
+
print("Main content preview:", main_content[:200] + "...")
|
|
71
|
+
|
|
72
|
+
# Find specific links
|
|
73
|
+
github_links = page.find_links_by_text("github")
|
|
74
|
+
print("GitHub links:", github_links)
|
|
75
|
+
|
|
76
|
+
# Close browser when done
|
|
77
|
+
browser.close()
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Browser Modes
|
|
81
|
+
|
|
82
|
+
### Light Mode (Default)
|
|
83
|
+
|
|
84
|
+
- **Use case**: Reading articles, scraping static content, extracting links
|
|
85
|
+
- **Performance**: < 15MB RAM, instant startup
|
|
86
|
+
- **Capabilities**: HTML parsing, markdown conversion, link extraction
|
|
87
|
+
- **Limitations**: No JavaScript execution
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
browser = AgentBrowser(mode=BrowserMode.LIGHT)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Render Mode
|
|
94
|
+
|
|
95
|
+
- **Use case**: SPAs, form filling, visual verification
|
|
96
|
+
- **Performance**: Higher memory usage, slower startup
|
|
97
|
+
- **Capabilities**: Full JavaScript execution, screenshots, interaction
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
browser = AgentBrowser(mode=BrowserMode.RENDER)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## API Reference
|
|
104
|
+
|
|
105
|
+
### AgentBrowser
|
|
106
|
+
|
|
107
|
+
Main browser class for web automation.
|
|
108
|
+
|
|
109
|
+
#### Methods
|
|
110
|
+
|
|
111
|
+
- `goto(url: str) -> Page`: Navigate to URL and return structured page data
|
|
112
|
+
- `close()`: Close the browser session
|
|
113
|
+
|
|
114
|
+
#### Parameters
|
|
115
|
+
|
|
116
|
+
- `mode`: BrowserMode.LIGHT or BrowserMode.RENDER
|
|
117
|
+
- `timeout`: Request timeout in seconds (default: 30)
|
|
118
|
+
- `user_agent`: Custom user agent string
|
|
119
|
+
|
|
120
|
+
### Page
|
|
121
|
+
|
|
122
|
+
Structured data from a web page.
|
|
123
|
+
|
|
124
|
+
#### Attributes
|
|
125
|
+
|
|
126
|
+
- `url: str`: The page URL
|
|
127
|
+
- `markdown: str`: Clean markdown content
|
|
128
|
+
- `links: List[str]`: Extracted links
|
|
129
|
+
- `screenshot: Optional[str]`: Base64-encoded screenshot (render mode only)
|
|
130
|
+
|
|
131
|
+
#### Methods
|
|
132
|
+
|
|
133
|
+
- `get_main_content() -> str`: Extract main content, skipping headers/footers
|
|
134
|
+
- `find_links_by_text(text: str) -> List[str]`: Find links containing specific text
|
|
135
|
+
|
|
136
|
+
## Context Manager
|
|
137
|
+
|
|
138
|
+
Use `BrowserSession` for automatic cleanup:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from fastweb import BrowserSession, BrowserMode
|
|
142
|
+
|
|
143
|
+
with BrowserSession(mode=BrowserMode.LIGHT) as browser:
|
|
144
|
+
page = browser.goto("https://example.com")
|
|
145
|
+
print(page.markdown)
|
|
146
|
+
# Browser automatically closed
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Development
|
|
150
|
+
|
|
151
|
+
### Building
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Build Rust engine
|
|
155
|
+
cd fastweb-engine/cli-core
|
|
156
|
+
cargo build --release
|
|
157
|
+
|
|
158
|
+
# Build Python SDK
|
|
159
|
+
cd sdk-python
|
|
160
|
+
python -m build
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Testing
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# Run Rust tests
|
|
167
|
+
cd fastweb-engine/cli-core
|
|
168
|
+
cargo test
|
|
169
|
+
|
|
170
|
+
# Run Python tests
|
|
171
|
+
cd sdk-python
|
|
172
|
+
python -m pytest
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Security
|
|
176
|
+
|
|
177
|
+
- All HTTP requests use TLS
|
|
178
|
+
- No arbitrary code execution
|
|
179
|
+
- Input validation and sanitization
|
|
180
|
+
- **Explicit Installation**: Binary must be installed via `python -m fastweb install` - no automatic downloads
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
MIT OR Apache-2.0
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
fastweb/__init__.py,sha256=n0-VFqpZLz_b9u4rV7xGQzqQ05wcyhGeB15P5XFPHrA,504
|
|
2
|
+
fastweb/__main__.py,sha256=HvFgDjgyPLJmh90yf1Gzt9Gj82L1gjlRJBbocoCRyto,4991
|
|
3
|
+
fastweb/browser.py,sha256=wytT0yQrNm47N6vSNKLVKgHEWKOFGWMDZ6jaSeQ4uCs,11188
|
|
4
|
+
fastweb/errors.py,sha256=4GAX8KXbTIr7XS4CVBJ5EaKsP_w2xxTYvuxize1TBjA,391
|
|
5
|
+
fastweb_sdk-0.1.0.dist-info/licenses/LICENSE,sha256=qLamYHg6Dlg-8bg7A-_j35qfg5YWpSP-P_FQ8NsiUFg,1068
|
|
6
|
+
fastweb_sdk-0.1.0.dist-info/METADATA,sha256=hVIideqy012oiijU9E9RcOjxp3wpp1k-TuoVWaER48k,4229
|
|
7
|
+
fastweb_sdk-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
8
|
+
fastweb_sdk-0.1.0.dist-info/entry_points.txt,sha256=H-srTWKX73J2aZNnAHvAUhNRN5fH9mQzlbm7sWOPtMo,61
|
|
9
|
+
fastweb_sdk-0.1.0.dist-info/top_level.txt,sha256=V-r157KWpldmRCXUQCAgzKVkcXvGZQ2WVwgs7xsYylw,8
|
|
10
|
+
fastweb_sdk-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Bani Montoya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fastweb
|