Skip to content

Commit aed2184

Browse files
feat(api): api update
1 parent 691b4fb commit aed2184

6 files changed

Lines changed: 151 additions & 39 deletions

File tree

‎.stats.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 22
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-4a46f38182c87694de28ad72b2ebb873d3004533dbe8db3276637d6d80cf9a33.yml
3-
openapi_spec_hash: b10ee8536928665190a110738964fccb
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-bfa54d26b675d92a0b3db3e3c2147dc98250fb1e4cb82bb6bd6f9af544763506.yml
3+
openapi_spec_hash: 7d834a5553262d0a2538bc066f39d549
44
config_hash: 70354330f92ce169beabc98696ebb9a3

‎README.md‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,11 @@ from context.dev import ContextDev
130130

131131
client = ContextDev()
132132

133-
response = client.ai.ai_query(
134-
data_to_extract=[
135-
{
136-
"datapoint_description": "datapoint_description",
137-
"datapoint_example": "datapoint_example",
138-
"datapoint_name": "datapoint_name",
139-
"datapoint_type": "text",
140-
}
141-
],
142-
domain="domain",
143-
specific_pages={},
133+
response = client.web.web_scrape_images(
134+
url="https://example.com",
135+
enrichment={},
144136
)
145-
print(response.specific_pages)
137+
print(response.enrichment)
146138
```
147139

148140
## Handling errors

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

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -398,21 +398,29 @@ def web_scrape_images(
398398
self,
399399
*,
400400
url: str,
401+
enrichment: web_web_scrape_images_params.Enrichment | Omit = omit,
402+
max_age_ms: int | Omit = omit,
401403
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
402404
# The extra values given here take precedence over values defined on the client or passed to this method.
403405
extra_headers: Headers | None = None,
404406
extra_query: Query | None = None,
405407
extra_body: Body | None = None,
406408
timeout: float | httpx.Timeout | None | NotGiven = not_given,
407409
) -> WebWebScrapeImagesResponse:
408-
"""Scrapes all images from the given URL.
409-
410-
Extracts images from img, svg,
411-
picture/source, link, and video elements including inline SVGs, base64 data
412-
URIs, and standard URLs.
410+
"""
411+
Extract image assets from a web page, including standard URLs, inline SVGs, data
412+
URIs, responsive image sources, metadata, CSS backgrounds, video posters, and
413+
embeds. The base request costs 1 credit; enrichment costs 1 credit per returned
414+
image.
413415
414416
Args:
415-
url: Full URL to scrape images from (must include http:// or https:// protocol)
417+
url: Page URL to inspect. Must include http:// or https://.
418+
419+
enrichment: Optional per-image processing, sent as deep-object query params such as
420+
enrichment[resolution]=true.
421+
422+
max_age_ms: Reuse a cached result this many milliseconds old or newer. Default: 86400000 (1
423+
day). Set to 0 to bypass cache. Maximum: 2592000000 (30 days).
416424
417425
extra_headers: Send extra headers
418426
@@ -429,7 +437,14 @@ def web_scrape_images(
429437
extra_query=extra_query,
430438
extra_body=extra_body,
431439
timeout=timeout,
432-
query=maybe_transform({"url": url}, web_web_scrape_images_params.WebWebScrapeImagesParams),
440+
query=maybe_transform(
441+
{
442+
"url": url,
443+
"enrichment": enrichment,
444+
"max_age_ms": max_age_ms,
445+
},
446+
web_web_scrape_images_params.WebWebScrapeImagesParams,
447+
),
433448
),
434449
cast_to=WebWebScrapeImagesResponse,
435450
)
@@ -922,21 +937,29 @@ async def web_scrape_images(
922937
self,
923938
*,
924939
url: str,
940+
enrichment: web_web_scrape_images_params.Enrichment | Omit = omit,
941+
max_age_ms: int | Omit = omit,
925942
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
926943
# The extra values given here take precedence over values defined on the client or passed to this method.
927944
extra_headers: Headers | None = None,
928945
extra_query: Query | None = None,
929946
extra_body: Body | None = None,
930947
timeout: float | httpx.Timeout | None | NotGiven = not_given,
931948
) -> WebWebScrapeImagesResponse:
932-
"""Scrapes all images from the given URL.
933-
934-
Extracts images from img, svg,
935-
picture/source, link, and video elements including inline SVGs, base64 data
936-
URIs, and standard URLs.
949+
"""
950+
Extract image assets from a web page, including standard URLs, inline SVGs, data
951+
URIs, responsive image sources, metadata, CSS backgrounds, video posters, and
952+
embeds. The base request costs 1 credit; enrichment costs 1 credit per returned
953+
image.
937954
938955
Args:
939-
url: Full URL to scrape images from (must include http:// or https:// protocol)
956+
url: Page URL to inspect. Must include http:// or https://.
957+
958+
enrichment: Optional per-image processing, sent as deep-object query params such as
959+
enrichment[resolution]=true.
960+
961+
max_age_ms: Reuse a cached result this many milliseconds old or newer. Default: 86400000 (1
962+
day). Set to 0 to bypass cache. Maximum: 2592000000 (30 days).
940963
941964
extra_headers: Send extra headers
942965
@@ -953,7 +976,14 @@ async def web_scrape_images(
953976
extra_query=extra_query,
954977
extra_body=extra_body,
955978
timeout=timeout,
956-
query=await async_maybe_transform({"url": url}, web_web_scrape_images_params.WebWebScrapeImagesParams),
979+
query=await async_maybe_transform(
980+
{
981+
"url": url,
982+
"enrichment": enrichment,
983+
"max_age_ms": max_age_ms,
984+
},
985+
web_web_scrape_images_params.WebWebScrapeImagesParams,
986+
),
957987
),
958988
cast_to=WebWebScrapeImagesResponse,
959989
)

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,47 @@
22

33
from __future__ import annotations
44

5-
from typing_extensions import Required, TypedDict
5+
from typing_extensions import Required, Annotated, TypedDict
66

7-
__all__ = ["WebWebScrapeImagesParams"]
7+
from .._utils import PropertyInfo
8+
9+
__all__ = ["WebWebScrapeImagesParams", "Enrichment"]
810

911

1012
class WebWebScrapeImagesParams(TypedDict, total=False):
1113
url: Required[str]
12-
"""Full URL to scrape images from (must include http:// or https:// protocol)"""
14+
"""Page URL to inspect. Must include http:// or https://."""
15+
16+
enrichment: Enrichment
17+
"""
18+
Optional per-image processing, sent as deep-object query params such as
19+
enrichment[resolution]=true.
20+
"""
21+
22+
max_age_ms: Annotated[int, PropertyInfo(alias="maxAgeMs")]
23+
"""Reuse a cached result this many milliseconds old or newer.
24+
25+
Default: 86400000 (1 day). Set to 0 to bypass cache. Maximum: 2592000000 (30
26+
days).
27+
"""
28+
29+
30+
class Enrichment(TypedDict, total=False):
31+
"""
32+
Optional per-image processing, sent as deep-object query params such as enrichment[resolution]=true.
33+
"""
34+
35+
classification: bool
36+
"""Classify each image by visual asset type."""
37+
38+
hosted_url: Annotated[bool, PropertyInfo(alias="hostedUrl")]
39+
"""
40+
Host materializable images on the Brand.dev CDN and return their URL and MIME
41+
type.
42+
"""
43+
44+
max_time_per_ms: Annotated[int, PropertyInfo(alias="maxTimePerMs")]
45+
"""Per-image enrichment timeout in milliseconds. Default: 6000. Maximum: 60000."""
46+
47+
resolution: bool
48+
"""Measure image width and height when possible."""

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,53 @@
55

66
from .._models import BaseModel
77

8-
__all__ = ["WebWebScrapeImagesResponse", "Image"]
8+
__all__ = ["WebWebScrapeImagesResponse", "Image", "ImageEnrichment"]
9+
10+
11+
class ImageEnrichment(BaseModel):
12+
"""Requested metadata for images that could be processed."""
13+
14+
height: Optional[int] = None
15+
"""Image height in pixels, when measured."""
16+
17+
mimetype: Optional[str] = None
18+
"""Detected MIME type, when hosted."""
19+
20+
type: Optional[
21+
Literal["photography", "illustration", "logo", "wordmark", "icon", "pattern", "graphic", "other"]
22+
] = None
23+
"""Visual asset category, when classified."""
24+
25+
url: Optional[str] = None
26+
"""Brand.dev CDN URL, when hosted."""
27+
28+
width: Optional[int] = None
29+
"""Image width in pixels, when measured."""
930

1031

1132
class Image(BaseModel):
1233
alt: Optional[str] = None
13-
"""Alt text of the image, or null if not present"""
34+
"""Image alt text, or null when unavailable."""
1435

1536
element: Literal["img", "svg", "link", "source", "video", "css", "object", "meta", "background"]
16-
"""The HTML element the image was found in"""
37+
"""Where the image was found."""
1738

1839
src: str
19-
"""The image source - can be a URL, inline HTML (for SVGs), or a base64 data URI"""
40+
"""Original image value: URL, inline SVG or HTML, or base64 data URI."""
2041

2142
type: Literal["url", "html", "base64"]
22-
"""The type/format of the src value"""
43+
"""Format of src."""
44+
45+
enrichment: Optional[ImageEnrichment] = None
46+
"""Requested metadata for images that could be processed."""
2347

2448

2549
class WebWebScrapeImagesResponse(BaseModel):
2650
images: List[Image]
27-
"""Array of scraped images"""
51+
"""Images found on the page."""
2852

2953
success: Literal[True]
30-
"""Indicates success"""
54+
"""Always true on success."""
3155

3256
url: str
33-
"""The URL that was scraped"""
57+
"""Page URL that was scraped."""

‎tests/api_resources/test_web.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,21 @@ def test_method_web_scrape_images(self, client: ContextDev) -> None:
248248
)
249249
assert_matches_type(WebWebScrapeImagesResponse, web, path=["response"])
250250

251+
@pytest.mark.skip(reason="Mock server tests are disabled")
252+
@parametrize
253+
def test_method_web_scrape_images_with_all_params(self, client: ContextDev) -> None:
254+
web = client.web.web_scrape_images(
255+
url="https://example.com",
256+
enrichment={
257+
"classification": True,
258+
"hosted_url": True,
259+
"max_time_per_ms": 1,
260+
"resolution": True,
261+
},
262+
max_age_ms=0,
263+
)
264+
assert_matches_type(WebWebScrapeImagesResponse, web, path=["response"])
265+
251266
@pytest.mark.skip(reason="Mock server tests are disabled")
252267
@parametrize
253268
def test_raw_response_web_scrape_images(self, client: ContextDev) -> None:
@@ -595,6 +610,21 @@ async def test_method_web_scrape_images(self, async_client: AsyncContextDev) ->
595610
)
596611
assert_matches_type(WebWebScrapeImagesResponse, web, path=["response"])
597612

613+
@pytest.mark.skip(reason="Mock server tests are disabled")
614+
@parametrize
615+
async def test_method_web_scrape_images_with_all_params(self, async_client: AsyncContextDev) -> None:
616+
web = await async_client.web.web_scrape_images(
617+
url="https://example.com",
618+
enrichment={
619+
"classification": True,
620+
"hosted_url": True,
621+
"max_time_per_ms": 1,
622+
"resolution": True,
623+
},
624+
max_age_ms=0,
625+
)
626+
assert_matches_type(WebWebScrapeImagesResponse, web, path=["response"])
627+
598628
@pytest.mark.skip(reason="Mock server tests are disabled")
599629
@parametrize
600630
async def test_raw_response_web_scrape_images(self, async_client: AsyncContextDev) -> None:

0 commit comments

Comments
 (0)