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.
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
- Go to RapidAPI - Screenshot & PDF API
- Subscribe to a plan (free tier available)
- Copy your
X-RapidAPI-Keyfrom 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.requestfrom the standard library
License
MIT
Project details
Release history Release notifications | RSS feed
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 screenshot_pdf_api-1.0.0.tar.gz.
File metadata
- Download URL: screenshot_pdf_api-1.0.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1634a93d0cb8c85b4677bc6b4c2345351c62f906000b8ff3c67e8903f5d4b10
|
|
| MD5 |
a58ec90a81d3bb19e6070861722baccb
|
|
| BLAKE2b-256 |
ea7cd9bee75d90e5ccf97f226cf50867e27d70ced803e88a864fe016b4abf556
|
File details
Details for the file screenshot_pdf_api-1.0.0-py3-none-any.whl.
File metadata
- Download URL: screenshot_pdf_api-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
988c653173e23f6b5d94d497c307a30a56ca90ea87ded94dfacedb94eb6f5aff
|
|
| MD5 |
c97ee982ab244017af73e6231fe43876
|
|
| BLAKE2b-256 |
30f7deddc45bad28114ad860beee5cc145adb365be4ed47ff0af3bafb235f459
|