The Batch Scraper API is in public beta, available to every ZenRows account. You need an active ZenRows API key. The
ZenRowsBatchClient shown here is separate from the SDK’s synchronous scraping client, ZenRowsClient.Install and Authenticate
While the batch client is being published to PyPI, install the SDK from the beta branch:This git install is temporary. The batch client is not on PyPI yet; once it is published,
pip install zenrows will include it.Python
with ZenRowsBatchClient(...) as client: ...) when you want connections to close automatically. By default it targets the production Batch Scraper API; pass base_url=... (or set ZENROWS_BATCH_BASE_URL) to point at a different environment.
Quickstart: Submit, Wait, Get Results
This is the standard end-to-end flow.submit_regular returns a JobRef (no GET yet), job.run.wait() blocks until the current run reaches a terminal state and returns a RunHandle, and run.results(...) iterates the per-task results.
Python
job.run.wait() returns a RunHandle whose .data snapshot is ready, so run.results(...) and run.download_to_dir(...) work without re-passing IDs.
Configuring the Scrape
zenrows_params sets scraping options for every URL in the job. Values can be strings, booleans, or integers; the SDK converts them to strings before sending.
Python
response_type: markdown produces Markdown; autoparse, json_response, or a CSS extractor produce JSON; otherwise the result is HTML. ZenRows records this format on each result. Other common keys include js_instructions, wait, block_resources, json_response, css_extractor, autoparse, outputs, original_status, allowed_status_codes, and session_id. Custom request headers (custom_headers) are not supported yet.
Per-URL Options and Correlating Results
To set a per-URLexternal_id, metadata, or zenrows_params, pass dictionaries instead of plain strings. Per-URL zenrows_params override the job-level ones when a key appears in both.
Python
Downloading Content
results() gives you metadata plus a presigned result_url per task; the SDK downloads bodies straight from that URL with no extra API round-trip. Four options, on the current run (job.run.*) or any specific run (client.get_run(job_id, run_id=...)):
Python
result_url is a plain presigned URL (no auth header) valid for a short window, so fetch it promptly or re-list the results to get a fresh one.
Open Jobs: Streaming URLs in Batches
When you don’t have every URL up front, open a job, add tasks in batches, and close it. The run stays active and completes once it finishes the final batch.Python
last_batch=True (or calling job.close()) locks the job, and the API rejects further adds. File-input (CSV) upload is not supported for open jobs; use a closed job for CSV.
Large Inputs: CSV Upload
For lists too large to inline, upload a CSV once and reference it.upload_csv allocates the slot, PUTs your file to the presigned URL, and returns a file_input_id that submit_regular(file_input_id=...) consumes.
Python
url and optional external_id columns, and applies the job-level zenrows_params to all of them. Limits: 50 MB / 100,000 rows.
Listing and Pagination
The SDK offers both single-page calls (list_jobs, list_runs, list_results) and lazy iterators that page for you. The iterators yield loaded handles.
Python
Reruns and Retrying Failures
Each rerun creates a brand-new run on the same job.Python
Scheduled Jobs
Build a schedule with the typed builders and submit a scheduled job. ZenRows stores its URLs as a template, and each fire produces a fresh run.Python
job.schedule.* controls the recurring schedule, and job.run.* controls the current run. This disambiguates the API’s two distinct “pause” actions:
Python
Completion Notifications: Webhooks
Attach a webhook at submit time, and ZenRows sends arun.completed event to your HTTPS URL when a run finishes. Set signature: True to receive HMAC-signed deliveries (see Signed Webhooks); it defaults to unsigned. You can also manage the webhook later with client.put_job_webhook(...) / client.delete_job_webhook(...), and probe a receiver with client.test_webhook(...).
Python
X-ZenRows-Event-Id header.
Bulk Export (ZIP)
Bundle an entire run’s result bodies into a single server-side zip:download_all_results starts the export, waits for it, and streams the file to disk.
Python
The server-side zip is capped at 1 GiB per run. For larger runs, or one file per task, use
download_to_dir, which fetches bodies client-side with no size limit (slower; tune with concurrency). For manual control, client.start_results_export(...) and client.wait_for_export(...) expose the two steps separately.Estimating Cost
Estimate usage before submitting withclient.estimate_cost. It takes the same body you would submit and runs client-side with no API call. The tiers are 1 (base), 5 (js_render), 10 (premium_proxy), 25 (both), and a dynamic 1 to 25 for mode=auto.
Python
min == max (est.exact) unless the job uses mode=auto, which yields a per-task range.
Checking Actual Cost
Once a run finishes, read the actual usage it consumed fromrun.stats.spend ({credits, cost}).
Python
task.spend is indicative and often absent on successful rows, so rely on the run-level rollup for actuals. Your ZenRows account statement remains the authoritative record for billing.
Signed Webhooks: HMAC Keys
Signed deliveries (see Webhooks) need an active HMAC key for your organization. Rotation uses two slots, active plus candidate, so you can roll keys without downtime.Python
X-Signature: t=<unix>,v1=<hex>,kid=<active> header by recomputing HMAC-SHA256(secret, f"{t}.{raw_body}") and comparing the result to v1, selecting the secret by kid.
Error Handling
Every non-2xx raisesBatchAPIError. Its code attribute carries the stable code from the RFC 7807 body, and status_code the HTTP status.
Python
failed results with an error object you can read through task.error.code and task.error.detail.
Idempotency
Passidempotency_key to submit_* and to rerun / retry_failed to guard against accidentally creating duplicate jobs. Each key can be used once: a later call that reuses the same key raises a 409 conflict, whether or not the body is identical, and the API does not store or replay the original result. An idempotency key is therefore not a safe-retry token, so if a call fails midway, check whether the job was created before retrying with a new key.
Python
ZenRowsBatchClient. See the SDK repository or run help(ZenRowsBatchClient).