Skip to main content

pythonsdk

An official Python SDK for ScreenshotOne.com API to take screenshots of URLs, render HTML as images and PDF.

It takes minutes to start taking screenshots. Just sign up to get access and secret keys, import the client, and you are ready to go.

See the screenshot API options for option descriptions and supported values.

Pass access_key to Client and use .async_option(True) for the API's async option. Repeated options such as .proxy_bypass_hosts(["cdn.example.com", "cdn.*.screenshotone.com"]) accept lists.

Installation

pip install screenshotone

Usage

Generate a screenshot URL without executing the request. Or download the screenshot. It is up to you:

import shutil
from screenshotone import Client, TakeOptions

# create API client
client = Client('<your access key>', '<your secret key>')

# set up options
options = (TakeOptions.url('https://screenshotone.com')
    .format("png")
    .viewport_width(1024)
    .viewport_height(768)
    .block_cookie_banners(True)
    .block_chats(True))

# generate the screenshot URL and share it with a user
url = client.generate_take_url(options)
# expected output: https://api.screenshotone.com/take?url=https%3A%2F%2Fscreenshotone.com&viewport_width=1024&viewport_height=768&block_cookie_banners=True&block_chats=True&access_key=<your access key>&signature=6afc9417a523788580fa01a9f668ea82c78a9d2b41441d2a696010bf2743170f

# or render a screenshot and download the image as stream
image = client.take(options)

# store the screenshot the example.png file
with open('example.png', 'wb') as result_file:
    shutil.copyfileobj(image, result_file)

How to handle errors

Read about how to handle the ScreenshotOne API errors, and that's how you can get the HTTP status code and the error code of the request:

from screenshotone import APIErrorException, InvalidRequestException

try:
    # ...
    # render a screenshot and download the image as stream
    image = client.take(options)
    # ...
except InvalidRequestException as e:
    print(f"Invalid request: {e}")
    if e.http_status_code:
        print(f"HTTP Status Code: {e.http_status_code}")
    if e.error_code:
        print(f"Error Code: {e.error_code}")
except APIErrorException as e:
    print(f"API Error: {e}")
    if e.http_status_code:
        print(f"HTTP Status Code: {e.http_status_code}")
    if e.error_code:
        print(f"Error Code: {e.error_code}")
except Exception as e:
    # handle any other exceptions
    print(f"An unexpected error occurred: {e}")

InvalidRequestException inherits from APIErrorException. Catch APIErrorException to handle both; place an InvalidRequestException handler first if you want to handle invalid requests separately.

Development

Install the SDK and run the offline regression tests:

python -m pip install -e .
python -m unittest discover -s tests -v

The tests mock HTTP requests and do not require API keys or network access. tests/fixtures/documented_options.json contains a saved documentation snapshot and its verification date. These tests check the snapshot, not the live docs; refresh it when synchronizing the SDK with the docs.

CI runs the tests on pushes and pull requests using Python 3.7 through 3.14. The release workflow also runs the tests before publishing.

Release

Github Actions is used to automate the release process and publishing to PyPI. Update the library version in pyproject.toml and create a new release to launch the publish workflow.

Useful resources

Python tutorials from the ScreenshotOne blog:

License

screenshotone/pythonsdk is released under the MIT license.

Metadata

Release files for screenshotone 0.0.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for screenshotone 0.0.17
File Size Uploaded Provenance Actions
screenshotone-0.0.17.tar.gz 9.8 kB Without provenance Details for screenshotone-0.0.17.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for screenshotone 0.0.17
File Interpreter ABI Platform Actions
screenshotone-0.0.17-py3-none-any.whl Python 3 none any Details for screenshotone-0.0.17-py3-none-any.whl

Total release size: 16.6 kB

Release files / screenshotone-0.0.17.tar.gz

Download URL screenshotone-0.0.17.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c11c5294cff857ca002ba57bf57d6db3938a8fbaa6ada0e66a71e81e740e2d47
BLAKE2b-256 checksum
How to use checksums
77e6192d0f976f58f478471428c71e3c74b71bf48e01ee4ea5058f1e7e538cc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / screenshotone-0.0.17-py3-none-any.whl

Download URL screenshotone-0.0.17-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5339e864c4bc12be01145c3972c5c11e7ffddae2cb851f2f3a00f73466807757
BLAKE2b-256 checksum
How to use checksums
3b5ab01ee51763a02417d6c6ab077a1354bcb1e2f3005a8e45a1224c7700a9c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for screenshotone 0.0.17

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page