Allow AIOHTTPClient to accept user-provided session or connector (#1736)#1737
Merged
skukutla-stripe merged 3 commits intomasterfrom Feb 24, 2026
Merged
Conversation
This comment was marked as spam.
This comment was marked as spam.
xavdid-stripe
approved these changes
Feb 24, 2026
Member
xavdid-stripe
left a comment
There was a problem hiding this comment.
nice! had a couple of small style suggestions. once you fix those, you can merge!
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.
Why?
Currently, AIOHTTPClient always creates its own
aiohttp.ClientSessionand TCPConnector internally, with no way for users to customize them. This means users cannot:limit,limit_per_host, orkeepalive_timeoutThe only workaround is setting the private _cached_session attribute after construction, which is an unstable interface.
RequestsClientalready accepts an optional session parameter in its constructor (line 585), so there is existing precedent for this pattern. The need is stronger forAIOHTTPClientbecause async usage inherently involves concurrent requests, making connection pool sharing and tuning a common requirement for people using this client.What?
_owns_sessiontracking so thatclose_async()only closes the session if AIOHTTPClient created it. This avoids destroying a shared session that the user manages themselves (an improvement overRequestsClient.close(), whichunconditionally closes even user-provided sessions)
See Also
AIOHTTPClientconstructor to take user-providedClientSession#1736