Repository navigation
Add batch async search helper (async_search) - #56
Open
AusafKhan144 wants to merge 3 commits into
Open
AusafKhan144 wants to merge 3 commits into
AusafKhan144 wants to merge 3 commits into
Conversation
This branch has not been deployed
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.
This is a first contribution, addressing #53 ("Make
async: Truebatch searches work out of the box").What it does
Adds
Client.async_search(), which runs a batch of async searches end to end: it submits each search withasync: Truevia the existingClient.search(), then polls the Search Archive API via the existingClient.search_archive()until every search reaches a terminal status (Success,Cached, orError), and returns the results as a list in the same order as the input. Archive polls send onlysearch_id, as the issue notes — reusing the original params makes the Archive API error.API
client.async_search(queries=["burly", "creator", "doubtful", "minecraft"], engine="youtube", device="desktop")— the shape proposed in the issue works verbatim; shared kwargs apply to every search.searches=[{...}, ...]) for batches that mix engines or params; per-search values win over shared kwargs. Plain strings are shorthand for{"q": item}.asyncio.gather(return_exceptions=True)) instead of sinking the whole batch.Error-status searches return theirSerpResults, which carry the API's error message.poll_interval(default 1s) andtimeout(default 300s;Nonewaits indefinitely) are keyword-only. Caller dicts are never mutated.Tests
11 new tests in
tests/test_async_search.py(mocked HTTP, in the repo's existing style) covering: all succeed, order preservation when searches finish out of order, polling until Success, one failed submission isolated while siblings succeed, Error status returned as a result, thequeries=call shape, archive requests carrying onlysearch_id+api_key, timeout behavior, input-dict immutability, empty batch, and missing-argument TypeError. Full offline suite: 250 passed vs a 239 baseline before this change, no regressions.Deliberate choices
queries=), since real batch jobs mix engines/params.Clientonly:AsyncClientusers can already fan out withasyncio.gather; an asyncio polling variant deserves its own design.Happy to adjust the API shape or split anything out if maintainers prefer.