Web fetch — API reference¶
FetchError
¶
Bases: Exception
Raised when a fetch fails.
FetchResult
dataclass
¶
convert_content
¶
convert_content(
body: bytes,
content_type: str,
charset: str,
*,
max_chars: int = DEFAULT_MAX_CHARS,
) -> str
Convert fetched content to a text representation suitable for an LLM.
| PARAMETER | DESCRIPTION |
|---|---|
body
|
Raw response bytes.
TYPE:
|
content_type
|
MIME type (e.g. "text/html").
TYPE:
|
charset
|
Character encoding (e.g. "utf-8").
TYPE:
|
max_chars
|
Maximum output length in characters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Converted text content, truncated if necessary. |
fetch_url
¶
fetch_url(
url: str,
*,
timeout: int = DEFAULT_TIMEOUT,
max_size: int = DEFAULT_MAX_SIZE,
allow_private: bool = False,
) -> FetchResult
Fetch a URL and return the response content.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
The URL to fetch.
TYPE:
|
timeout
|
Request timeout in seconds.
TYPE:
|
max_size
|
Maximum response body in bytes.
TYPE:
|
allow_private
|
If True, allow fetching private/loopback IPs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FetchResult
|
FetchResult with the response data. |
| RAISES | DESCRIPTION |
|---|---|
FetchError
|
If the fetch fails for any reason. |