feat(async-client): add session pooling for connection reuse TAV-4105#155
Merged
Conversation
- Replace per-request client creation with persistent httpx.AsyncClient - Add close(), __aenter__, __aexit__ for lifecycle management - Extract duplicated error handling into _handle_error_response() - Add _post() helper for centralized request logic - Consolidate _method/method pairs into single public methods - Add test_session_pooling.py with 9 edge case tests - Fix test_errors.py fixture crash when TAVILY_API_KEY unset Performance: 2-10x faster for sequential requests (TCP connection reuse) Code reduction: 786 → 476 lines (39% smaller) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
… pooling Reverts helper method extraction (_handle_error_response, _post, etc.) while preserving the core session pooling feature: - Persistent self._client instance - close(), __aenter__, __aexit__ lifecycle methods - Direct self._client usage instead of _client_creator lambda TAV-4105 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
pulvedu
approved these changes
Jan 30, 2026
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.AsyncClientinstance for connection pooling inAsyncTavilyClientclose()method and async context manager support (__aenter__,__aexit__)tests/test_session_pooling.py)Changes
The async client now maintains a single
httpx.AsyncClientinstance instead of creating a new client per request. This enables HTTP connection reuse (avoiding TCP/TLS handshake overhead on subsequent requests).Usage
Test plan
tests/test_session_pooling.py)Linear: TAV-4105
🤖 Generated with Claude Code