Python SDK for the Rendershot screenshot & PDF generation API
Project description
rendershot-python
Python SDK for the Rendershot screenshot & PDF generation API.
Installation
pip install rendershot
Quick start
import rendershot
# Sync client
client = rendershot.RenderShotClient(api_key='your-api-key')
# Capture a screenshot
png_bytes = client.screenshot_url('https://example.com')
# Save directly to a file
client.screenshot_url_to_file('https://example.com', 'screenshot.png')
# Render a PDF
pdf_bytes = client.pdf_url('https://example.com')
client.pdf_html_to_file('<h1>Hello</h1>', 'output.pdf')
# Check your balance
balance = client.get_balance()
print(balance.credits_remaining)
Async client
import asyncio
import rendershot
async def main():
async with rendershot.AsyncRenderShotClient(api_key='your-api-key') as client:
png = await client.screenshot_url('https://example.com')
await client.pdf_url_to_file('https://example.com', 'report.pdf')
asyncio.run(main())
Bulk rendering
All bulk methods submit jobs via the /v1/bulk endpoint, poll until complete, and save results to a folder.
# Bulk screenshots from URLs
paths = client.bulk_screenshot_urls(
['https://example.com', 'https://github.com'],
output_dir='/tmp/screenshots',
)
# Bulk PDFs from an HTML Jinja2 template (great for invoices)
template = '''
<html><body>
<h1>Invoice #{{ invoice_id }}</h1>
<p>Amount: ${{ amount }}</p>
</body></html>
'''
paths = client.bulk_pdf_from_template(
template,
contexts=[
{'invoice_id': 1001, 'amount': '99.00'},
{'invoice_id': 1002, 'amount': '149.00'},
],
output_dir='/tmp/invoices',
)
AI cleanup (remove cookie banners & popups)
Pass ai_cleanup to have the backend strip common cookie banners, consent overlays, and popup modals before the render. Two modes:
AICleanupMode.fast— JS heuristics (1 credit, same as a plain render).AICleanupMode.thorough— adds a Claude LLM pass that snapshots the DOM and identifies remaining overlays (3 credits; backend must have an Anthropic key configured).
png = client.screenshot_url(
'https://example.com',
ai_cleanup=rendershot.models.AICleanupMode.fast,
)
pdf = client.pdf_url(
'https://example.com',
ai_cleanup=rendershot.models.AICleanupMode.thorough,
)
Works on all single and bulk methods on both the sync and async clients.
Handling network_idle timeouts
Some URLs never reach network_idle (e.g. sites with persistent WebSocket connections or infinite polling). Use timeout_fallback_to='dom_content_loaded' to automatically retry with wait_for='dom_content_loaded' when a timeout occurs:
# Single URL — retries automatically on timeout
png = client.screenshot_url(
'https://example.com',
wait_for='network_idle',
timeout_fallback_to='dom_content_loaded',
)
# Save to file
client.screenshot_url_to_file(
'https://example.com',
'sport5.png',
wait_for='network_idle',
timeout_fallback_to='dom_content_loaded',
)
# Bulk — each timed-out job is individually retried
paths = client.bulk_screenshot_urls(
urls=['https://example.com', 'https://example2.com'],
output_dir='./screenshots',
wait_for='network_idle',
timeout_fallback_to='dom_content_loaded',
)
Configuration
| Parameter | Default | Description |
|---|---|---|
api_key |
required | Your Rendershot API key |
base_url |
https://api.rendershot.io |
API base URL |
Bulk methods also accept poll_interval (seconds, default 2.0) and timeout (seconds, default 300.0).
Error handling
from rendershot import exceptions
try:
client.screenshot_url('https://example.com')
except exceptions.AuthenticationError:
print('Invalid API key')
except exceptions.RateLimitError as e:
print(f'Rate limited, retry after {e.retry_after}s')
except exceptions.JobFailedError as e:
print(f'Job {e.job_id} failed')
except exceptions.APIError as e:
print(f'API error {e.status_code}: {e.detail}')
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
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 rendershot-0.1.9.tar.gz.
File metadata
- Download URL: rendershot-0.1.9.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73b8a56b9a253e91fd52e05ffe9e962035bd2efcd2277a658afdaa4f2d5fad73
|
|
| MD5 |
19fc1e41f4d7d6a6cfd66afebe5600d5
|
|
| BLAKE2b-256 |
56ace588ea50361fd9995c9a14d9a854666966c1226ee6ca283c27393c30fdc3
|
File details
Details for the file rendershot-0.1.9-py3-none-any.whl.
File metadata
- Download URL: rendershot-0.1.9-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b205ba03e50d80d6e665c6c91108bb91d611b4a21f69a1362462c68cea560784
|
|
| MD5 |
8cf3d9bd4ed15cf15b1b998689bf77c4
|
|
| BLAKE2b-256 |
ac499aa7bf43fbbe18b34d55323eed053e73a3642b385b72946ff974516524c2
|