alexdlaird / amazon-orders

A CLI and library for interacting with Amazon order history
https://amazon-orders.readthedocs.io
MIT License
21 stars 9 forks source link

Asyncio support? #19

Open jeffsawatzky opened 1 month ago

jeffsawatzky commented 1 month ago

Acknowledgements

Describe the Feature

Would you be open to adding asyncio support using either httpx or aiohttp?

might help speed up loading as it is currently pretty slow.

Describe Alternative Solutions/Workarounds

Other options are using something like gevent maybe? But asyncio seems cleaner.

alexdlaird commented 1 month ago

No plans to add this, but would be happy to consider a pull request. It doesn't seem like it'd be a huge lift, and the current tests for unit / integration should catch any regressions.

alexdlaird commented 3 weeks ago

If anyone does pick this up to do it, I think I'd rather switch ot using httpx rather than modifying requests (or using grequests) to accomplish this, since that feels hacky. To start this work then, we'd first need to replace requests with httpx throughout the code (primarily in AmazonSession, since that's pretty coupled to requestsSession object (but the comparable way to do this inhttpxwould be with its [Client`](https://www.python-httpx.org/advanced/clients/)).

The biggest lift beyond this will probably be refactoring tests, which currently very conveniently uses responses.activate to mock responses. I haven't looked in to what / if httpx has a good alternative to this, or if we're going to have to roll our own monkeypatch for each test.

Once the coupling with AmazonSession is replaced, the remaining code to add awaits is a pretty small lift from there.

jeffsawatzky commented 3 weeks ago

For httpx there is pytest_httpx

Would you want both sync and async support, or are you ok with dropping sync altogether?

alexdlaird commented 3 weeks ago

Nice!

I think we'd want to maintain both, but I haven't thought about it enough to decide if users would lose anything they might miss if we dropped sync support ... I'll noodle on it, would be curious to know your thoughts.