Skip to main content

Screenshot Client Batch

PyPI version Python 3.11+

Complete screenshot service client and batch orchestration package. Provides both a low-level API client (ScreenshotServiceClient) and high-level coordinators for batch processing of screenshot jobs via the Azure-hosted screenshot service.

Built on top of the auto-generated screenshot-client-core, this package adds:

  • Polling with configurable timeout/interval (using infra_core.polling)
  • Environment-based configuration (from_env())
  • Custom exception hierarchy for better error handling
  • Batch coordination with chunking, parallel execution, and progress tracking
  • CLI tool for processing JSONL files

Installation

pip install screenshot-client-batch

Requirements

  • Python 3.11+
  • Access to a screenshot service endpoint (Azure Function)

Environment Variables

Variable Required Description
SCREENSHOT_FUNC_BASE_URL Yes Base URL of the screenshot service
SCREENSHOT_FUNC_API_KEY No API key for authenticated endpoints
SCREENSHOT_AZURE_STORAGE_CONNECTION_STRING No Azure Storage connection for upload/download

Quick Start: API Client

from screenshot_batch import ScreenshotServiceClient

# Create client from environment variables
client = ScreenshotServiceClient.from_env()  # Uses SCREENSHOT_FUNC_BASE_URL, SCREENSHOT_FUNC_API_KEY

# Start a batch
handle = client.start_batch(
    "my-batch",
    {"jobs": [{"job_id": "1", "url": "https://example.com"}]}
)

# Poll until completion
result = client.poll_run(handle.batch_id, handle.job_id, timeout=600)
print(f"Status: {result['status']}")

# Get results
manifest = client.get_result(handle.batch_id, handle.job_id)

Batch Orchestration

For single batch runs with automatic polling and optional artifact download:

from pathlib import Path

from screenshot import ScreenshotOptions, CaptureOptions
from screenshot_batch import ScreenshotBatchCoordinator, ScreenshotJobSpec

coordinator = ScreenshotBatchCoordinator(
    base_url="https://site-screenshot.azurewebsites.net",
    batch_id="marketing-refresh",
    store_dir=Path("data/site-screens"),
    download_results=True,
)

jobs = [
    ScreenshotJobSpec.from_url(
        "https://example.com",
        options=ScreenshotOptions(
            capture=CaptureOptions(enabled=True, max_pages=3, depth=1),
        ),
    ),
]

result = coordinator.run_batch_sync(jobs)
print(result.status, result.job_completed)

Chunked Runs

For large collections (e.g., 4,000 URLs), use ScreenshotMultiRunCoordinator to fan out multiple API calls while keeping results grouped in per-run folders:

from screenshot_batch import (
    ScreenshotMultiRunCoordinator,
    ScreenshotJobSpec,
)

runner = ScreenshotMultiRunCoordinator(
    base_url="https://site-screenshot.azurewebsites.net",
    batch_id="yc-companies",
    store_dir=Path("data/site-screens"),
    download_results=True,
    upload_results=True,  # Optional: upload to Azure Storage
)

specs = [
    ScreenshotJobSpec.from_url("https://example.com", options=my_options),
    # ... more specs
]

summaries = runner.run_jobs(specs, chunk_size=4, max_parallel_runs=4)
for summary in summaries:
    print(summary.chunk_index, summary.result.status, summary.result.job_failed)

CLI

Install the package and run the CLI to process a JSONL file in chunks:

screenshot-client-batch input.jsonl my-batch-id \
  --base-url https://site-screenshot.azurewebsites.net \
  --chunk-size 4 \
  --max-parallel-runs 32 \
  --per-run-concurrency 4 \
  --store-dir data/screenshots \
  --download-results \
  --upload-results \
  --state-path data/state.json \
  --metadata '{"source":"my-project"}' \
  --output data/results.jsonl

CLI Options

Option Default Description
--base-url $SCREENSHOT_FUNC_BASE_URL Screenshot service URL
--chunk-size 4 Jobs per API call
--max-parallel-runs 32 Concurrent API calls
--per-run-concurrency 4 Concurrency per run
--store-dir None Directory for downloaded artifacts
--download-results False Download artifacts after completion
--upload-results False Upload artifacts to Azure Storage
--state-path None JSON file for resumable state
--metadata None JSON metadata merged into all jobs
--output {input}.results.jsonl Output file path
--sample N None Limit to first N jobs (for testing)

Input Format

The input JSONL file should contain one JSON object per line:

{"url": "https://example.com", "job_id": "site-1", "metadata": {"category": "tech"}}
{"url": "https://another.com", "job_id": "site-2"}

Output Format

The output JSONL mirrors the input with added status fields:

{"url": "https://example.com", "job_id": "site-1", "status": "succeeded", "blob_url": "https://..."}
{"url": "https://another.com", "job_id": "site-2", "status": "failed", "errors": ["timeout"]}

Exception Handling

The package provides a custom exception hierarchy:

from screenshot_batch import (
    ScreenshotServiceError,  # Base exception
    ScreenshotConfigError,   # Configuration/environment errors
    ScreenshotAPIError,      # API communication errors
    ScreenshotTimeoutError,  # Polling timeout
)

try:
    result = client.poll_run(batch_id, job_id, timeout=60)
except ScreenshotTimeoutError:
    print("Batch did not complete in time")
except ScreenshotAPIError as e:
    print(f"API error: {e}")

Development

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Type checking
mypy src/screenshot_batch

# Linting
ruff check src/ tests/
ruff format src/ tests/

License

MIT

Metadata

Release files for screenshot-client-batch 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for screenshot-client-batch 0.1.0
File Size Uploaded Provenance
screenshot_client_batch-0.1.0.tar.gz 38.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for screenshot-client-batch 0.1.0
File Interpreter ABI Platform
screenshot_client_batch-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 64.0 kB

Release files / screenshot_client_batch-0.1.0.tar.gz

Download URL screenshot_client_batch-0.1.0.tar.gz
Size 38.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4e43ed4fb02275b57b9437a92e26d73738a00ced928e5d77eb3d0a56fb544928
BLAKE2b-256 checksum
How to use checksums
25018187a4bdaaf49fcdbc9e2736f136ca18ed7c9216d6f7b704a49672794e35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2025.

Transparency log

Release files / screenshot_client_batch-0.1.0-py3-none-any.whl

Download URL screenshot_client_batch-0.1.0-py3-none-any.whl
Size 25.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
057e070567ef43346a77e4cced2bb226964809dba1e5a7767fcbd7cfeb911cc4
BLAKE2b-256 checksum
How to use checksums
71443141f7ba26e097fb8eb886d48973ff03f2e95c8518be5cf51474afc18f0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2025.

Transparency log

Security for screenshot-client-batch 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for screenshot_client_batch-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page