Language

Python Screenshot API

Integrate screenshot capture into Python applications using the requests library or httpx. Ideal for data pipelines, Django/Flask web apps, automation scripts, and web scraping projects. Includes examples for synchronous and async requests, saving images to files, and handling rate limits with exponential backoff.

Quick Start

1

Install dependencies

Run pip install requests (or pip install httpx for async support). Works with Python 3.7+.

2

Get your API key

Sign up for Screenshotly and get your API key from the dashboard.

3

Copy the code example

Use our Python code example as a starting point.

4

Customize and integrate

Modify the code to fit your specific use case and requirements.

Code Example

# Python with requests
import requests

def capture_screenshot(url: str, output_path: str) -> None:
    response = requests.post(
        'https://api.screenshotly.app/screenshot',
        headers={
            'Authorization': f'Bearer {API_KEY}',
            'Content-Type': 'application/json',
        },
        json={
            'url': url,
            'device': 'desktop',
            'format': 'png',
        }
    )
    
    with open(output_path, 'wb') as f:
        f.write(response.content)

When to Use Python with Screenshotly

Use the Python integration for data pipelines, Django/Flask web applications, automation scripts, and machine learning preprocessing. Python is ideal when you need to combine screenshots with data analysis (Pandas), image processing (Pillow/OpenCV), or feed visual data into ML models.

Python Best Practices

Use httpx instead of requests for async support — critical for Django Channels, FastAPI, and high-concurrency data pipelines.

Implement exponential backoff with the tenacity library: @retry(stop=stop_after_attempt(3), wait=wait_exponential()).

Save screenshots to BytesIO for in-memory processing with Pillow before writing to disk or uploading to S3.

For Pandas batch workflows, use concurrent.futures.ThreadPoolExecutor to parallelize captures across a DataFrame of URLs.

Want a step-by-step walkthrough?

Read the full Python tutorial →

API Reference

EndpointPOST /api/screenshot
AuthenticationBearer token
Content-Typeapplication/json
View full API docs

Frequently Asked Questions

How do I handle authentication in Python requests?

Include your API key in the Authorization header as 'Bearer YOUR_API_KEY'. Use environment variables to store your key securely: os.getenv('SCREENSHOTLY_API_KEY').

Can I use Screenshotly with Django or Flask?

Yes! Create views that accept URLs and return screenshots. You can serve images directly using HttpResponse with image content-type or save to media storage for later access.

What's the best way to handle errors in Python?

Use response.raise_for_status() to raise exceptions for HTTP errors. Wrap API calls in try-except blocks to handle RequestException, Timeout, and ConnectionError appropriately.

How do I process screenshots in Python data pipelines?

Use libraries like Pandas for batch processing URLs, concurrent.futures for parallel requests, and PIL/Pillow for image processing. Consider using asyncio with aiohttp for high-performance async processing.

Start building with Python

Get your API key and start capturing screenshots in minutes.

Other Languages