From 759b6f05c28236e4834a606e6bd0f6756466efbd Mon Sep 17 00:00:00 2001 From: Deril Raju <47169600+deril2605@users.noreply.github.com> Date: Wed, 11 Feb 2026 19:45:10 +0530 Subject: [PATCH 1/2] Refactor begin_analyze_binary method Refactor begin_analyze_binary to accept in-memory data or file path. Improve error handling for input parameters. --- python/content_understanding_client.py | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/python/content_understanding_client.py b/python/content_understanding_client.py index 7b7cc68..c63f7ec 100644 --- a/python/content_understanding_client.py +++ b/python/content_understanding_client.py @@ -424,7 +424,7 @@ def get_analyzer_detail_by_id(self, analyzer_id: str) -> Dict[str, Any]: self._raise_for_status_with_detail(response) return response.json() - def begin_create_analyzer( + def _create_analyzer( self, analyzer_id: str, analyzer_template: dict = None, @@ -551,14 +551,15 @@ def begin_analyze_url(self, analyzer_id: str, url: str) -> Response: ) return response - def begin_analyze_binary(self, analyzer_id: str, file_location: str) -> Response: + def begin_analyze_binary(self, analyzer_id: str, file_location: Optional[str] = None, data: Optional[bytes] = None) -> Response: """ Begins the analysis of a single binary file using the specified analyzer. Uses the :analyzeBinary endpoint required by GA API 2025-11-01. Args: analyzer_id (str): The ID of the analyzer to use. - file_location (str): The local path to the file to analyze. + file_location (Optional[str]): Local path to the file to analyze. + data (Optional[bytes]): In-memory file bytes to analyze. Returns: Response: The response from the analysis request. @@ -567,12 +568,20 @@ def begin_analyze_binary(self, analyzer_id: str, file_location: str) -> Response ValueError: If the file location is not a valid file path. HTTPError: If the HTTP request returned an unsuccessful status code. """ - file_path = Path(file_location) - if not file_path.exists() or not file_path.is_file(): - raise ValueError("File location must be a valid file path.") - - with open(file_location, "rb") as file: - file_bytes = file.read() + if (file_location is None and data is None) or (file_location is not None and data is not None): + raise ValueError("Provide exactly one of: file_location or data.") + + if file_location is not None: + file_path = Path(file_location) + if not file_path.exists() or not file_path.is_file(): + raise ValueError("File location must be a valid file path.") + with open(file_path, "rb") as file: + file_bytes = file.read() + else: + # Use in-memory bytes + if not isinstance(data, (bytes, bytearray)) or len(data) == 0: + raise ValueError("data must be non-empty bytes.") + file_bytes = bytes(data) headers = {"Content-Type": "application/octet-stream"} headers.update(self._headers) From 2c73b4caed9853d3589d9c4c4e14fb407c8782a1 Mon Sep 17 00:00:00 2001 From: Deril Raju <47169600+deril2605@users.noreply.github.com> Date: Wed, 11 Feb 2026 19:46:59 +0530 Subject: [PATCH 2/2] fix function name --- python/content_understanding_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/content_understanding_client.py b/python/content_understanding_client.py index c63f7ec..0b0c1c1 100644 --- a/python/content_understanding_client.py +++ b/python/content_understanding_client.py @@ -424,7 +424,7 @@ def get_analyzer_detail_by_id(self, analyzer_id: str) -> Dict[str, Any]: self._raise_for_status_with_detail(response) return response.json() - def _create_analyzer( + def begin_create_analyzer( self, analyzer_id: str, analyzer_template: dict = None,