Repository navigation
Google: link_token on search results, search.resolve() and resolve_all() (0.82.0) (SCR-667) - #107
Merged
Merged
Conversation
…l() (0.82.0) (SCR-667)
- google.search.resolve(results): one POST /v1/google/resolve with
{"results": [...]}. Returns the response dict unchanged. Costs no credits.
- google.search.resolve_all(results, *, max_wait=240.0): sends the rows that
have a link_token, at most 25 per request, sleeps the smallest
retry_after_seconds returned (at least 1 second, never past max_wait) and
repeats until no row is waiting or max_wait has passed. Returns a new list
in the input order and does not change the input. Rows still not ready at
max_wait are returned with their latest link_token and retry_after_seconds;
no exception is raised. Rows with an error and rows without a link_token
are not sent.
- search() and light() docstrings, docs/google.md, README and CHANGELOG
describe link_token and retry_after_seconds on organic_results.
- Version 0.82.0 in pyproject, SDK_VERSION, __version__ and uv.lock.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
google.search.search()andgoogle.search.light()responses, anorganic_resultsitem whoselinkis still a Google redirect (https://www.google.com/goto?url=...) now haslink_token(string) andretry_after_seconds(int, 0 = can be resolved right away). Both areNonewhenlinkis already the real URL. These responses are plain dicts, so the fields pass through with no code change. The docstrings and docs now describe them.google.search.resolve(results)(new). OnePOST /v1/google/resolvewith{"results": [...]}. Returns the response dict unchanged:{"results": [...], "retry_after_seconds": int | None}. No client-side validation. Costs no credits.google.search.resolve_all(results, *, max_wait=240.0)(new). A loop aroundresolve:link_tokenand noerror, at most 25 per request.retry_after_secondsreturned (at least 1 second, never pastmax_wait), then sends the rows that are still not ready, with their latest token.max_waitseconds have passed. Rows that are still not ready are returned with their latestlink_tokenandretry_after_seconds. No exception is raised for them.link_tokenare returned as they are and never sent. The input list and its dicts are not changed. The result is a new list.docs/google.md: the two new organic fields,resolveandresolve_allin the Methods table, a "Resolving result links" section with a runnable example and the meaning of each row state, and a 0-credit row in the cost table. One line inREADME.md. NewCHANGELOG.mdentry.pyproject.toml,SDK_VERSION,__version__anduv.lock.No existing signature changes. Nothing inside a generated block was edited.
How it was tested
uv run pytest --ignore=tests/e2e: 1022 passed, 0 failed.tests/test_google.pyhas 65 tests, 13 of them new:resolveposts{"results": [...]}to/v1/google/resolveand returns the dict.resolve_all: resolved on the first call; a row that is not ready is sent again with the new token after sleeping the returned wait; a wait of 0 or no wait becomes 1 second; a failed row is returned and not sent again; a row that already haserroris never sent; 60 rows go out as 25, 25 and 10; with several requests the smallest wait is used; at the deadline the last sleep is cut, the rows come back with their latest tokens and nothing is raised;max_wait=0sends each row once; rows withoutlink_tokenare never sent and keep their position; nothing to resolve makes no request; the input is not mutated.uv run pytestwith no API key set: 1022 passed, 77 skipped. The 77 aretests/e2e, which call the live API.uv run ruff check src/ tests/: all checks passed.uv run ruff format --check src/ tests/: 308 files already formatted.uv run mypy src/: no issues found in 257 source files.Release
Do not release before POST /v1/google/resolve is live.
🤖 Generated with Claude Code