I would like to create a ClientSession myself in my library, so I can set useful options like base_url
, headers
and raise_for_status
globally. This avoids needing to repeat options or create wrapper methods for creating requests.
As long as my ClientSession uses the same connector as Home Assistant’s global ClientSession, I believe it will share the connection pool and I don’t have to worry about closing the ClientSession. In fact, async_create_clientsession
seems to basically be a wrapper for doing exactly this: create a new ClientSession with the existing connector.
There is at least one caveat; the custom ClientSession won’t use orjson for json decoding, so it will be slightly slower. However, at least re-using the connector would be much better than creating a completely new ClientSession instance.