deep_translator package

Submodules

deep_translator.base module

deep_translator.cli module

deep_translator.constants module

deep_translator.deepl module

class deep_translator.deepl.DeeplTranslator(source: str = 'de', target: str = 'en', api_key: Optional[str] = None, use_free_api: bool = True, **kwargs)[source]

Bases: deep_translator.base.BaseTranslator

class that wraps functions, which use the DeeplTranslator translator under the hood to translate word(s)

translate(text: str, **kwargs) → str[source]

@param text: text to translate @return: translated text

translate_batch(batch: List[str], **kwargs) → List[str][source]

@param batch: list of texts to translate @return: list of translations

translate_file(path: str, **kwargs) → str[source]

deep_translator.detection module

language detection API

deep_translator.detection.batch_detection(text_list: List[str], api_key: str, detailed: bool = False, *args, **kwargs)[source]

function responsible for detecting the language from a text

@param text_list: target batch that you want to detect its language @param api_key: your private API key @param detailed: set to True if you want to get detailed information about the detection process

deep_translator.detection.get_request_body(text: Union[str, List[str]], api_key: str, *args, **kwargs)[source]

send a request and return the response body parsed as dictionary

@param text: target text that you want to detect its language @type text: str @type api_key: str @param api_key: your private API key

deep_translator.detection.single_detection(text: str, api_key: Optional[str] = None, detailed: bool = False, *args, **kwargs)[source]

function responsible for detecting the language from a text

@param text: target text that you want to detect its language @type text: str @type api_key: str @param api_key: your private API key @param detailed: set to True if you want to get detailed information about the detection process

deep_translator.engines module

deep_translator.exceptions module

exception deep_translator.exceptions.ApiKeyException(env_var)[source]

Bases: deep_translator.exceptions.BaseError

exception thrown if no ApiKey was provided

exception deep_translator.exceptions.AuthorizationException(api_key, *args)[source]

Bases: Exception

exception deep_translator.exceptions.BaiduAPIerror(api_message)[source]

Bases: Exception

exception thrown if Baidu API returns one of its errors

exception deep_translator.exceptions.BaseError(val, message)[source]

Bases: Exception

base error structure class

exception deep_translator.exceptions.ElementNotFoundInGetRequest(val, message='Required element was not found in the API response')[source]

Bases: deep_translator.exceptions.BaseError

exception thrown if the html element was not found in the body parsed by beautifulsoup

exception deep_translator.exceptions.InvalidSourceOrTargetLanguage(val, message='Invalid source or target language!')[source]

Bases: deep_translator.exceptions.BaseError

exception thrown if the user enters an invalid payload

exception deep_translator.exceptions.LanguageNotSupportedException(val, message='There is no support for the chosen language')[source]

Bases: deep_translator.exceptions.BaseError

exception thrown if the user uses a language that is not supported by the deep_translator

exception deep_translator.exceptions.MicrosoftAPIerror(api_message)[source]

Bases: Exception

exception thrown if Microsoft API returns one of its errors

exception deep_translator.exceptions.NotValidLength(val, min_chars, max_chars)[source]

Bases: deep_translator.exceptions.BaseError

exception thrown if the provided text exceed the length limit of the translator

exception deep_translator.exceptions.NotValidPayload(val, message='text must be a valid text with maximum 5000 character,otherwise it cannot be translated')[source]

Bases: deep_translator.exceptions.BaseError

exception thrown if the user enters an invalid payload

exception deep_translator.exceptions.RequestError(message='Request exception can happen due to an api connection error. Please check your connection and try again')[source]

Bases: Exception

exception thrown if an error occurred during the request call, e.g a connection problem.

exception deep_translator.exceptions.ServerException(status_code, *args)[source]

Bases: Exception

Default YandexTranslate exception from the official website

errors = {400: 'ERR_BAD_REQUEST', 401: 'ERR_KEY_INVALID', 402: 'ERR_KEY_BLOCKED', 403: 'ERR_DAILY_REQ_LIMIT_EXCEEDED', 404: 'ERR_DAILY_CHAR_LIMIT_EXCEEDED', 413: 'ERR_TEXT_TOO_LONG', 422: 'ERR_UNPROCESSABLE_TEXT', 429: 'ERR_TOO_MANY_REQUESTS', 500: 'ERR_INTERNAL_SERVER_ERROR', 501: 'ERR_LANG_NOT_SUPPORTED', 503: 'ERR_SERVICE_NOT_AVAIBLE'}
exception deep_translator.exceptions.TencentAPIerror(api_message)[source]

Bases: Exception

exception thrown if Tencent API returns one of its errors

exception deep_translator.exceptions.TooManyRequests(message='Server Error: You made too many requests to the server.According to google, you are allowed to make 5 requests per secondand up to 200k requests per day. You can wait and try again later oryou can try the translate_batch function')[source]

Bases: Exception

exception thrown if an error occurred during the request call, e.g a connection problem.

exception deep_translator.exceptions.TranslationNotFound(val, message='No translation was found using the current translator. Try another translator?')[source]

Bases: deep_translator.exceptions.BaseError

exception thrown if no translation was found for the text provided by the user

deep_translator.google module

deep_translator.libre module

deep_translator.linguee module

deep_translator.microsoft module

deep_translator.mymemory module

deep_translator.papago module

deep_translator.pons module

deep_translator.qcri module

deep_translator.validate module

deep_translator.validate.is_empty(text: str) → bool[source]
deep_translator.validate.is_input_valid(text: str, min_chars: int = 0, max_chars: Optional[int] = None) → bool[source]

validate the target text to translate @param min_chars: min characters @param max_chars: max characters @param text: text to translate @return: bool

deep_translator.validate.request_failed(status_code: int) → bool[source]

Check if a request has failed or not. A request is considered successfull if the status code is in the 2** range.

Args:

status_code (int): status code of the request

Returns:

bool: indicates request failure

deep_translator.yandex module

Module contents