Skip to content

Python examples

Response.text is the original HTTP response text. Response.html is the live DOM serialized after scripts execute.

import brimp
response = brimp.get("https://example.com")
response.raise_for_status()
print("original bytes:", len(response.content))
print("rendered HTML:", response.html)

For JSON responses, use the familiar json() helper:

data = brimp.get("https://api.example.com/status").json()
print(data)
import brimp
with brimp.Session() as session:
session.headers["X-Client"] = "brimp-example"
response = session.get(
"https://example.com/search",
params={"q": "headless browser", "tag": ["agents", "javascript"]},
headers={"X-Request-ID": "example-1"},
)
print(response.url)

User-Agent and Accept-Language belong to the browser persona and cannot be overridden as arbitrary request headers.

import brimp
with brimp.Session() as session:
session.cookies["experiment"] = "rendered"
session.get("https://example.com/first")
second = session.get("https://example.com/second")
print(session.cookies)
print(second.cookies)
from pathlib import Path
import brimp
with brimp.Session() as session:
session.get("https://example.com")
summary = session.evaluate("""
({
title: document.title,
links: document.querySelectorAll('a').length,
text: document.body.textContent.trim()
})
""")
png = session.screenshot(full_page=True)
print(summary)
Path("example.png").write_bytes(png)

Evaluation results must be JSON-compatible.

from pathlib import Path
import brimp
persona_json = Path("persona/example.json").read_text()
with brimp.Session(persona_json=persona_json) as session:
session.get("https://example.com")
print(session.evaluate("navigator.userAgent"))

See the Python API for the complete public surface.