Skip to main content

Python wrapper for the Screenshot & PDF API — capture screenshots, generate PDFs, extract metadata, and render HTML to images.

Project description

Screenshot & PDF API

Python wrapper for the Screenshot & PDF API on RapidAPI.

Capture screenshots, generate PDFs, extract page metadata, and render HTML/CSS to images — all from a single, zero-dependency package.

PyPI version Python 3.8+ License: MIT

Installation

pip install screenshot-pdf-api

Quick Start

from screenshot_pdf_api import ScreenshotAPI

api = ScreenshotAPI("your-rapidapi-key")

# Check API status
print(api.health())

# Take a screenshot
png = api.screenshot("https://example.com")
with open("example.png", "wb") as f:
    f.write(png)

Get Your API Key

  1. Go to RapidAPI - Screenshot & PDF API
  2. Subscribe to a plan (free tier available)
  3. Copy your X-RapidAPI-Key from the dashboard

Endpoints

Free Tier

api = ScreenshotAPI("your-key")

# Screenshot any URL → PNG, JPEG, or WebP
png = api.screenshot("https://example.com")

# Full-page screenshot with custom viewport
img = api.screenshot(
    "https://example.com",
    width=1920,
    height=1080,
    full_page=True,
    format="jpeg",
    quality=90,
)

# Screenshot a specific element
element = api.screenshot(
    "https://example.com",
    selector="#main-content",
)

# Wait for dynamic content before capture
img = api.screenshot(
    "https://example.com",
    delay=2000,  # wait 2 seconds
)

Basic Tier

# Generate a PDF from any URL
pdf = api.pdf("https://example.com")
with open("page.pdf", "wb") as f:
    f.write(pdf)

# PDF with custom options
pdf = api.pdf(
    "https://example.com",
    format="Letter",
    landscape=True,
    print_background=True,
    margin="narrow",
)

# Extract page metadata (title, OG tags, favicon, etc.)
meta = api.metadata("https://example.com")
print(meta["title"])
print(meta["og"])
print(meta["favicon"])

Pro Tier

# Render HTML/CSS to image
html = """
<html>
<body style="background: linear-gradient(135deg, #667eea, #764ba2);
             color: white; font-family: Arial; padding: 40px;">
  <h1>Hello World</h1>
  <p>Rendered from raw HTML</p>
</body>
</html>
"""
img = api.screenshot_html(html, width=800, height=600)
with open("rendered.png", "wb") as f:
    f.write(img)

Error Handling

The library raises specific exceptions for different error types:

from screenshot_pdf_api import (
    ScreenshotAPI,
    ScreenshotAuthError,
    ScreenshotForbiddenError,
    ScreenshotRateLimitError,
    ScreenshotAPIError,
)

api = ScreenshotAPI("your-key")

try:
    img = api.screenshot_html("<h1>Pro feature</h1>")
except ScreenshotAuthError:
    print("Invalid API key")
except ScreenshotForbiddenError:
    print("Upgrade your plan for this endpoint")
except ScreenshotRateLimitError:
    print("Rate limited — slow down or upgrade")
except ScreenshotAPIError as e:
    print(f"API error [{e.status_code}]: {e.message}")
Exception HTTP Code Meaning
ScreenshotAuthError 401 Invalid or missing API key
ScreenshotForbiddenError 403 Endpoint not in your tier
ScreenshotNotFoundError 404 Resource not found
ScreenshotRateLimitError 429 Rate limit exceeded
ScreenshotServerError 5xx Server-side error
ScreenshotAPIError any Base class for all errors

Configuration

api = ScreenshotAPI(
    api_key="your-key",
    timeout=60,       # request timeout in seconds (default: 30)
)

Requirements

  • Python 3.8+
  • Zero dependencies — uses only urllib.request from the standard library

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

screenshot_pdf_api-1.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

screenshot_pdf_api-1.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: screenshot_pdf_api-1.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for screenshot_pdf_api-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6dfc442feb60f8eacf89c403e8d5d806b7d0b19b2ecebca47c371689fe60922e
MD5 efb5fab60d82e4b1ea69e19d6b4f6ff4
BLAKE2b-256 dd90b6eac0fad62be01a4231f34280085627c8df39bcb54dc5a88e489a693afe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for screenshot_pdf_api-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1a8987a75ad2b6a18b9364f05ae23a161b2d2230bb962d3ca62e589d741280c
MD5 5294f40eeaa3d550dec01d0b6c6c3c57
BLAKE2b-256 c3b7da5d63d6a6bcae6b5e32e59db8550899c1740bf6ce402251be96b663277a

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