I can't test it because I don't have a API key, but by reading the documentation of the free Deepl API, everything is well indicated, with a CURL example:
curl https://api.deepl.com/v2/translate \
-d auth_key=[yourAuthKey] \
-d "text=Hello, world!" \
-d "target_lang=DE"
The documentation indicates that the source_lang
parameter is optional and if it is omitted, the API will attempt to detect the language of the text and translate it.
So in python code, it should be
import requests
import json
url = "https://api-free.deepl.com/v2/translate"
data = f"auth_key={yourAuthKey}&text={YourText}&target_lang={LanguageCode}"
resp = requests.post(url, data=data)
translated_text = json.loads(resp.content)
print(translated_text)
with:
yourAuthKey
- your API key.
YourText
- the text you wish to translate.
LanguageCode
- the language code (see API doc) into which the text should be translated.
It should be fine like this with standard libraries.
Or you can use official DeepL Python Library to make it even simpler.