From 148be86b892bb7718fa2b79c0964f0089613fc96 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 25 Apr 2026 23:40:20 +0000 Subject: [PATCH 1/8] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 6d33ce6..fd64b39 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 22 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-a831ece9950c336fba69327e01aed391a08418e1898f4aff27a800471f139cc7.yml -openapi_spec_hash: 459258410b739536cdc75b91e8b4eac7 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-1cbd2dedb73f97573854f4ec863ebc17920b5813b6b16259f26989935b0cb1f4.yml +openapi_spec_hash: 1da5f104706e10973ebe29341f6cc0b7 config_hash: 70354330f92ce169beabc98696ebb9a3 From c9c388ecb41827df93f98ac8aa3c8f5ce754a13e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 26 Apr 2026 02:23:27 +0000 Subject: [PATCH 2/8] feat(api): api update --- .stats.yml | 4 +-- src/context/dev/resources/ai.py | 42 +++++++++++++-------------- src/context/dev/resources/industry.py | 8 ++--- src/context/dev/resources/utility.py | 16 +++------- 4 files changed, 30 insertions(+), 40 deletions(-) diff --git a/.stats.yml b/.stats.yml index fd64b39..20d2c16 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 22 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-1cbd2dedb73f97573854f4ec863ebc17920b5813b6b16259f26989935b0cb1f4.yml -openapi_spec_hash: 1da5f104706e10973ebe29341f6cc0b7 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-0f4b818ec07eb384832ac53f99b79eb59b0af5246209c6954c416148c8f0b5c0.yml +openapi_spec_hash: 08043c0ff1dea4cb8f0c5e54368a84c4 config_hash: 70354330f92ce169beabc98696ebb9a3 diff --git a/src/context/dev/resources/ai.py b/src/context/dev/resources/ai.py index 8c01210..6d7aebe 100644 --- a/src/context/dev/resources/ai.py +++ b/src/context/dev/resources/ai.py @@ -115,9 +115,8 @@ def extract_product( timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AIExtractProductResponse: """ - Beta feature: Given a single URL, determines if it is a product detail page, - classifies the platform/product type, and extracts the product information. - Supports Amazon, TikTok Shop, Etsy, and generic ecommerce sites. + Given a single URL, determines if it is a product page and extracts the product + information. Args: url: The product page URL to extract product data from. @@ -162,11 +161,11 @@ def extract_products( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AIExtractProductsResponse: - """Beta feature: Extract product information from a brand's website. + """Extract product information from a brand's website. - We will - analyze the website and return a list of products with details such as name, - description, image, pricing, features, and more. + We will analyze the website + and return a list of products with details such as name, description, image, + pricing, features, and more. Args: domain: The domain name to analyze. @@ -200,11 +199,11 @@ def extract_products( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AIExtractProductsResponse: - """Beta feature: Extract product information from a brand's website. + """Extract product information from a brand's website. - We will - analyze the website and return a list of products with details such as name, - description, image, pricing, features, and more. + We will analyze the website + and return a list of products with details such as name, description, image, + pricing, features, and more. Args: direct_url: A specific URL to use directly as the starting point for extraction without @@ -347,9 +346,8 @@ async def extract_product( timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AIExtractProductResponse: """ - Beta feature: Given a single URL, determines if it is a product detail page, - classifies the platform/product type, and extracts the product information. - Supports Amazon, TikTok Shop, Etsy, and generic ecommerce sites. + Given a single URL, determines if it is a product page and extracts the product + information. Args: url: The product page URL to extract product data from. @@ -394,11 +392,11 @@ async def extract_products( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AIExtractProductsResponse: - """Beta feature: Extract product information from a brand's website. + """Extract product information from a brand's website. - We will - analyze the website and return a list of products with details such as name, - description, image, pricing, features, and more. + We will analyze the website + and return a list of products with details such as name, description, image, + pricing, features, and more. Args: domain: The domain name to analyze. @@ -432,11 +430,11 @@ async def extract_products( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AIExtractProductsResponse: - """Beta feature: Extract product information from a brand's website. + """Extract product information from a brand's website. - We will - analyze the website and return a list of products with details such as name, - description, image, pricing, features, and more. + We will analyze the website + and return a list of products with details such as name, description, image, + pricing, features, and more. Args: direct_url: A specific URL to use directly as the starting point for extraction without diff --git a/src/context/dev/resources/industry.py b/src/context/dev/resources/industry.py index fbcce05..cf90762 100644 --- a/src/context/dev/resources/industry.py +++ b/src/context/dev/resources/industry.py @@ -120,8 +120,8 @@ def retrieve_sic( ) -> IndustryRetrieveSicResponse: """ Classify any brand into Standard Industrial Classification (SIC) codes from its - domain or name. Choose between the original 1987 SIC system (`original_sic`) or - the latest SIC list maintained by the SEC (`latest_sec`). + domain or name. Choose between the original SIC system (`original_sic`) or the + latest SIC list maintained by the SEC (`latest_sec`). Args: input: Brand domain or title to retrieve SIC code for. If a valid domain is provided, @@ -266,8 +266,8 @@ async def retrieve_sic( ) -> IndustryRetrieveSicResponse: """ Classify any brand into Standard Industrial Classification (SIC) codes from its - domain or name. Choose between the original 1987 SIC system (`original_sic`) or - the latest SIC list maintained by the SEC (`latest_sec`). + domain or name. Choose between the original SIC system (`original_sic`) or the + latest SIC list maintained by the SEC (`latest_sec`). Args: input: Brand domain or title to retrieve SIC code for. If a valid domain is provided, diff --git a/src/context/dev/resources/utility.py b/src/context/dev/resources/utility.py index 775300e..15328a1 100644 --- a/src/context/dev/resources/utility.py +++ b/src/context/dev/resources/utility.py @@ -56,9 +56,7 @@ def prefetch( ) -> UtilityPrefetchResponse: """ Signal that you may fetch brand data for a particular domain soon to improve - latency. This endpoint does not charge credits and is available for paid - customers to optimize future requests. [You must be on a paid plan to use this - endpoint] + latency. Args: domain: Domain name to prefetch brand data for @@ -106,9 +104,7 @@ def prefetch_by_email( Signal that you may fetch brand data for a particular domain soon to improve latency. This endpoint accepts an email address, extracts the domain from it, validates that it's not a disposable or free email provider, and queues the - domain for prefetching. This endpoint does not charge credits and is available - for paid customers to optimize future requests. [You must be on a paid plan to - use this endpoint] + domain for prefetching. Args: email: Email address to prefetch brand data for. The domain will be extracted from the @@ -177,9 +173,7 @@ async def prefetch( ) -> UtilityPrefetchResponse: """ Signal that you may fetch brand data for a particular domain soon to improve - latency. This endpoint does not charge credits and is available for paid - customers to optimize future requests. [You must be on a paid plan to use this - endpoint] + latency. Args: domain: Domain name to prefetch brand data for @@ -227,9 +221,7 @@ async def prefetch_by_email( Signal that you may fetch brand data for a particular domain soon to improve latency. This endpoint accepts an email address, extracts the domain from it, validates that it's not a disposable or free email provider, and queues the - domain for prefetching. This endpoint does not charge credits and is available - for paid customers to optimize future requests. [You must be on a paid plan to - use this endpoint] + domain for prefetching. Args: email: Email address to prefetch brand data for. The domain will be extracted from the From 307b4236cd18f463adf6bf4a54fef97e6137aee9 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 26 Apr 2026 19:23:08 +0000 Subject: [PATCH 3/8] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 20d2c16..6707347 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 22 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-0f4b818ec07eb384832ac53f99b79eb59b0af5246209c6954c416148c8f0b5c0.yml -openapi_spec_hash: 08043c0ff1dea4cb8f0c5e54368a84c4 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-91dbd4c6ac7e59beea9c160c063dbcc54ab6375444833f1da0d38a3e6c182384.yml +openapi_spec_hash: 5a827539bca2813c6d0d2bba2c3301a2 config_hash: 70354330f92ce169beabc98696ebb9a3 From c24a18236e7f9a4c9d84d6ead4ec0fecbdcf77fc Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 26 Apr 2026 23:26:21 +0000 Subject: [PATCH 4/8] feat(api): api update --- .stats.yml | 4 +-- src/context/dev/resources/ai.py | 36 +++++++++++++++++++ .../dev/types/ai_extract_product_params.py | 7 ++++ .../dev/types/ai_extract_products_params.py | 14 ++++++++ tests/api_resources/test_ai.py | 6 ++++ 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 6707347..5ceb808 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 22 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-91dbd4c6ac7e59beea9c160c063dbcc54ab6375444833f1da0d38a3e6c182384.yml -openapi_spec_hash: 5a827539bca2813c6d0d2bba2c3301a2 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-d5ca4cac056c38a1cb69c6d9033abe0d2b4d5858ee9a76e1172b23649ab1cca6.yml +openapi_spec_hash: 8e1dd204746bcfaaf637d93b1d339eb2 config_hash: 70354330f92ce169beabc98696ebb9a3 diff --git a/src/context/dev/resources/ai.py b/src/context/dev/resources/ai.py index 6d7aebe..2979380 100644 --- a/src/context/dev/resources/ai.py +++ b/src/context/dev/resources/ai.py @@ -106,6 +106,7 @@ def extract_product( self, *, url: str, + max_age_ms: int | Omit = omit, timeout_ms: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -121,6 +122,10 @@ def extract_product( Args: url: The product page URL to extract product data from. + max_age_ms: Return a cached result if a prior scrape for the same parameters exists and is + younger than this many milliseconds. Defaults to 7 days (604800000 ms) when + omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + timeout_ms: Optional timeout in milliseconds for the request. Maximum allowed value is 300000ms (5 minutes). @@ -137,6 +142,7 @@ def extract_product( body=maybe_transform( { "url": url, + "max_age_ms": max_age_ms, "timeout_ms": timeout_ms, }, ai_extract_product_params.AIExtractProductParams, @@ -152,6 +158,7 @@ def extract_products( self, *, domain: str, + max_age_ms: int | Omit = omit, max_products: int | Omit = omit, timeout_ms: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. @@ -170,6 +177,10 @@ def extract_products( Args: domain: The domain name to analyze. + max_age_ms: Return a cached result if a prior scrape for the same parameters exists and is + younger than this many milliseconds. Defaults to 7 days (604800000 ms) when + omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + max_products: Maximum number of products to extract. timeout_ms: Optional timeout in milliseconds for the request. Maximum allowed value is @@ -190,6 +201,7 @@ def extract_products( self, *, direct_url: str, + max_age_ms: int | Omit = omit, max_products: int | Omit = omit, timeout_ms: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. @@ -209,6 +221,10 @@ def extract_products( direct_url: A specific URL to use directly as the starting point for extraction without domain resolution. + max_age_ms: Return a cached result if a prior scrape for the same parameters exists and is + younger than this many milliseconds. Defaults to 7 days (604800000 ms) when + omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + max_products: Maximum number of products to extract. timeout_ms: Optional timeout in milliseconds for the request. Maximum allowed value is @@ -229,6 +245,7 @@ def extract_products( self, *, domain: str | Omit = omit, + max_age_ms: int | Omit = omit, max_products: int | Omit = omit, timeout_ms: int | Omit = omit, direct_url: str | Omit = omit, @@ -244,6 +261,7 @@ def extract_products( body=maybe_transform( { "domain": domain, + "max_age_ms": max_age_ms, "max_products": max_products, "timeout_ms": timeout_ms, "direct_url": direct_url, @@ -337,6 +355,7 @@ async def extract_product( self, *, url: str, + max_age_ms: int | Omit = omit, timeout_ms: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -352,6 +371,10 @@ async def extract_product( Args: url: The product page URL to extract product data from. + max_age_ms: Return a cached result if a prior scrape for the same parameters exists and is + younger than this many milliseconds. Defaults to 7 days (604800000 ms) when + omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + timeout_ms: Optional timeout in milliseconds for the request. Maximum allowed value is 300000ms (5 minutes). @@ -368,6 +391,7 @@ async def extract_product( body=await async_maybe_transform( { "url": url, + "max_age_ms": max_age_ms, "timeout_ms": timeout_ms, }, ai_extract_product_params.AIExtractProductParams, @@ -383,6 +407,7 @@ async def extract_products( self, *, domain: str, + max_age_ms: int | Omit = omit, max_products: int | Omit = omit, timeout_ms: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. @@ -401,6 +426,10 @@ async def extract_products( Args: domain: The domain name to analyze. + max_age_ms: Return a cached result if a prior scrape for the same parameters exists and is + younger than this many milliseconds. Defaults to 7 days (604800000 ms) when + omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + max_products: Maximum number of products to extract. timeout_ms: Optional timeout in milliseconds for the request. Maximum allowed value is @@ -421,6 +450,7 @@ async def extract_products( self, *, direct_url: str, + max_age_ms: int | Omit = omit, max_products: int | Omit = omit, timeout_ms: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. @@ -440,6 +470,10 @@ async def extract_products( direct_url: A specific URL to use directly as the starting point for extraction without domain resolution. + max_age_ms: Return a cached result if a prior scrape for the same parameters exists and is + younger than this many milliseconds. Defaults to 7 days (604800000 ms) when + omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + max_products: Maximum number of products to extract. timeout_ms: Optional timeout in milliseconds for the request. Maximum allowed value is @@ -460,6 +494,7 @@ async def extract_products( self, *, domain: str | Omit = omit, + max_age_ms: int | Omit = omit, max_products: int | Omit = omit, timeout_ms: int | Omit = omit, direct_url: str | Omit = omit, @@ -475,6 +510,7 @@ async def extract_products( body=await async_maybe_transform( { "domain": domain, + "max_age_ms": max_age_ms, "max_products": max_products, "timeout_ms": timeout_ms, "direct_url": direct_url, diff --git a/src/context/dev/types/ai_extract_product_params.py b/src/context/dev/types/ai_extract_product_params.py index b570411..797a1f8 100644 --- a/src/context/dev/types/ai_extract_product_params.py +++ b/src/context/dev/types/ai_extract_product_params.py @@ -13,6 +13,13 @@ class AIExtractProductParams(TypedDict, total=False): url: Required[str] """The product page URL to extract product data from.""" + max_age_ms: Annotated[int, PropertyInfo(alias="maxAgeMs")] + """ + Return a cached result if a prior scrape for the same parameters exists and is + younger than this many milliseconds. Defaults to 7 days (604800000 ms) when + omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + """ + timeout_ms: Annotated[int, PropertyInfo(alias="timeoutMS")] """Optional timeout in milliseconds for the request. diff --git a/src/context/dev/types/ai_extract_products_params.py b/src/context/dev/types/ai_extract_products_params.py index 1aaa868..62d4a18 100644 --- a/src/context/dev/types/ai_extract_products_params.py +++ b/src/context/dev/types/ai_extract_products_params.py @@ -14,6 +14,13 @@ class ByDomain(TypedDict, total=False): domain: Required[str] """The domain name to analyze.""" + max_age_ms: Annotated[int, PropertyInfo(alias="maxAgeMs")] + """ + Return a cached result if a prior scrape for the same parameters exists and is + younger than this many milliseconds. Defaults to 7 days (604800000 ms) when + omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + """ + max_products: Annotated[int, PropertyInfo(alias="maxProducts")] """Maximum number of products to extract.""" @@ -31,6 +38,13 @@ class ByDirectURL(TypedDict, total=False): domain resolution. """ + max_age_ms: Annotated[int, PropertyInfo(alias="maxAgeMs")] + """ + Return a cached result if a prior scrape for the same parameters exists and is + younger than this many milliseconds. Defaults to 7 days (604800000 ms) when + omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh. + """ + max_products: Annotated[int, PropertyInfo(alias="maxProducts")] """Maximum number of products to extract.""" diff --git a/tests/api_resources/test_ai.py b/tests/api_resources/test_ai.py index 8dd7e51..4635049 100644 --- a/tests/api_resources/test_ai.py +++ b/tests/api_resources/test_ai.py @@ -125,6 +125,7 @@ def test_method_extract_product(self, client: ContextDev) -> None: def test_method_extract_product_with_all_params(self, client: ContextDev) -> None: ai = client.ai.extract_product( url="https://example.com", + max_age_ms=0, timeout_ms=1000, ) assert_matches_type(AIExtractProductResponse, ai, path=["response"]) @@ -168,6 +169,7 @@ def test_method_extract_products_overload_1(self, client: ContextDev) -> None: def test_method_extract_products_with_all_params_overload_1(self, client: ContextDev) -> None: ai = client.ai.extract_products( domain="domain", + max_age_ms=0, max_products=1, timeout_ms=1000, ) @@ -212,6 +214,7 @@ def test_method_extract_products_overload_2(self, client: ContextDev) -> None: def test_method_extract_products_with_all_params_overload_2(self, client: ContextDev) -> None: ai = client.ai.extract_products( direct_url="https://example.com", + max_age_ms=0, max_products=1, timeout_ms=1000, ) @@ -353,6 +356,7 @@ async def test_method_extract_product(self, async_client: AsyncContextDev) -> No async def test_method_extract_product_with_all_params(self, async_client: AsyncContextDev) -> None: ai = await async_client.ai.extract_product( url="https://example.com", + max_age_ms=0, timeout_ms=1000, ) assert_matches_type(AIExtractProductResponse, ai, path=["response"]) @@ -396,6 +400,7 @@ async def test_method_extract_products_overload_1(self, async_client: AsyncConte async def test_method_extract_products_with_all_params_overload_1(self, async_client: AsyncContextDev) -> None: ai = await async_client.ai.extract_products( domain="domain", + max_age_ms=0, max_products=1, timeout_ms=1000, ) @@ -440,6 +445,7 @@ async def test_method_extract_products_overload_2(self, async_client: AsyncConte async def test_method_extract_products_with_all_params_overload_2(self, async_client: AsyncContextDev) -> None: ai = await async_client.ai.extract_products( direct_url="https://example.com", + max_age_ms=0, max_products=1, timeout_ms=1000, ) From 95fd70ecf76c50261f4224b688584ae7ff8b52af Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2026 02:14:33 +0000 Subject: [PATCH 5/8] fix: use correct field name format for multipart file arrays --- src/context/dev/_qs.py | 8 ++---- src/context/dev/_types.py | 3 +++ src/context/dev/_utils/_utils.py | 42 ++++++++++++++++++++++++++------ tests/test_extract_files.py | 28 +++++++++++++++++---- tests/test_files.py | 2 +- 5 files changed, 63 insertions(+), 20 deletions(-) diff --git a/src/context/dev/_qs.py b/src/context/dev/_qs.py index de8c99b..4127c19 100644 --- a/src/context/dev/_qs.py +++ b/src/context/dev/_qs.py @@ -2,17 +2,13 @@ from typing import Any, List, Tuple, Union, Mapping, TypeVar from urllib.parse import parse_qs, urlencode -from typing_extensions import Literal, get_args +from typing_extensions import get_args -from ._types import NotGiven, not_given +from ._types import NotGiven, ArrayFormat, NestedFormat, not_given from ._utils import flatten _T = TypeVar("_T") - -ArrayFormat = Literal["comma", "repeat", "indices", "brackets"] -NestedFormat = Literal["dots", "brackets"] - PrimitiveData = Union[str, int, float, bool, None] # this should be Data = Union[PrimitiveData, "List[Data]", "Tuple[Data]", "Mapping[str, Data]"] # https://github.com/microsoft/pyright/issues/3555 diff --git a/src/context/dev/_types.py b/src/context/dev/_types.py index 18b8e26..a10ca9d 100644 --- a/src/context/dev/_types.py +++ b/src/context/dev/_types.py @@ -47,6 +47,9 @@ ModelT = TypeVar("ModelT", bound=pydantic.BaseModel) _T = TypeVar("_T") +ArrayFormat = Literal["comma", "repeat", "indices", "brackets"] +NestedFormat = Literal["dots", "brackets"] + # Approximates httpx internal ProxiesTypes and RequestFiles types # while adding support for `PathLike` instances diff --git a/src/context/dev/_utils/_utils.py b/src/context/dev/_utils/_utils.py index 771859f..199cd23 100644 --- a/src/context/dev/_utils/_utils.py +++ b/src/context/dev/_utils/_utils.py @@ -17,11 +17,11 @@ ) from pathlib import Path from datetime import date, datetime -from typing_extensions import TypeGuard +from typing_extensions import TypeGuard, get_args import sniffio -from .._types import Omit, NotGiven, FileTypes, HeadersLike +from .._types import Omit, NotGiven, FileTypes, ArrayFormat, HeadersLike _T = TypeVar("_T") _TupleT = TypeVar("_TupleT", bound=Tuple[object, ...]) @@ -40,25 +40,45 @@ def extract_files( query: Mapping[str, object], *, paths: Sequence[Sequence[str]], + array_format: ArrayFormat = "brackets", ) -> list[tuple[str, FileTypes]]: """Recursively extract files from the given dictionary based on specified paths. A path may look like this ['foo', 'files', '', 'data']. + ``array_format`` controls how ```` segments contribute to the emitted + field name. Supported values: ``"brackets"`` (``foo[]``), ``"repeat"`` and + ``"comma"`` (``foo``), ``"indices"`` (``foo[0]``, ``foo[1]``). + Note: this mutates the given dictionary. """ files: list[tuple[str, FileTypes]] = [] for path in paths: - files.extend(_extract_items(query, path, index=0, flattened_key=None)) + files.extend(_extract_items(query, path, index=0, flattened_key=None, array_format=array_format)) return files +def _array_suffix(array_format: ArrayFormat, array_index: int) -> str: + if array_format == "brackets": + return "[]" + if array_format == "indices": + return f"[{array_index}]" + if array_format == "repeat" or array_format == "comma": + # Both repeat the bare field name for each file part; there is no + # meaningful way to comma-join binary parts. + return "" + raise NotImplementedError( + f"Unknown array_format value: {array_format}, choose from {', '.join(get_args(ArrayFormat))}" + ) + + def _extract_items( obj: object, path: Sequence[str], *, index: int, flattened_key: str | None, + array_format: ArrayFormat, ) -> list[tuple[str, FileTypes]]: try: key = path[index] @@ -75,9 +95,11 @@ def _extract_items( if is_list(obj): files: list[tuple[str, FileTypes]] = [] - for entry in obj: - assert_is_file_content(entry, key=flattened_key + "[]" if flattened_key else "") - files.append((flattened_key + "[]", cast(FileTypes, entry))) + for array_index, entry in enumerate(obj): + suffix = _array_suffix(array_format, array_index) + emitted_key = (flattened_key + suffix) if flattened_key else suffix + assert_is_file_content(entry, key=emitted_key) + files.append((emitted_key, cast(FileTypes, entry))) return files assert_is_file_content(obj, key=flattened_key) @@ -106,6 +128,7 @@ def _extract_items( path, index=index, flattened_key=flattened_key, + array_format=array_format, ) elif is_list(obj): if key != "": @@ -117,9 +140,12 @@ def _extract_items( item, path, index=index, - flattened_key=flattened_key + "[]" if flattened_key is not None else "[]", + flattened_key=( + (flattened_key if flattened_key is not None else "") + _array_suffix(array_format, array_index) + ), + array_format=array_format, ) - for item in obj + for array_index, item in enumerate(obj) ] ) diff --git a/tests/test_extract_files.py b/tests/test_extract_files.py index 34b6253..bfeb671 100644 --- a/tests/test_extract_files.py +++ b/tests/test_extract_files.py @@ -4,7 +4,7 @@ import pytest -from context.dev._types import FileTypes +from context.dev._types import FileTypes, ArrayFormat from context.dev._utils import extract_files @@ -37,10 +37,7 @@ def test_multiple_files() -> None: def test_top_level_file_array() -> None: query = {"files": [b"file one", b"file two"], "title": "hello"} - assert extract_files(query, paths=[["files", ""]]) == [ - ("files[]", b"file one"), - ("files[]", b"file two"), - ] + assert extract_files(query, paths=[["files", ""]]) == [("files[]", b"file one"), ("files[]", b"file two")] assert query == {"title": "hello"} @@ -71,3 +68,24 @@ def test_ignores_incorrect_paths( expected: list[tuple[str, FileTypes]], ) -> None: assert extract_files(query, paths=paths) == expected + + +@pytest.mark.parametrize( + "array_format,expected_top_level,expected_nested", + [ + ("brackets", [("files[]", b"a"), ("files[]", b"b")], [("items[][file]", b"a"), ("items[][file]", b"b")]), + ("repeat", [("files", b"a"), ("files", b"b")], [("items[file]", b"a"), ("items[file]", b"b")]), + ("comma", [("files", b"a"), ("files", b"b")], [("items[file]", b"a"), ("items[file]", b"b")]), + ("indices", [("files[0]", b"a"), ("files[1]", b"b")], [("items[0][file]", b"a"), ("items[1][file]", b"b")]), + ], +) +def test_array_format_controls_file_field_names( + array_format: ArrayFormat, + expected_top_level: list[tuple[str, FileTypes]], + expected_nested: list[tuple[str, FileTypes]], +) -> None: + top_level = {"files": [b"a", b"b"]} + assert extract_files(top_level, paths=[["files", ""]], array_format=array_format) == expected_top_level + + nested = {"items": [{"file": b"a"}, {"file": b"b"}]} + assert extract_files(nested, paths=[["items", "", "file"]], array_format=array_format) == expected_nested diff --git a/tests/test_files.py b/tests/test_files.py index e9e3a2d..840a361 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -131,7 +131,7 @@ def test_extract_files_does_not_mutate_original_nested_array_path(self) -> None: copied = deepcopy_with_paths(original, [["items", "", "file"]]) extracted = extract_files(copied, paths=[["items", "", "file"]]) - assert extracted == [("items[][file]", file1), ("items[][file]", file2)] + assert [entry for _, entry in extracted] == [file1, file2] assert original == { "items": [ {"file": file1, "extra": 1}, From 90d2e4e449b1af9541881775c771969d37f3a6f1 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2026 02:15:32 +0000 Subject: [PATCH 6/8] feat: support setting headers via env --- src/context/dev/_client.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/context/dev/_client.py b/src/context/dev/_client.py index ace042b..511e025 100644 --- a/src/context/dev/_client.py +++ b/src/context/dev/_client.py @@ -19,7 +19,11 @@ RequestOptions, not_given, ) -from ._utils import is_given, get_async_library +from ._utils import ( + is_given, + is_mapping_t, + get_async_library, +) from ._compat import cached_property from ._version import __version__ from ._streaming import Stream as Stream, AsyncStream as AsyncStream @@ -94,6 +98,15 @@ def __init__( if base_url is None: base_url = f"https://api.context.dev/v1" + custom_headers_env = os.environ.get("CONTEXT_DEV_CUSTOM_HEADERS") + if custom_headers_env is not None: + parsed: dict[str, str] = {} + for line in custom_headers_env.split("\n"): + colon = line.find(":") + if colon >= 0: + parsed[line[:colon].strip()] = line[colon + 1 :].strip() + default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})} + super().__init__( version=__version__, base_url=base_url, @@ -292,6 +305,15 @@ def __init__( if base_url is None: base_url = f"https://api.context.dev/v1" + custom_headers_env = os.environ.get("CONTEXT_DEV_CUSTOM_HEADERS") + if custom_headers_env is not None: + parsed: dict[str, str] = {} + for line in custom_headers_env.split("\n"): + colon = line.find(":") + if colon >= 0: + parsed[line[:colon].strip()] = line[colon + 1 :].strip() + default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})} + super().__init__( version=__version__, base_url=base_url, From aa67822eb3c2bbd78e1553d3ecb779174fb4c10e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 30 Apr 2026 07:10:01 +0000 Subject: [PATCH 7/8] codegen metadata --- .stats.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.stats.yml b/.stats.yml index 5ceb808..adf31eb 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 22 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev%2Fcontext.dev-d5ca4cac056c38a1cb69c6d9033abe0d2b4d5858ee9a76e1172b23649ab1cca6.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d5ca4cac056c38a1cb69c6d9033abe0d2b4d5858ee9a76e1172b23649ab1cca6.yml openapi_spec_hash: 8e1dd204746bcfaaf637d93b1d339eb2 config_hash: 70354330f92ce169beabc98696ebb9a3 From 710ef71d9472e524a7d184e9afe873324a63770e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 30 Apr 2026 07:10:24 +0000 Subject: [PATCH 8/8] release: 0.13.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 15 +++++++++++++++ pyproject.toml | 2 +- src/context/dev/_version.py | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index a713055..d52d2b9 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.12.0" + ".": "0.13.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a982e33..7ef33de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 0.13.0 (2026-04-30) + +Full Changelog: [v0.12.0...v0.13.0](https://github.com/context-dot-dev/context-python-sdk/compare/v0.12.0...v0.13.0) + +### Features + +* **api:** api update ([c24a182](https://github.com/context-dot-dev/context-python-sdk/commit/c24a18236e7f9a4c9d84d6ead4ec0fecbdcf77fc)) +* **api:** api update ([c9c388e](https://github.com/context-dot-dev/context-python-sdk/commit/c9c388ecb41827df93f98ac8aa3c8f5ce754a13e)) +* support setting headers via env ([90d2e4e](https://github.com/context-dot-dev/context-python-sdk/commit/90d2e4e449b1af9541881775c771969d37f3a6f1)) + + +### Bug Fixes + +* use correct field name format for multipart file arrays ([95fd70e](https://github.com/context-dot-dev/context-python-sdk/commit/95fd70ecf76c50261f4224b688584ae7ff8b52af)) + ## 0.12.0 (2026-04-25) Full Changelog: [v0.11.0...v0.12.0](https://github.com/context-dot-dev/context-python-sdk/compare/v0.11.0...v0.12.0) diff --git a/pyproject.toml b/pyproject.toml index acf5906..944eeb0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "context.dev" -version = "0.12.0" +version = "0.13.0" description = "The official Python library for the context.dev API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/context/dev/_version.py b/src/context/dev/_version.py index b052e1c..8b0c2d1 100644 --- a/src/context/dev/_version.py +++ b/src/context/dev/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "context.dev" -__version__ = "0.12.0" # x-release-please-version +__version__ = "0.13.0" # x-release-please-version