From 1aa99f71f83593bb9822fd5aa8d84f80f932971f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 12 Jul 2026 19:47:24 +0000 Subject: [PATCH 1/2] feat(api): api update --- .stats.yml | 4 +- README.md | 10 +- src/context/dev/resources/parse.py | 229 +++++++++++++++---- src/context/dev/types/parse_handle_params.py | 135 ++++++++--- tests/api_resources/test_parse.py | 20 +- 5 files changed, 300 insertions(+), 98 deletions(-) diff --git a/.stats.yml b/.stats.yml index 1ba5348..7cfdbba 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 30 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c90f13e3cf4b9ae6a1d8f22c0e7285ab12d412d3a659a51a247a97adc7f08121.yml -openapi_spec_hash: bf7879be38ebf3397a939c80b261a47a +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-fb56935a194e69348fecd985f7cf8b249795b46af2fb32f6c5c8ef648cf10c15.yml +openapi_spec_hash: 7260a560474283b7ad6ac5d426058ac9 config_hash: daabb160675d86b354711da1e77e5129 diff --git a/README.md b/README.md index 98acec8..04149d0 100644 --- a/README.md +++ b/README.md @@ -133,14 +133,8 @@ from context.dev import ContextDev client = ContextDev() -response = client.web.extract( - schema={ - "type": "bar", - "properties": "bar", - "required": "bar", - "additionalProperties": "bar", - }, - url="https://example.com", +response = client.parse.handle( + body=b"Example data", pdf={}, ) print(response.pdf) diff --git a/src/context/dev/resources/parse.py b/src/context/dev/resources/parse.py index 16aa7a0..460660f 100644 --- a/src/context/dev/resources/parse.py +++ b/src/context/dev/resources/parse.py @@ -3,6 +3,7 @@ from __future__ import annotations import os +from typing_extensions import Literal import httpx @@ -59,14 +60,83 @@ def handle( self, body: FileContent | BinaryTypes, *, - base_url: str | Omit = omit, - extension: str | Omit = omit, - filename: str | Omit = omit, + extension: Literal[ + "txt", + "text", + "md", + "markdown", + "html", + "htm", + "xhtml", + "xml", + "rss", + "atom", + "csv", + "tsv", + "yaml", + "yml", + "py", + "java", + "js", + "jsx", + "mjs", + "cjs", + "json", + "jsonl", + "ndjson", + "php", + "sh", + "bash", + "zsh", + "fish", + "rb", + "ts", + "tsx", + "rtf", + "srt", + "css", + "scss", + "less", + "styl", + "sass", + "svg", + "pdf", + "docx", + "doc", + "xlsx", + "xlsm", + "xlsb", + "xltx", + "xltm", + "xls", + "pptx", + "pptm", + "ppsx", + "ppsm", + "potx", + "potm", + "ppt", + "pps", + "pot", + "jpg", + "jpeg", + "jpe", + "png", + "gif", + "bmp", + "tiff", + "tif", + "webp", + "ppm", + "pbm", + "pgm", + "pnm", + ] + | Omit = omit, include_images: bool | Omit = omit, include_links: bool | Omit = omit, ocr: bool | Omit = omit, - pdf_end: int | Omit = omit, - pdf_start: int | Omit = omit, + pdf: parse_handle_params.Pdf | Omit = omit, shorten_base64_images: bool | Omit = omit, use_main_content_only: bool | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. @@ -78,30 +148,28 @@ def handle( ) -> ParseHandleResponse: """ Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes - into LLM-usable Markdown. + into LLM-usable Markdown. The base request costs 1 credit. When OCR runs + (requires ocr=true), the entire call costs 5 credits; ocr=true requests where no + OCR ends up running still cost 1 credit. Args: - base_url: Optional HTTP(S) source document URL used to resolve relative links and image - references. Relative references remain relative when omitted. - - extension: Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, - md, py, rtf, jpg, png, or txt. - - filename: Optional filename hint used to infer the extension when extension is omitted. + extension: Optional file extension hint. Case-insensitive; a leading dot is accepted (e.g. + ".pdf"). include_images: Include image references in Markdown output include_links: Preserve hyperlinks in Markdown output - ocr: When true for PDF inputs, detect and OCR images embedded in the selected pages, - inserting recognized text at each image's position in page reading order while - preserving the PDF text layer. pdfStart/pdfEnd limit the inclusive page range. - This is separate from automatic scanned-PDF OCR fallback. - - pdf_end: Last 1-based PDF page to parse. When omitted, parsing ends at the last page. - Must be greater than or equal to pdfStart when both are provided. + ocr: Gates all OCR. When true, PDFs get embedded-image OCR (recognized text inserted + at each image's position in page reading order, preserving the text layer; + pdf.start/pdf.end limit the page range), scanned PDFs with no text layer get + full-document OCR, and raster images get their visible text transcribed. When + false, no OCR runs: scanned PDFs may yield no content and images return only + format/dimension metadata. Calls where OCR actually runs cost 5 credits instead + of 1. - pdf_start: First 1-based PDF page to parse. When omitted, parsing starts at the first page. + pdf: PDF page-range controls. Use start/end to limit parsing (and OCR when ocr=true) + to an inclusive 1-based page range. shorten_base64_images: Shorten base64-encoded image data in the Markdown output @@ -126,14 +194,11 @@ def handle( timeout=timeout, query=maybe_transform( { - "base_url": base_url, "extension": extension, - "filename": filename, "include_images": include_images, "include_links": include_links, "ocr": ocr, - "pdf_end": pdf_end, - "pdf_start": pdf_start, + "pdf": pdf, "shorten_base64_images": shorten_base64_images, "use_main_content_only": use_main_content_only, }, @@ -168,14 +233,83 @@ async def handle( self, body: FileContent | AsyncBinaryTypes, *, - base_url: str | Omit = omit, - extension: str | Omit = omit, - filename: str | Omit = omit, + extension: Literal[ + "txt", + "text", + "md", + "markdown", + "html", + "htm", + "xhtml", + "xml", + "rss", + "atom", + "csv", + "tsv", + "yaml", + "yml", + "py", + "java", + "js", + "jsx", + "mjs", + "cjs", + "json", + "jsonl", + "ndjson", + "php", + "sh", + "bash", + "zsh", + "fish", + "rb", + "ts", + "tsx", + "rtf", + "srt", + "css", + "scss", + "less", + "styl", + "sass", + "svg", + "pdf", + "docx", + "doc", + "xlsx", + "xlsm", + "xlsb", + "xltx", + "xltm", + "xls", + "pptx", + "pptm", + "ppsx", + "ppsm", + "potx", + "potm", + "ppt", + "pps", + "pot", + "jpg", + "jpeg", + "jpe", + "png", + "gif", + "bmp", + "tiff", + "tif", + "webp", + "ppm", + "pbm", + "pgm", + "pnm", + ] + | Omit = omit, include_images: bool | Omit = omit, include_links: bool | Omit = omit, ocr: bool | Omit = omit, - pdf_end: int | Omit = omit, - pdf_start: int | Omit = omit, + pdf: parse_handle_params.Pdf | Omit = omit, shorten_base64_images: bool | Omit = omit, use_main_content_only: bool | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. @@ -187,30 +321,28 @@ async def handle( ) -> ParseHandleResponse: """ Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes - into LLM-usable Markdown. + into LLM-usable Markdown. The base request costs 1 credit. When OCR runs + (requires ocr=true), the entire call costs 5 credits; ocr=true requests where no + OCR ends up running still cost 1 credit. Args: - base_url: Optional HTTP(S) source document URL used to resolve relative links and image - references. Relative references remain relative when omitted. - - extension: Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, - md, py, rtf, jpg, png, or txt. - - filename: Optional filename hint used to infer the extension when extension is omitted. + extension: Optional file extension hint. Case-insensitive; a leading dot is accepted (e.g. + ".pdf"). include_images: Include image references in Markdown output include_links: Preserve hyperlinks in Markdown output - ocr: When true for PDF inputs, detect and OCR images embedded in the selected pages, - inserting recognized text at each image's position in page reading order while - preserving the PDF text layer. pdfStart/pdfEnd limit the inclusive page range. - This is separate from automatic scanned-PDF OCR fallback. - - pdf_end: Last 1-based PDF page to parse. When omitted, parsing ends at the last page. - Must be greater than or equal to pdfStart when both are provided. + ocr: Gates all OCR. When true, PDFs get embedded-image OCR (recognized text inserted + at each image's position in page reading order, preserving the text layer; + pdf.start/pdf.end limit the page range), scanned PDFs with no text layer get + full-document OCR, and raster images get their visible text transcribed. When + false, no OCR runs: scanned PDFs may yield no content and images return only + format/dimension metadata. Calls where OCR actually runs cost 5 credits instead + of 1. - pdf_start: First 1-based PDF page to parse. When omitted, parsing starts at the first page. + pdf: PDF page-range controls. Use start/end to limit parsing (and OCR when ocr=true) + to an inclusive 1-based page range. shorten_base64_images: Shorten base64-encoded image data in the Markdown output @@ -235,14 +367,11 @@ async def handle( timeout=timeout, query=await async_maybe_transform( { - "base_url": base_url, "extension": extension, - "filename": filename, "include_images": include_images, "include_links": include_links, "ocr": ocr, - "pdf_end": pdf_end, - "pdf_start": pdf_start, + "pdf": pdf, "shorten_base64_images": shorten_base64_images, "use_main_content_only": use_main_content_only, }, diff --git a/src/context/dev/types/parse_handle_params.py b/src/context/dev/types/parse_handle_params.py index 78bd93a..2acfa4f 100644 --- a/src/context/dev/types/parse_handle_params.py +++ b/src/context/dev/types/parse_handle_params.py @@ -2,28 +2,90 @@ from __future__ import annotations -from typing_extensions import Annotated, TypedDict +from typing_extensions import Literal, Annotated, TypedDict from .._utils import PropertyInfo -__all__ = ["ParseHandleParams"] +__all__ = ["ParseHandleParams", "Pdf"] class ParseHandleParams(TypedDict, total=False): - base_url: Annotated[str, PropertyInfo(alias="baseUrl")] + extension: Literal[ + "txt", + "text", + "md", + "markdown", + "html", + "htm", + "xhtml", + "xml", + "rss", + "atom", + "csv", + "tsv", + "yaml", + "yml", + "py", + "java", + "js", + "jsx", + "mjs", + "cjs", + "json", + "jsonl", + "ndjson", + "php", + "sh", + "bash", + "zsh", + "fish", + "rb", + "ts", + "tsx", + "rtf", + "srt", + "css", + "scss", + "less", + "styl", + "sass", + "svg", + "pdf", + "docx", + "doc", + "xlsx", + "xlsm", + "xlsb", + "xltx", + "xltm", + "xls", + "pptx", + "pptm", + "ppsx", + "ppsm", + "potx", + "potm", + "ppt", + "pps", + "pot", + "jpg", + "jpeg", + "jpe", + "png", + "gif", + "bmp", + "tiff", + "tif", + "webp", + "ppm", + "pbm", + "pgm", + "pnm", + ] + """Optional file extension hint. + + Case-insensitive; a leading dot is accepted (e.g. ".pdf"). """ - Optional HTTP(S) source document URL used to resolve relative links and image - references. Relative references remain relative when omitted. - """ - - extension: str - """ - Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, - md, py, rtf, jpg, png, or txt. - """ - - filename: str - """Optional filename hint used to infer the extension when extension is omitted.""" include_images: Annotated[bool, PropertyInfo(alias="includeImages")] """Include image references in Markdown output""" @@ -32,28 +94,45 @@ class ParseHandleParams(TypedDict, total=False): """Preserve hyperlinks in Markdown output""" ocr: bool + """Gates all OCR. + + When true, PDFs get embedded-image OCR (recognized text inserted at each image's + position in page reading order, preserving the text layer; pdf.start/pdf.end + limit the page range), scanned PDFs with no text layer get full-document OCR, + and raster images get their visible text transcribed. When false, no OCR runs: + scanned PDFs may yield no content and images return only format/dimension + metadata. Calls where OCR actually runs cost 5 credits instead of 1. """ - When true for PDF inputs, detect and OCR images embedded in the selected pages, - inserting recognized text at each image's position in page reading order while - preserving the PDF text layer. pdfStart/pdfEnd limit the inclusive page range. - This is separate from automatic scanned-PDF OCR fallback. + + pdf: Pdf + """PDF page-range controls. + + Use start/end to limit parsing (and OCR when ocr=true) to an inclusive 1-based + page range. """ - pdf_end: Annotated[int, PropertyInfo(alias="pdfEnd")] + shorten_base64_images: Annotated[bool, PropertyInfo(alias="shortenBase64Images")] + """Shorten base64-encoded image data in the Markdown output""" + + use_main_content_only: Annotated[bool, PropertyInfo(alias="useMainContentOnly")] + """Extract only the main content from HTML-like inputs""" + + +class Pdf(TypedDict, total=False): + """PDF page-range controls. + + Use start/end to limit parsing (and OCR when ocr=true) to an inclusive 1-based page range. + """ + + end: int """Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to - pdfStart when both are provided. + start when both are provided. """ - pdf_start: Annotated[int, PropertyInfo(alias="pdfStart")] + start: int """First 1-based PDF page to parse. When omitted, parsing starts at the first page. """ - - shorten_base64_images: Annotated[bool, PropertyInfo(alias="shortenBase64Images")] - """Shorten base64-encoded image data in the Markdown output""" - - use_main_content_only: Annotated[bool, PropertyInfo(alias="useMainContentOnly")] - """Extract only the main content from HTML-like inputs""" diff --git a/tests/api_resources/test_parse.py b/tests/api_resources/test_parse.py index f496f1e..4e4654f 100644 --- a/tests/api_resources/test_parse.py +++ b/tests/api_resources/test_parse.py @@ -30,14 +30,14 @@ def test_method_handle(self, client: ContextDev) -> None: def test_method_handle_with_all_params(self, client: ContextDev) -> None: parse = client.parse.handle( body=b"Example data", - base_url="https://example.com", - extension="extension", - filename="filename", + extension="txt", include_images=True, include_links=True, ocr=True, - pdf_end=1, - pdf_start=1, + pdf={ + "end": 1, + "start": 1, + }, shorten_base64_images=True, use_main_content_only=True, ) @@ -88,14 +88,14 @@ async def test_method_handle(self, async_client: AsyncContextDev) -> None: async def test_method_handle_with_all_params(self, async_client: AsyncContextDev) -> None: parse = await async_client.parse.handle( body=b"Example data", - base_url="https://example.com", - extension="extension", - filename="filename", + extension="txt", include_images=True, include_links=True, ocr=True, - pdf_end=1, - pdf_start=1, + pdf={ + "end": 1, + "start": 1, + }, shorten_base64_images=True, use_main_content_only=True, ) From bc1896ae8b1aeca29d785f72ae22942a7f1ff958 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 12 Jul 2026 19:47:48 +0000 Subject: [PATCH 2/2] release: 2.4.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ pyproject.toml | 2 +- src/context/dev/_version.py | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 75ec52f..b44b287 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "2.3.0" + ".": "2.4.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f0de6e..c566b65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 2.4.0 (2026-07-12) + +Full Changelog: [v2.3.0...v2.4.0](https://github.com/context-dot-dev/context-python-sdk/compare/v2.3.0...v2.4.0) + +### Features + +* **api:** api update ([1aa99f7](https://github.com/context-dot-dev/context-python-sdk/commit/1aa99f71f83593bb9822fd5aa8d84f80f932971f)) + ## 2.3.0 (2026-07-12) Full Changelog: [v2.2.0...v2.3.0](https://github.com/context-dot-dev/context-python-sdk/compare/v2.2.0...v2.3.0) diff --git a/pyproject.toml b/pyproject.toml index 56109df..a2037dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "context.dev" -version = "2.3.0" +version = "2.4.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 b5761aa..520d6d8 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__ = "2.3.0" # x-release-please-version +__version__ = "2.4.0" # x-release-please-version