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
-
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