Skip to content

Commit f73f73b

Browse files
author
stlc-bot
committed
feat(batch): support Scrape Anything batches up to 100k URLs (#1883)
Stainless-Generated-From: 1c12fc91530bca169d3625153736b147c679d944
1 parent 55aee7f commit f73f73b

9 files changed

Lines changed: 2157 additions & 1216 deletions

File tree

‎src/context/dev/resources/batch.py‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def list(
9595
limit: int | Omit = omit,
9696
q: str | Omit = omit,
9797
search_type: Literal["exact", "prefix"] | Omit = omit,
98+
should_include_unified: bool | Omit = omit,
9899
status: Literal["queued", "running", "cancelling", "completed", "cancelled", "failed"] | Omit = omit,
99100
tags: Union[str, SequenceNotStr[str]] | Omit = omit,
100101
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -118,6 +119,8 @@ def list(
118119
search_type: `prefix` for as-you-type prefix matching (default), `exact` for full-token
119120
matching.
120121
122+
should_include_unified: Include batches submitted with Scrape Anything formats. Defaults to false.
123+
121124
status: Filter by status.
122125
123126
tags: Tags to filter by (matches batches having any of them). Pass repeated `tags`
@@ -144,6 +147,7 @@ def list(
144147
"limit": limit,
145148
"q": q,
146149
"search_type": search_type,
150+
"should_include_unified": should_include_unified,
147151
"status": status,
148152
"tags": tags,
149153
},
@@ -242,8 +246,9 @@ def get_results(
242246
) -> BatchGetResultsResponse:
243247
"""Page through a finished batch’s results as JSON.
244248
245-
Results remain available for
246-
180 days.
249+
Each record contains result
250+
with the same outputs and per-format errors as POST /web/scrape. Results remain
251+
available for 180 days.
247252
248253
Args:
249254
batch_id: Batch ID.
@@ -296,10 +301,11 @@ def submit(
296301
extra_body: Body | None = None,
297302
timeout: float | httpx.Timeout | None | NotGiven = not_given,
298303
) -> BatchSubmitResponse:
299-
"""Scrape up to 25,000 URLs, or crawl a site, asynchronously.
300-
301-
Poll the batch ID or
302-
receive a webhook when it finishes.
304+
"""
305+
Scrape up to 100,000 URLs, or crawl a site, asynchronously using the same
306+
formats and scrape parameters as POST /web/scrape. Choose Markdown, HTML,
307+
screenshots, images, bytes, parsed fields, products, highlights, and JSON. Poll
308+
the batch ID or receive a webhook when it finishes.
303309
304310
Args:
305311
input: Choose a URL list or a site crawl.
@@ -408,6 +414,7 @@ async def list(
408414
limit: int | Omit = omit,
409415
q: str | Omit = omit,
410416
search_type: Literal["exact", "prefix"] | Omit = omit,
417+
should_include_unified: bool | Omit = omit,
411418
status: Literal["queued", "running", "cancelling", "completed", "cancelled", "failed"] | Omit = omit,
412419
tags: Union[str, SequenceNotStr[str]] | Omit = omit,
413420
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -431,6 +438,8 @@ async def list(
431438
search_type: `prefix` for as-you-type prefix matching (default), `exact` for full-token
432439
matching.
433440
441+
should_include_unified: Include batches submitted with Scrape Anything formats. Defaults to false.
442+
434443
status: Filter by status.
435444
436445
tags: Tags to filter by (matches batches having any of them). Pass repeated `tags`
@@ -457,6 +466,7 @@ async def list(
457466
"limit": limit,
458467
"q": q,
459468
"search_type": search_type,
469+
"should_include_unified": should_include_unified,
460470
"status": status,
461471
"tags": tags,
462472
},
@@ -555,8 +565,9 @@ async def get_results(
555565
) -> BatchGetResultsResponse:
556566
"""Page through a finished batch’s results as JSON.
557567
558-
Results remain available for
559-
180 days.
568+
Each record contains result
569+
with the same outputs and per-format errors as POST /web/scrape. Results remain
570+
available for 180 days.
560571
561572
Args:
562573
batch_id: Batch ID.
@@ -609,10 +620,11 @@ async def submit(
609620
extra_body: Body | None = None,
610621
timeout: float | httpx.Timeout | None | NotGiven = not_given,
611622
) -> BatchSubmitResponse:
612-
"""Scrape up to 25,000 URLs, or crawl a site, asynchronously.
613-
614-
Poll the batch ID or
615-
receive a webhook when it finishes.
623+
"""
624+
Scrape up to 100,000 URLs, or crawl a site, asynchronously using the same
625+
formats and scrape parameters as POST /web/scrape. Choose Markdown, HTML,
626+
screenshots, images, bytes, parsed fields, products, highlights, and JSON. Poll
627+
the batch ID or receive a webhook when it finishes.
616628
617629
Args:
618630
input: Choose a URL list or a site crawl.

‎src/context/dev/types/batch_cancel_response.py‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
from typing import List, Optional
44
from typing_extensions import Literal
55

6+
from pydantic import Field as FieldInfo
7+
68
from .intake import Intake
79
from .._models import BaseModel
810
from .crawl_controls import CrawlControls
911
from .page_error_count import PageErrorCount
1012

11-
__all__ = ["BatchCancelResponse", "Credits", "Progress", "Timing", "KeyMetadata"]
13+
__all__ = ["BatchCancelResponse", "Credits", "Formats", "Progress", "Timing", "KeyMetadata"]
1214

1315

1416
class Credits(BaseModel):
@@ -18,6 +20,37 @@ class Credits(BaseModel):
1820
"""Credits held at submission; unused credits are refunded when the batch settles."""
1921

2022

23+
class Formats(BaseModel):
24+
"""Outputs requested for each page. Matches input.data.formats on submission."""
25+
26+
bytes: Optional[bool] = None
27+
"""The original HTTP response body."""
28+
29+
highlights: Optional[bool] = None
30+
"""Markdown excerpts relevant to `highlightsParams.query`."""
31+
32+
html: Optional[bool] = None
33+
"""Rendered HTML."""
34+
35+
images: Optional[bool] = None
36+
"""Images found on the page."""
37+
38+
json_: Optional[bool] = FieldInfo(alias="json", default=None)
39+
"""An object matching `jsonParams.schema`, extracted from the page."""
40+
41+
markdown: Optional[bool] = None
42+
"""Page content as Markdown."""
43+
44+
parse: Optional[bool] = None
45+
"""Fields extracted with custom rules or a prebuilt parser, returned as `parsed`."""
46+
47+
product: Optional[bool] = None
48+
"""Product details such as name, price, and availability."""
49+
50+
screenshot: Optional[bool] = None
51+
"""A screenshot of the page."""
52+
53+
2154
class Progress(BaseModel):
2255
"""How far the batch got before cancellation."""
2356

@@ -61,8 +94,8 @@ class BatchCancelResponse(BaseModel):
6194
credits: Credits
6295
"""What this batch cost so far."""
6396

64-
format: Literal["markdown", "html"]
65-
"""What each page is returned as."""
97+
formats: Formats
98+
"""Outputs requested for each page. Matches input.data.formats on submission."""
6699

67100
input: Intake
68101
"""What the submission accepted."""

0 commit comments

Comments
 (0)