A Python SDK for ScreenshotOne.com API to take screenshots of URLs, render HTML as images and PDF
Project description
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.
The SDK client is synchronized with the latest screenshot API options.
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:
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}")
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.
License
screenshotone/pythonsdk
is released under the MIT license.
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
Built Distribution
File details
Details for the file screenshotone-0.0.13.tar.gz
.
File metadata
- Download URL: screenshotone-0.0.13.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac4dcb6035d080e0f2cd299d08064397e81469503bd35aae97daddede88acb01 |
|
MD5 | c2e6b04c44260e5c35caa91906abdaa2 |
|
BLAKE2b-256 | f0db14a05eb955f35a58653ed0d3e1a9f9f5836d25dedca49a717db4caf4f817 |
File details
Details for the file screenshotone-0.0.13-py3-none-any.whl
.
File metadata
- Download URL: screenshotone-0.0.13-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c2ecd7e0304ed8f87a70c8ab508397137a8102950596daa0289ccae2467de15 |
|
MD5 | 0d4511752e7703ed5b4fe8cc60dca614 |
|
BLAKE2b-256 | 512a352e0916f959ee80277305f84d5b14863d6c930032b2ebda895eccda8b36 |