Official Python SDK for ScreenshotSage - Capture high-quality screenshots of any website
Project description
ScreenshotSage Python SDK
Official Python SDK for ScreenshotSage - Capture high-quality screenshots of any website.
Installation
pip install screenshotsage
Quick Start
from screenshotsage import ScreenshotSage
# Initialize the client
client = ScreenshotSage(api_key="your-api-key")
# Basic screenshot
result = client.capture(url="https://example.com")
print(result["data"]["downloadUrl"])
# Mobile screenshot
result = client.capture(
url="https://example.com",
devicePreset="mobile",
format="webp",
quality=85
)
# Full page screenshot
result = client.capture(
url="https://example.com",
fullPage=True,
format="png"
)
# Download the screenshot
image_bytes = client.download(result["data"]["downloadUrl"])
with open("screenshot.png", "wb") as f:
f.write(image_bytes)
# Or capture and download in one step
image_bytes = client.capture_and_download(url="https://example.com")
Async Usage
import asyncio
from screenshotsage import ScreenshotSage
async def main():
async with ScreenshotSage(api_key="your-api-key") as client:
result = await client.capture_async(url="https://example.com")
print(result["data"]["downloadUrl"])
# Download
image_bytes = await client.download_async(result["data"]["downloadUrl"])
asyncio.run(main())
Features
Device Presets
# Desktop (default: 1200x800)
client.capture(url="https://example.com", devicePreset="desktop")
# Tablet (768x1024)
client.capture(url="https://example.com", devicePreset="tablet")
# Mobile (375x667, iPhone user agent)
client.capture(url="https://example.com", devicePreset="mobile")
Output Formats
# PNG (default)
client.capture(url="https://example.com", format="png")
# JPEG with quality
client.capture(url="https://example.com", format="jpeg", quality=90)
# WebP
client.capture(url="https://example.com", format="webp", quality=85)
# PDF (Professional+ plans)
client.capture(url="https://example.com", format="pdf")
# HTML snapshot
client.capture(url="https://example.com", format="html")
Clean Screenshots
# Remove ads, cookie banners, and chat widgets
client.capture(
url="https://example.com",
blockAds=True,
blockCookieBanners=True,
blockChatWidgets=True
)
# Hide specific elements
client.capture(
url="https://example.com",
hideSelectors=[".popup", "#newsletter-modal", ".sticky-footer"]
)
Geolocation & Timezone
client.capture(
url="https://maps.google.com",
geolocation={
"latitude": 40.7128,
"longitude": -74.0060,
"accuracy": 100
},
timezone="America/New_York",
language="en-US"
)
Authentication
# HTTP Basic Auth
client.capture(
url="https://example.com/admin",
basicAuth={
"username": "admin",
"password": "secret"
}
)
# Session cookies
client.capture(
url="https://example.com/dashboard",
cookies=[
{
"name": "session_id",
"value": "abc123xyz",
"httpOnly": True,
"secure": True
}
]
)
Custom CSS/JavaScript
# Inject custom styles and scripts (Professional+ plans)
client.capture(
url="https://example.com",
customCss="body { background: #f0f0f0 !important; }",
customJs="document.querySelector('.popup')?.remove();"
)
Clip Region
# Capture a specific region
client.capture(
url="https://example.com",
clip={
"x": 0,
"y": 0,
"width": 800,
"height": 600
}
)
Error Handling
from screenshotsage import ScreenshotSage, ScreenshotSageError
client = ScreenshotSage(api_key="your-api-key")
try:
result = client.capture(url="https://example.com")
except ScreenshotSageError as e:
print(f"Error: {e}")
print(f"Status code: {e.status_code}")
print(f"Response: {e.response}")
Configuration
client = ScreenshotSage(
api_key="your-api-key",
base_url="https://screenshotsage.com", # Custom base URL
timeout=120.0 # Request timeout in seconds
)
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
screenshotsage-1.0.0.tar.gz
(5.1 kB
view details)
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 screenshotsage-1.0.0.tar.gz.
File metadata
- Download URL: screenshotsage-1.0.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68a69764efb7556784669dcc9349bcd035c538e50bc002fc3532ea772f2de06c
|
|
| MD5 |
86511449fae793675f801eb8e9b88afa
|
|
| BLAKE2b-256 |
51b131fc4b9baecf13b637991624f78b91eba34d1c033d84861e6a47e0d28359
|
File details
Details for the file screenshotsage-1.0.0-py3-none-any.whl.
File metadata
- Download URL: screenshotsage-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a3d02e3b7a32cf937190b07cd0d545837f1ce107a49950d40c68be1203a49f5
|
|
| MD5 |
b270511b0c5c490017dfdb03d15a70d7
|
|
| BLAKE2b-256 |
37cad71e6a2c4038406b9c66f95be386d59948c483c0a899f18041190284532f
|