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.
Release files for screenshotone 0.0.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| screenshotone-0.0.16.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| screenshotone-0.0.16-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:11.1 kB
Release files / screenshotone-0.0.16.tar.gz
| Download URL | screenshotone-0.0.16.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c5d34e509ffc89cdece113295e7640485bff05c0eb8c6834aed8c90152e038d
|
|
BLAKE2b-256 checksum How to use checksums |
b7a2d2fceb69f8daa417af8c959f1c95a4cf827136eb6a131b5ff0a36915c1d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / screenshotone-0.0.16-py3-none-any.whl
| Download URL | screenshotone-0.0.16-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91839c45b21cefc159fca2780f96df8e6acf1e55951fc00af38e56fa708a5070
|
|
BLAKE2b-256 checksum How to use checksums |
2d62b1a4fd4159923070763382fd8c2cd099fb5a9e1d7c25c39ad763260a1dec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|