Open DefiDebauchery opened 5 days ago
Hi @DefiDebauchery,
If you use aiohttp library and want to use the same ClientSession for communication with different hosts, then I would not set base_url
. This is an entirely optional convenience parameter.
Otherwise, if you would like to access some advanced options of aiohttp library I would consider implementing a custom client class following this example: https://github.com/pmateusz/meatie/blob/master/src/meatie_aiohttp/client.py). Meatie codebase contains analog implementations for httpx and requests. By doing it you will have full control over the way HTTP requests are being dispatched.
We had a similar challenge in my other project (i.e., large API is spread across 5 different hosts). We ended up implementing 5 meatie clients with independent Client Sessions. We considered it best tradeoff because each of these hosts behaved differently in terms of error handling and rate limit policies.
I have sort of a unique situation. My use of meatie is only one small part of my overall application, and I would like to re-use my ClientSession, which has already been set up with various default options (like enabling env for proxy data, custom
TCPConnector
, timeouts, etc).There's no easy way (that I could find) to quickly and generally apply these options to another ClientSession, and I wouldn't want to apply the
base_url
to this CS instance because that would of course apply to unrelated tasks.I recognize that this is more an aiohttp limitation (not supporting
base_url
in.request()
that I could pass intosession_params=
) than meatie, but perhaps there's room to increase flexibility by allowing for a local base variable that is combined inmeatie.Client
? This could also makeClient
s reusable for platforms that have a consistent API but available on different hostnames, utilizing the same ClientSession (thus potentially opening up strategies likeasyncio.gather()
across several instances at once).