feat: add asyncio support with HTTPX - #43
Closed
Joseph-Mutua wants to merge 1 commit into
Closed
Joseph-Mutua wants to merge 1 commit into
Joseph-Mutua wants to merge 1 commit into
Conversation
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.
Summary
httpx.Client/httpx.AsyncClienttransports while preserving the existing synchronousserpapi.Clientand module-level helpersserpapi.AsyncClientsupport for search, archive, account, locations, image upload, concurrent calls, and async paginationclose()/aclose()and sync/async context managers, shared parameter behavior, redirects, timeout and error translation, and compatibility handling for the existing per-call proxy/TLS optionsFixes #27
Compatibility notes
The synchronous call pattern remains unchanged.
timeout=Nonekeeps the SDK's historical no-timeout behavior, redirects remain enabled, pagination URLs retain existing query parameters, and SerpApi exceptions retainstatus_code,error,request, andresponsedetails.HTTPX configures proxy and TLS settings at the client level. Constructor-level
proxy,verify, andcertsettings therefore reuse the connection pool; legacy per-callproxies,verify,cert, andstreamarguments remain accepted through a scoped compatibility path.HTTPX 0.28 requires Python 3.8+, which matches this repository's current Python 3.8-3.14 CI matrix.
Verification
119 passed, 42 deselectedin the deterministic offline suite34 passedfor the transport/client suite on Python 3.8.20 with HTTPX 0.28.1twine checkClientandAsyncClientand depends on HTTPX, not RequestsLive API tests were not run locally to avoid consuming account searches; the existing CI workflow can exercise those with the repository secret.
Controlled benchmark
20 requests against a local threaded endpoint with a 50 ms response delay, using the median of three runs and excluding client setup/shutdown:
requests.Sessionsequentialserpapi.Clientsequential HTTPXserpapi.AsyncClientconcurrentThat is a 9.05x throughput improvement for this concurrent I/O workload. It does not imply that a single search becomes faster.
Review context
@adarshdigievo @jvmvik - I followed the separate
AsyncClientdirection discussed in #27. The two decisions I would especially appreciate confirmation on are raising the declared minimum to Python 3.8 and retaining legacy per-call proxy/TLS options via scoped clients.