VingtCinq / python-mailchimp

Python client for v3 of MailChimp API
MIT License
463 stars 131 forks source link

MailChimpClient reuse connection pool and keep-alive #148

Open xmedeko opened 7 years ago

xmedeko commented 7 years ago

MailChimpClient open a new connection for every request. It's faster to reuse the connection pool and keep-alive. So, the MailChimpClient should open and keep the requests session. Also, if the MailChimpClient would implement the session, then it should have some close() and/or __exit__() methods to close the session manually.

xmedeko commented 7 years ago

I have tried to patch MailChimp class to use just one session and it has lead to about 1/3 speedup on my development machine. I can make a PR to use a session in the MailChimpClient. However, I think the MailChimp should not be child of MailChimpClient. It should use MailChimpClient as a fields only (inheritance vs. composition). Then it would be possible to switch different implementations of MailChimpClient.

Nevertheless, most of the use cases may be solved by batch processing.