Metadata-Version: 2.4
Name: Browshot
Version: 2.0.0
Summary: Client to interact with Browshot
Home-page: https://github.com/juliensobrier/browshot-python
Author: Julien Sobrier
Author-email: julien@sobrier.net
License: Apache-2.0
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.9
Description-Content-Type: text/plain
Requires-Dist: requests
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

Browshot version 2.0.0
================================

Browshot captures web pages as screenshots, PDFs, and videos. The Python client supports both API v1 and v2.

Install from PyPI with python3 -m pip install Browshot. Install from this checkout with python3 -m pip install .

Python 3.9 or newer is required. pip installs the requests dependency.

API 2.0

    from browshot import BrowshotClient
    import os

    client = BrowshotClient(os.environ['BROWSHOT_API_KEY'])
    capture = client.screenshot_create('https://example.com/', {
        'browser': 'brave',
        'country': 'fr',
        'screen_width': 1280,
        'screen_height': 720,
    })

Existing options such as instance_id, details, priority, hosting, and hooks
select v1. Use browser, country, and a device or viewport dimensions for v2.
An explicit API base URL sets the client default. Pass api_version in a
request's parameters to select a specific version.

screenshot_info and thumbnail downloads prefer v2 and accept IDs created
through either version. Set details or api_version=1 when you need the v1
screenshot metadata. The browser catalog and numeric browser IDs use v1 by
default to retain the legacy catalog fields. Use browser_info('brave') or
browser_list({'api_version': 2}) to look up the v2 browsers.

Use device_list to find device keys, tag_list to list your capture tags, and
batch_download to retrieve the ZIP bytes for a finished batch. app_create and
the other app methods manage v2 delivery destinations. Use simple or
simple_file for a synchronous screenshot.

API v1 reference
https://browshot.com/api/documentation/

API v2 reference
https://browshot.com/api/documentation-v2/

Source
https://github.com/juliensobrier/browshot-python

Tests

    python3 -m unittest discover -s tests -p '*_test.py'

Set BROWSHOT_API_KEY to enable live checks with your account. Set
BROWSHOT_SCREENSHOT_ID to a finished capture and BROWSHOT_RETINA_ID to a
finished capture with retina and ad blocking. For artifact checks, set
BROWSHOT_PDF_ID, BROWSHOT_WEBM_ID, BROWSHOT_MP4_ID, and BROWSHOT_GIF_ID to
owned, finished captures of each format.

API 1.32

    from browshot import BrowshotClient
    import os

    client = BrowshotClient(os.environ['BROWSHOT_API_KEY'])
    capture = client.screenshot_create('https://example.com/', {
        'instance_id': 373,
        'pdf': 1,
        'pdf_format': 'a4',
        'pdf_margin': '10mm',
        'device_scale': 2,
        'hide_ads': 1,
    })

Poll screenshot_info(capture['id']) until status is 'finished'. Download with
screenshot_pdf(capture['id']) or save with
screenshot_pdf_file(capture['id'], 'example.pdf').

PDF settings include pdf_format (letter, a4, or legal), pdf_background,
pdf_landscape, pdf_one_page, pdf_margin, and the per-side pdf_margin_top,
pdf_margin_bottom, pdf_margin_left, and pdf_margin_right.

Request a short video or animated GIF with the same capture method.

    recording = client.screenshot_create('https://example.com/', {
        'instance_id': 373,
        'video': 1,
        'video_format': 'gif',
        'video_duration': 5,
        'video_scale': 0.5,
    })

After the capture finishes, use screenshot_video(recording['id']) to get the
bytes or screenshot_video_file(recording['id'], 'example.gif') to save them.
Accepted formats are webm (default), mp4, and gif. Set video_duration to 1–30
seconds, video_quality to 0–63, video_fps to 1–30, and video_scale to 0.1–1.
GIF uses 20 fps. An MP4 request can produce WebM where MP4 encoding is unavailable.

The download methods return bytes or b'' on failure. File helpers use the
supplied path in an existing directory and return that path, or '' on failure.
Downloads preserve the returned bytes.

Choose a capture country through instance_id. The IDs below are in order
Chrome, Firefox, iPhone 12, and Samsung S20.

    France          373  374  375  376
    India           377  378  379  380
    Finland         381  382  383  384
    United Kingdom  385  386  387  388

Each new instance costs one credit before options. PDF adds one credit per
capture. Recording adds one credit per started five seconds of requested
duration. Both require a paid Chrome-based instance, and video requires
device_scale=1. Retina (device_scale=2), ad blocking (hide_ads=1), and downloads
add no credits.
