Skip to main content

Python SDK for the Rendershot screenshot & PDF generation API

Project description

rendershot-python

CI PyPI License: MIT

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',
)

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

rendershot-0.1.8.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

rendershot-0.1.8-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file rendershot-0.1.8.tar.gz.

File metadata

  • Download URL: rendershot-0.1.8.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rendershot-0.1.8.tar.gz
Algorithm Hash digest
SHA256 8f1c1eac80e3e172c9f273940edb1b27349c3446abbf5b0c90bae03dc9e2f862
MD5 3c7ac8c12db7f61d6102f45fb3c0e6b3
BLAKE2b-256 ded62341d54bf9d89421e86603bce6d7de73ad67497dccb775a455a3a34e649a

See more details on using hashes here.

File details

Details for the file rendershot-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: rendershot-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rendershot-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 53c65c80e12c16c09e2578bb3775f0be1377ffb5086f0e638c333449c161bedd
MD5 7d33edc474c10e1a736cfc060dac2668
BLAKE2b-256 7a3f91ed1165b6a93d5e5d11b4e84ff346298714f1beb3538eb037baea9d69f1

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