At current version of deep-translator(1.10.1) batch_translate is doing a linear loop of same function of single translate function. So in that context request is creating new session every time for requesting url to translate. Which is causing translator slow. Also It's working synchronously as each time request is blocking so until that request is finished translator is waiting idle. It can be optimized with asyncio feature also adding a dependency of aiohttp package and further for duplicate request we can utilize lru_cache system. Theres still long way to go for every translator to add the asyncio.
Changes Made
Changes are going to be non-breaking. Maybe we could add different function for async versions. But new dependency should be added aside of request we need to add aiohttp for async http calls.
[X] Making new async version function as async_translate_batch for high level function (non-breaking change which adds functionality)
[X] Added only for Google Translator with updated tests [ Function Docs Will be added in future commits ]
[X] Added _async_translate as abstract method to translate a single text asynchronusly in base.py which should be implemented in every translator
Checklist:
[X] My code follows the style guidelines of this project
[X] I have performed a self-review of my code
[X] I have added tests that prove my fix is effective or that my feature works
[ ] Make the asyncio aiohttp dependency optional
[ ] Add asyncio for deepl translator with tests
[ ] Add asyncio for libre translator with tests
[ ] Add asyncio for linguee translator with tests
[ ] Add asyncio for microsoft translator with tests
[ ] Add asyncio for mymemory translator with tests
Description
At current version of
deep-translator(1.10.1)
batch_translate is doing a linear loop of same function of single translate function. So in that contextrequest
is creating new session every time for requesting url to translate. Which is causing translator slow. Also It's working synchronously as each time request is blocking so until that request is finished translator is waiting idle. It can be optimized with asyncio feature also adding a dependency ofaiohttp
package and further for duplicate request we can utilizelru_cache
system. Theres still long way to go for every translator to add the asyncio.Changes Made
Changes are going to be non-breaking. Maybe we could add different function for async versions. But new dependency should be added aside of request we need to add
aiohttp
for async http calls.async_translate_batch
for high level function (non-breaking change which adds functionality)_async_translate
as abstract method to translate a single text asynchronusly inbase.py
which should be implemented in every translatorChecklist:
aiohttp
dependency optionaldeepl
translator with testslibre
translator with testslinguee
translator with testsmicrosoft
translator with testsmymemory
translator with testspapago
translator with testspons
translator with testsqcri
translator with testsyandex
translator with testsProof Of Concept
Usage