Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix: image search field mapping in Python SDK (#2244)

Neha Prasadcc411b6a3bf3
diff --git a/apps/python-sdk/firecrawl/v2/methods/search.py b/apps/python-sdk/firecrawl/v2/methods/search.py
index 244c07c82..ca434ba6d 100644
--- a/apps/python-sdk/firecrawl/v2/methods/search.py
+++ b/apps/python-sdk/firecrawl/v2/methods/search.py
@@ -5,7 +5,7 @@ Search functionality for Firecrawl v2 API.
import re
from typing import Dict, Any, Union, List, TypeVar, Type
from ..types import SearchRequest, SearchData, Document, SearchResultWeb, SearchResultNews, SearchResultImages
-from ..utils.normalize import normalize_document_input
+from ..utils.normalize import normalize_document_input, _map_search_result_keys
from ..utils import HttpClient, handle_response_error, validate_scrape_options, prepare_scrape_options
T = TypeVar("T")
@@ -73,9 +73,20 @@ def _transform_array(arr: List[Any], result_type: Type[T]) -> List[Union[T, 'Doc
):
results.append(Document(**normalize_document_input(item)))
else:
- results.append(result_type(**item))
+ result_type_name = None
+ if result_type == SearchResultImages:
+ result_type_name = "images"
+ elif result_type == SearchResultNews:
+ result_type_name = "news"
+ elif result_type == SearchResultWeb:
+ result_type_name = "web"
+
+ if result_type_name:
+ normalized_item = _map_search_result_keys(item, result_type_name)
+ results.append(result_type(**normalized_item))
+ else:
+ results.append(result_type(**item))
else:
- # For non-dict items, assume it's a URL and wrap in result_type
results.append(result_type(url=item))
return results
diff --git a/apps/python-sdk/firecrawl/v2/utils/normalize.py b/apps/python-sdk/firecrawl/v2/utils/normalize.py
index b821310d1..2b523c7ec 100644
--- a/apps/python-sdk/firecrawl/v2/utils/normalize.py
+++ b/apps/python-sdk/firecrawl/v2/utils/normalize.py
@@ -112,3 +112,27 @@ def normalize_document_input(doc: Dict[str, Any]) -> Dict[str, Any]:
return normalized
+def _map_search_result_keys(result: Dict[str, Any], result_type: str) -> Dict[str, Any]:
+ if result_type == "images":
+ mapping = {
+ "imageUrl": "image_url",
+ "imageWidth": "image_width",
+ "imageHeight": "image_height",
+ }
+ elif result_type == "news":
+ mapping = {
+ "imageUrl": "image_url",
+ }
+ elif result_type == "web":
+ mapping = {}
+ else:
+ mapping = {}
+
+ out: Dict[str, Any] = {}
+ for k, v in result.items():
+ snake = mapping.get(k, k)
+ out[snake] = v
+
+ return out
+
+