Skip to main content

Official Python SDK for Rendex — capture screenshots, generate PDFs, and render HTML to images

Project description

rendex

Official Python SDK for Rendex — the screenshot, PDF, and HTML rendering API. Capture any webpage or raw HTML as an image or PDF with a single function call.

  • Full type hints (PEP 561 compatible)
  • Single dependency (httpx)
  • Sync API with context manager support
  • Typed error handling with API error codes

Install

pip install rendex

Quick Start

from pathlib import Path
from rendex import Rendex

rendex = Rendex("your-api-key")

# Render raw HTML straight to a PNG
result = rendex.render_html("<h1>Hello, world</h1>")
Path("hello.png").write_bytes(result.image)

# Or capture a live URL
shot = rendex.screenshot("https://example.com", format="png", full_page=True)
Path("screenshot.png").write_bytes(shot.image)

print(f"{result.metadata.bytes_size} bytes, loaded in {result.metadata.load_time_ms}ms")

API Reference

Rendex(api_key, *, base_url="https://api.rendex.dev")

Create a new Rendex client.

rendex = Rendex("your-api-key")

# Or with context manager for connection reuse
with Rendex("your-api-key") as rendex:
    result = rendex.screenshot("https://example.com")

rendex.screenshot(url, **options)

Capture a screenshot and return the binary image with metadata.

result = rendex.screenshot(
    "https://example.com",
    format="webp",
    width=1920,
    height=1080,
    dark_mode=True,
)
Path("screenshot.webp").write_bytes(result.image)
print(result.metadata.load_time_ms)  # 350

Returns ScreenshotResult:

  • imagebytes of the captured image
  • metadataScreenshotMetadata with url, dimensions, format, bytes_size, load_time_ms, quality, etc.

rendex.render_html(html, **options)

Render raw HTML straight to an image and return the binary result. Convenience wrapper over screenshot(html=...).

result = rendex.render_html("<h1>Hello, world</h1>", format="png", width=1200)
Path("hello.png").write_bytes(result.image)

Returns ScreenshotResult — same shape as screenshot().

You can also pass html directly to screenshot() / screenshot_json():

result = rendex.screenshot(html="<h1>Hello, world</h1>", full_page=True)

HTML rendering is POST-only and accepts up to 5MB. It is not available via screenshot_url() (the GET endpoint can't carry an HTML body). Provide either url or html — not both; the SDK raises RendexError locally if you supply neither or both.

rendex.screenshot_json(url, **options)

Capture a screenshot and return JSON with a base64-encoded image.

result = rendex.screenshot_json("https://example.com")
print(result["data"]["bytesSize"])        # 45823
print(result["meta"]["usage"]["remaining"])  # 499

Returns ScreenshotJsonResponse dict with data (image + metadata) and meta (request ID, usage).

rendex.screenshot_url(url, **options)

Generate a GET URL for embedding. No network call — pure URL builder.

url = rendex.screenshot_url("https://example.com", format="png", width=1200)
# Use in <img> tags, OpenGraph, etc.

Note: The API key is included in the URL. Use server-side only.

Screenshot Options

All options are keyword arguments in snake_case. Only url (positional) is required:

Option Type Default Description
format str "png" "png", "jpeg", "webp", or "pdf"
width int 1280 Viewport width (320–3840)
height int 800 Viewport height (240–2160)
full_page bool False Capture the full scrollable page
quality int 80 JPEG/WebP quality (1–100, default 80)
delay int 0 Delay before capture in ms (0–10000)
dark_mode bool False Emulate dark mode
device_scale_factor float 2 Device pixel ratio (1–3). 2× Retina by default
block_ads bool True Block ads and trackers
block_resource_types list Block: "font", "image", "media", "stylesheet", "other"
timeout int 30 Page load timeout in seconds (5–60)
wait_until str "networkidle2" "load", "domcontentloaded", "networkidle0", "networkidle2"
wait_for_selector str CSS selector to wait for
best_attempt bool True Return best-effort screenshot on timeout
selector str Capture a specific element by CSS selector

Error Handling

from rendex import Rendex, RendexApiError, RendexNetworkError

rendex = Rendex("your-api-key")

try:
    rendex.screenshot("https://example.com")
except RendexApiError as e:
    # API returned an error
    print(e.error_code)   # "RATE_LIMITED", "VALIDATION_ERROR", etc.
    print(e.status_code)  # 429, 400, etc.
    print(e.request_id)   # For debugging with Rendex support
    print(e.details)      # Validation details (if any)
except RendexNetworkError as e:
    # Network failure (DNS, timeout, connection refused)
    print(f"Network error: {e}")

Error Codes

Code HTTP Status Description
VALIDATION_ERROR 400 Invalid request parameters
INVALID_URL 400 URL failed SSRF validation
TIMEOUT 408 Page took too long to load
CAPTURE_FAILED 500 Browser rendering error
RATE_LIMITED 429 Rate limit exceeded
USAGE_EXCEEDED 429 Monthly credit limit reached
MISSING_API_KEY 401 No API key provided
INVALID_API_KEY 401 API key verification failed

License

MIT - Copperline Labs LLC

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

rendex-1.1.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rendex-1.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file rendex-1.1.0.tar.gz.

File metadata

  • Download URL: rendex-1.1.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.12.13 HTTPX/0.28.1

File hashes

Hashes for rendex-1.1.0.tar.gz
Algorithm Hash digest
SHA256 3e88be7beee9b601e6f568c1ab277d42f36d307e133db196f88d0b6f873b074f
MD5 140047ce5b1d0d6e5d88a029623a243d
BLAKE2b-256 265b333c471001e23c02842e126b8d15ac462c0ce78b880be33914ec00a4aad4

See more details on using hashes here.

File details

Details for the file rendex-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: rendex-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.12.13 HTTPX/0.28.1

File hashes

Hashes for rendex-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b313b02c8d10eb7a77f21a684abc71e4c7ce073aeef8cd0f3e20d3726ddb7a88
MD5 a4adfea447e8d51883cbc4fc8cd64b65
BLAKE2b-256 6e6be63eb00031687e1aa65654c0de8cf5b6518ff9af7eabb790aec3e58ea1fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page