Python client for Browser-Use Fetch HTTP service
Project description
fetch-use
Python client for the Browser-Use Fetch HTTP service.
Installation
pip install fetch-use
Quick Start
import asyncio
import os
from fetch_use import fetch
# Set your project ID and session ID
os.environ['PROJECT_ID'] = 'your-project-id'
os.environ['SESSION_ID'] = 'your-session-id'
async def main():
response = await fetch("https://httpbin.org/get")
print(response.status_code) # 200
print(response.json())
asyncio.run(main())
Or use the synchronous API:
from fetch_use import fetch_sync
response = fetch_sync("https://httpbin.org/get")
print(response.status_code)
Features
- Session-based IP persistence: Maintain consistent IP across requests
- Proxy Routing: Route requests through proxies by country
- Automatic Retries: Configurable retry with exponential backoff
Configuration
Set these environment variables:
| Variable | Required | Description |
|---|---|---|
PROJECT_ID |
Yes | Your Browser-Use project ID |
SESSION_ID |
Yes | Session ID for IP persistence |
Note: Cookies are persisted server-side per session. Pass cookies via the cookies parameter to add or override cookies for a specific request.
Usage
Basic GET Request
async def example():
response = await fetch("https://example.com")
if response.ok:
print(response.text)
POST with JSON
async def post_example():
response = await fetch(
"https://api.example.com/data",
method="POST",
json_body={"name": "John", "email": "john@example.com"},
)
return response.json()
Custom Headers and Cookies
async def headers_example():
response = await fetch(
"https://example.com/api",
headers={
"Authorization": "Bearer token123",
"Accept": "application/json",
},
cookies={
"session": "abc123",
"preferences": "dark_mode",
},
)
return response
Proxy Country
async def proxy_example():
# Route through German proxy
response = await fetch(
"https://example.com",
proxy_country="DE",
)
return response
Retry Configuration
from fetch_use import fetch, RetryConfig
async def retry_example():
response = await fetch(
"https://example.com",
retry=RetryConfig(
count=5,
on_status=[500, 502, 503, 504, 429],
backoff_ms=200,
),
)
return response
Cookies
Cookies are persisted server-side per session. Use the cookies parameter to add or override cookies:
async def cookies_example(params):
# Pass cookies to add/override for this request
response = await fetch(
"https://example.com/dashboard",
cookies={"session": params["session_cookie"]},
)
return response
Response Object
The FetchResponse object provides:
| Property | Type | Description |
|---|---|---|
status_code |
int |
HTTP status code |
status |
str |
Full status string (e.g., "200 OK") |
headers |
dict |
Response headers |
body |
str |
Response body as text |
text |
str |
Alias for body |
content |
bytes |
Response body as bytes (handles binary) |
ok |
bool |
True if status is 2xx |
final_url |
str |
Final URL after redirects |
redirect_count |
int |
Number of redirects followed |
protocol |
str |
HTTP protocol (e.g., "HTTP/2.0") |
Methods:
json()- Parse body as JSONraise_for_status()- RaiseFetchErrorif status >= 400
Error Handling
from fetch_use import fetch, FetchError
async def error_handling_example():
try:
response = await fetch("https://example.com")
response.raise_for_status() # Raises FetchError on 4xx/5xx
return response.json()
except FetchError as e:
print(f"Error: {e}")
print(f"Code: {e.code}")
print(f"Details: {e.details}")
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fetch_use-0.1.0.tar.gz.
File metadata
- Download URL: fetch_use-0.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
120763297cf50544514b704372d0b377dd21ddfca3be2d8443da5a24099e1cde
|
|
| MD5 |
f51b6104bbd7bc0d14f7d20070f7ce7d
|
|
| BLAKE2b-256 |
a9f7c264da35f1081ea625fd6a84044b3f98a333d8442d2e74ec32a8e708eb2a
|
File details
Details for the file fetch_use-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fetch_use-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e774cb6027749619c51948e9faff86afbfed03795ff80f2e9ca837a14280674
|
|
| MD5 |
c6b67cede497d491a647c37174006d2e
|
|
| BLAKE2b-256 |
2a88e86ff84cb69f1962d3e0c8580058f785eb6eaa2a82c9c98a79a3ed06b038
|