Python

Take screenshots using Python with our official SDK or plain HTTP requests.

Installation

pip install lambdashot

Quick Start

from lambdashot import LambdaShot

client = LambdaShot("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY")

# Take a screenshot
screenshot = client.take(
    url="https://example.com",
    format="png",
    viewport_width=1920,
    viewport_height=1080,
)

# Save to file
with open("screenshot.png", "wb") as f:
    f.write(screenshot)

Async Support

import asyncio
from lambdashot import AsyncLambdaShot

async def main():
    client = AsyncLambdaShot("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY")

    screenshot = await client.take(
        url="https://example.com",
        format="png",
    )

    with open("screenshot.png", "wb") as f:
        f.write(screenshot)

asyncio.run(main())

Generate Signed URL

url = client.generate_signed_url(
    url="https://example.com",
    format="png",
    block_ads=True,
)

print(url)
# https://api.lambdashot.com/take?url=...&signature=...

Options

screenshot = client.take(
    url="https://example.com",

    # Output
    format="png",              # png, jpeg, webp, pdf
    image_quality=90,          # 0-100

    # Viewport
    viewport_width=1920,
    viewport_height=1080,
    viewport_device="iphone_15_pro",
    device_scale_factor=2,

    # Full page
    full_page=True,
    full_page_scroll=True,

    # Blocking
    block_ads=True,
    block_cookie_banners=True,
    block_trackers=True,

    # Customization
    dark_mode=True,
    delay=2,
    wait_for_selector=".content-loaded",
)

Without SDK (requests)

import requests

params = {
    "access_key": "YOUR_ACCESS_KEY",
    "url": "https://example.com",
    "format": "png",
    "viewport_width": 1920,
}

response = requests.get("https://api.lambdashot.com/take", params=params)

with open("screenshot.png", "wb") as f:
    f.write(response.content)

Video Recording

video = client.animate(
    url="https://example.com",
    scenario="scroll",
    duration=10,
    format="mp4",
)

with open("video.mp4", "wb") as f:
    f.write(video)

Error Handling

from lambdashot import LambdaShotError

try:
    screenshot = client.take(url="https://example.com")
except LambdaShotError as e:
    if e.code == "timeout_error":
        print("Screenshot timed out, retrying...")
    elif e.code == "access_key_invalid":
        print("Check your API key")
    else:
        print(f"Error: {e.message}")

Batch Screenshots

import asyncio
from lambdashot import AsyncLambdaShot

async def take_screenshots(urls):
    client = AsyncLambdaShot("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY")

    tasks = [
        client.take(url=url, format="png")
        for url in urls
    ]

    return await asyncio.gather(*tasks)

urls = [
    "https://example.com",
    "https://google.com",
    "https://github.com",
]

screenshots = asyncio.run(take_screenshots(urls))