DeepLcom / deepl-python

Official Python library for the DeepL language translation API.
https://www.deepl.com
MIT License
1.11k stars 80 forks source link

New feature : customize timeout duration #89

Open louisgaume opened 9 months ago

louisgaume commented 9 months ago

👋 Hello, we're super happy with this nice SDK !

We're just missing a small feature that would help us improving our performance. We would like to have the ability to customize the timeout of the API call being made. Customizing this parameter at a global level would be fine (for example like it's done within the PHP SDK)

If you're accepting this, we can provide a PR for this !

Let me know if you guys need anything ! Thanks in advance 😄

JanEbbing commented 9 months ago

Hi @louisgaume , there is some functionality for this already, does it not cover your use case? You can do the following

import deepl
deepl.http_client.min_connection_timeout = 5.0
translator = deepl.Translator('my_auth_key')  # Will use 5 second timeout

Please note that the library uses exponential backoff, so each consecutive retry will wait for longer - probably easiest to check the code to see what exactly happens under the hood.

See also this issue. This functionality is a bit hidden, we should definitely document it better, sorry. If it doesn't cover your use case, please elaborate.

louisgaume commented 9 months ago

Hello ! Thanks for your reply, this might do the job for us in fact! Didn't know we could change this parameter this way. :) I'll take a look again at the code deeply to see how is it working under the hood.

Thanks again :)