| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
Adds first-class image upload support to serpapi-python for Google Lens workflows via SerpApi’s /image POST endpoint, enabling users to upload local images and then perform Lens searches using the returned image_id.
Changes:
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file| File | Description |
|---|---|
| tests/test_image_upload.py | Adds unit coverage for multipart upload behavior, input types, and Google Lens URL vs image_id usage. |
| serpapi/http.py | Adjusts API-key injection to support endpoints that authenticate via form data. |
| serpapi/core.py | Implements Client.upload_image(...) and exposes module-level upload_image. |
| README.md | Documents Google Lens usage via URL and via uploaded image_id. |
| docs/index.rst | Exposes upload_image in Sphinx API reference for both module function and Client method. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you @adarshdigievo 👍, mostly looks good!
Sorry, something went wrong.
| def test_google_lens_search_supports_url_and_uploaded_image_id(): | ||
| client = serpapi.Client(api_key="test-api-key") | ||
| client.session.request = Mock( | ||
| side_effect=[ | ||
| json_response(b'{"image_id": "uploaded-image-123"}'), | ||
| json_response(b'{"search_metadata": {"status": "Success"}}'), | ||
| json_response(b'{"search_metadata": {"status": "Success"}}'), | ||
| ] | ||
| ) | ||
|
|
||
| upload = client.upload_image(BytesIO(b"fake-image-data")) | ||
| client.search(engine="google_lens", image_id=upload["image_id"]) | ||
| client.search(engine="google_lens", url="https://example.com/image.png") | ||
|
|
||
| upload_search = client.session.request.call_args_list[1][1]["params"] | ||
| url_search = client.session.request.call_args_list[2][1]["params"] | ||
| assert upload_search["image_id"] == "uploaded-image-123" | ||
| assert "url" not in upload_search | ||
| assert url_search["url"] == "https://example.com/image.png" | ||
| assert "image_id" not in url_search |
There was a problem hiding this comment.
Don't think this tests much. It just asserts the params we passed in, which is self-fulfilling. I think we can remove it.
Sorry, something went wrong.
There was a problem hiding this comment.
@tanysheng Thanks for the review. I removed the test.
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you @adarshdigievo! LGTM 👍
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
This PR adds image-upload support for Google Lens, using the new /image POST endpoint.
Changes
This means users can pass an image path or an open image binary file to upload_image()
Live Tests
Image uploads were verified using the live tests below: