Skip to main content

Python SDK for ShotAPI - Screenshot & Rendering API

Project description

ShotAPI Python SDK

Official Python SDK for ShotAPI - The Screenshot & Rendering API.

Installation

pip install shotapi

Quick Start

from shotapi import ShotAPI

# Initialize the client
client = ShotAPI("sk_your_api_key")

# Take a screenshot
image = client.screenshot("https://example.com")
with open("screenshot.png", "wb") as f:
    f.write(image)

Features

  • URL Screenshots - Capture any webpage as PNG, JPEG, WebP, or PDF
  • HTML Rendering - Convert HTML/CSS to images
  • Metadata Extraction - Get OG tags, title, description, tech stack
  • Batch Processing - Screenshot multiple URLs in parallel
  • Visual Diff - Compare two pages and get difference percentage

Usage Examples

Basic Screenshot

from shotapi import ShotAPI

client = ShotAPI("sk_your_api_key")

# Simple screenshot
image = client.screenshot("https://stripe.com")

# Full-page screenshot
image = client.screenshot(
    "https://github.com",
    full_page=True,
    format="png"
)

# With options
image = client.screenshot(
    "https://example.com",
    width=1920,
    height=1080,
    dark_mode=True,
    device_scale_factor=2,
    block_ads=True,
)

Device Mockups

# Wrap in iPhone frame
image = client.screenshot(
    "https://example.com",
    mockup="iphone"
)

# MacBook mockup
image = client.screenshot(
    "https://example.com",
    mockup="macbook"
)

HTML to Image

# Render HTML to image
html = """
<div style="padding: 40px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
    <h1 style="color: white; font-family: sans-serif;">Hello World!</h1>
</div>
"""

image = client.render(html, width=800, height=400)

Metadata Extraction

# Get page metadata
meta = client.metadata("https://github.com")
print(meta["title"])
print(meta["description"])
print(meta["og_image"])

# With markdown content
meta = client.metadata("https://example.com", extract_markdown=True)
print(meta["markdown"])

Batch Screenshots

# Capture multiple URLs
urls = [
    "https://google.com",
    "https://github.com",
    "https://stripe.com",
]

result = client.batch(urls, format="png", full_page=True)
for item in result["results"]:
    print(f"{item['url']} -> {item['filename']}")

Visual Diff

# Compare two pages
diff_image, diff_percentage = client.diff(
    "https://example.com",
    "https://example.org"
)

print(f"Pages differ by {diff_percentage}%")
with open("diff.png", "wb") as f:
    f.write(diff_image)

Advanced Options

# Full control over the capture
image = client.screenshot(
    "https://example.com",
    width=1280,
    height=720,
    full_page=True,
    format="png",
    delay=2,  # Wait 2 seconds before capture
    dark_mode=True,
    device_scale_factor=2,
    custom_css="body { font-family: 'Comic Sans MS' !important; }",
    custom_js="document.querySelector('.popup').remove()",
    wait_for_selector=".content-loaded",
    click_selector=".accept-cookies",
    hide_selectors=[".ad-banner", ".newsletter-popup"],
    block_ads=True,
    headers={"Authorization": "Bearer token"},
    cookies=[{"name": "session", "value": "abc123", "domain": "example.com"}],
    geolocation={"latitude": 40.7128, "longitude": -74.0060},
    timezone="America/New_York",
)

Error Handling

from shotapi import ShotAPI, ShotAPIError, AuthenticationError, RateLimitError

client = ShotAPI("sk_your_api_key")

try:
    image = client.screenshot("https://example.com")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except ShotAPIError as e:
    print(f"API error: {e.message}")

Context Manager

# Automatically close connection
with ShotAPI("sk_your_api_key") as client:
    image = client.screenshot("https://example.com")

Configuration

# Custom base URL and timeout
client = ShotAPI(
    api_key="sk_your_api_key",
    base_url="https://shotapi.net",  # default
    timeout=120.0,  # seconds
)

Pro/Max Features

Some features require a Pro or Max plan:

Feature Free Pro Max
Basic screenshots Yes Yes Yes
Full-page capture Yes Yes Yes
Dark mode No Yes Yes
Device mockups No Yes Yes
Custom CSS/JS No Yes Yes
Element selection No Yes Yes
Geo/Timezone emulation No Yes Yes
Block ads No Yes Yes
Batch processing No Yes Yes
Markdown extraction No Yes Yes

Links

License

MIT License - see LICENSE file for details.

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

shotapi-1.0.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

shotapi-1.0.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file shotapi-1.0.0.tar.gz.

File metadata

  • Download URL: shotapi-1.0.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for shotapi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 24f4b54eed17c517d8990120a8b9632c0a70884e5ed42b4479b919d5337bf6f1
MD5 733e23015c22d01f8710dd3bf1a55a37
BLAKE2b-256 06f99b79b029f3a032a44a3391c2a0a4efb6f55f527d6f75560785e1827fb89b

See more details on using hashes here.

File details

Details for the file shotapi-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: shotapi-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for shotapi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2881ed324e60094824a2b2934d00cfbf8a8e0f4895e8290eba719ba37cfbea1f
MD5 f972a832a7b956b9ffc9ecacef364808
BLAKE2b-256 12b2f850f9cd147c41e2ea2e45a68065750ae2065bc1af33fe2190b91af4ff79

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