You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added the migration guide Upgrading to 2.0.0, which
lists the breaking changes since 1.33.0 with before and after examples.
Breaking:Usage.Detail is constructed as Usage.Detail(count, limit); the former (json, prefix) constructor is removed.
The library is tested with Python 3.9 to 3.15. Python 3.9 remains the
minimum supported version.
Breaking:translate_document_download() and download_translation_memory_export()
require output_file and return None. They no longer return the
streaming requests.Response; pass a file-like object opened in binary mode
to receive the downloaded file.
Breaking: The dictionaries argument of create_multilingual_glossary(), the dictionary argument of update_multilingual_glossary_dictionary() and replace_multilingual_glossary_dictionary(), the csv argument of the *_from_csv() multilingual glossary functions, the glossary argument of get_multilingual_glossary() and the content argument of upload_translation_memory_file() are required in their type annotations;
they are no longer Optional. Pass a value instead of None.
Breaking: The max_retries and timeout_s options of DeepLClient and DeepLAdminClient default to 5 and 10.0 for each client instead of None. Clients no longer read any module-level setting; pass the options
to every client that needs other values.
Breaking:DeepLClient no longer extends Translator; it extends no public class.
All functions of Translator are now defined on DeepLClient with the same
arguments and behaviour. Code that checks isinstance(client, deepl.Translator) or annotates clients as Translator must use DeepLClient.
Breaking:StyleRuleInfo.configured_rules returns the configured rules as the API
sends them: a dict mapping category names to dicts of rule names and
values, the same shape create_style_rule() and update_style_rule_configured_rules() take. Categories the library does
not know are kept, and an empty {} from the API is returned as {}
instead of None; None still means the response omitted the field.
Replace attribute access such as rule.configured_rules.numbers with rule.configured_rules.get("numbers", {}).
Breaking:translate_document() and translate_document_from_filepath() raise DocumentTranslationException with document_handleNone when the upload
fails, copying http_status_code and should_retry; the original
exception (for example QuotaExceededException) is its __cause__.
Catch DocumentTranslationException instead of the upload exception.
Breaking:translate_document_from_filepath() raises ValueError instead of FileNotFoundError if the input file does not exist, and DocumentTranslationException with document_handleNone instead of the OSError of open() if the input or output file cannot be opened.
Catch ValueError and DocumentTranslationException instead.
Breaking:translate_document_wait_until_done() raises DeepLException with the
API's error message when the translation fails, instead of returning the DocumentStatus with okFalse. Catch DeepLException instead of
checking status.ok.
Breaking:wait_until_translation_memory_job_done() raises DeepLException with the
API's error message when the job fails or expires, instead of returning
the job with okFalse. Catch DeepLException instead of checking job.ok.
Breaking:TranslationMemoryJob.done and TranslationMemoryJobResult.done are True only for a completed job, as DocumentStatus.done; a failed or
expired job is no longer done. Use ok to detect failure.
Breaking:import_translation_memory_from_filepath() and export_translation_memory_to_filepath() no longer raise OSError, FileNotFoundError, IsADirectoryError or PermissionError; see the TranslationMemoryJobException entry below.
Breaking:TranslationMemoryJob.creation_time and updated_time are typed datetime.datetime, no longer Optional; they are required constructor
arguments, placed after results. A job response without them raises DeepLException. Code that constructs a TranslationMemoryJob must pass
both.
Breaking:StyleRuleInfo.custom_instructions is typed Optional[List[CustomInstruction]] and returns None when the response
omits the field (for example get_all_style_rules() without detailed=True), instead of []. An empty list from the API is returned
as []. Check for None before iterating.
Breaking:Usage.character and Usage.api_key_character return None when the
response does not contain both the count and the limit of that usage type,
instead of a Usage.Detail whose missing count or limit is None. Usage.Detail.count and limit are typed int. Replace usage.character.valid with usage.character is not None.
Breaking:delete_multilingual_glossary_dictionary() takes (glossary, source_lang, target_lang); the dictionary argument is
keyword-only. Replace delete_multilingual_glossary_dictionary(glossary, dictionary) with delete_multilingual_glossary_dictionary(glossary, dictionary=dictionary) or pass the language pair.
Breaking:MultilingualGlossaryDictionaryEntries.entries read from the API (by get_multilingual_glossary_dictionary_entries()) is a dict of source to
target terms, as its type annotation says, instead of the TSV string the
API returns. Remove calls of convert_tsv_to_dict() on it.
Breaking:update_multilingual_glossary_dictionary() and replace_multilingual_glossary_dictionary() no longer check dictionary
for None. None raises Python's own AttributeError, still before any
request, instead of TypeError: ... missing required argument: dictionary. Pass a dictionary, not None.
Breaking: a connection that breaks off while a streamed response body
is read (translate_document_download(), download_translation_memory_export() and the error body of a streamed
request) raises ConnectionException with should_retryTrue instead of False. The download is still not retried automatically, because part of
the file may already be written to output_file. If you retry, truncate or
reopen output_file first.
Breaking: functions that create a resource are only retried when the
request was not sent: after HTTP 429 or a network failure while connecting,
before any request byte is written, such as a DNS resolution failure, a
refused connection, a connect timeout, or a reset or timeout in the TLS or
proxy handshake. They are no longer retried after HTTP 5xx, a read timeout, a
reset connection or a response body cut off mid-read, which could create the
resource twice. This applies to create_glossary(), create_glossary_from_csv(), create_multilingual_glossary(), create_multilingual_glossary_from_csv(), create_spoken_terms(), create_style_rule(), create_style_rule_custom_instruction(), create_style_profile(), create_translation_memory_import(), create_translation_memory_export(), the document upload of translate_document_upload(), translate_document() and translate_document_from_filepath(), and the job creation of import_translation_memory_from_filepath() and export_translation_memory_to_filepath(). The error raised after the first
failure is described in the next entry. If you retry yourself, check for a
duplicate resource first.
Breaking: the exception raised by a function that creates a resource (the
functions listed above and DeepLAdminClient.create_developer_key()) has should_retryTrue only after HTTP 429, a network failure while connecting
(see the previous entry) or a response body cut off mid-read. After HTTP 5xx,
a read timeout, a reset connection or a broken pipe it is False instead of True, because repeating the request could create a duplicate. DocumentTranslationException from a failed document upload copies this
value. If you retry yourself, check for a duplicate resource first.
Breaking: a failure to connect to the proxy (a DNS resolution failure, a
refused connection or a connect timeout) is retried and raises ConnectionException with should_retryTrue, like the same failure
without a proxy. Before, every proxy failure raised ConnectionException
with should_retryFalse at once. An error answer from the proxy (a status
other than 2xx in reply to CONNECT, such as 407) and a TLS failure with an https:// proxy are still not retried. DeepLAdminClient.create_developer_key() is now also retried after a failure
to connect to the proxy and after a reset or timeout in the proxy tunnel or
the TLS handshake, before the request is written; the other functions that
create a resource retry them from this release on. Pass max_retries=0 to
fail at once.
Breaking:translate_text(), rephrase_text() and correct_text()
raise ValueError if a list of texts contains an empty string, before any
request is sent. Before, only a single empty string was rejected. Remove
empty strings from the list before the call.
Breaking:translate_text(), rephrase_text() and correct_text() no
longer check the type of text. A value that is neither a string nor
iterable raises Python's own TypeError from list() (for example "'int'
object is not iterable"), still before any request, instead of TypeError: text parameter must be a string or an iterable of strings. Pass
a string or a list of strings, and do not match the error message.
Breaking:translate_text(), translate_document_upload() and the
document functions that call it raise ValueError if target_lang or a
given source_lang is an empty string, before any request is sent. Pass a
language code, or None as source_lang to detect the language.
Breaking:translate_text(), translate_document_upload() and the
document functions that call it raise ValueError if glossary, an entry
of glossary_ids, style_rule, style_profile or translation_memory is
an empty string or an object with an empty ID, before any request is sent.
Before, the empty ID was sent to the API. Pass None to use no glossary,
style rule, style profile or translation memory.
Breaking: the multilingual glossary functions
(create_multilingual_glossary(), update_multilingual_glossary(), the
dictionary update, replace, get-entries and delete functions and their *_from_csv() variants), the spoken terms functions
(create_spoken_terms(), update_spoken_terms(), replace_spoken_terms_list(), get_spoken_terms_entries(), delete_spoken_terms_list()) and the custom instruction functions of style
rules (create_style_rule(), create_style_rule_custom_instruction(), update_style_rule_custom_instruction()) raise ValueError before any
request if a required language of the multilingual glossary or spoken terms
functions is empty, or a custom instruction's source_language is an empty
string. Before, the empty value was sent. Pass a language code, or None to
leave source_language unset.
Breaking:rephrase_text() and correct_text() raise ValueError if target_lang is an empty string, before any request is sent, instead of
leaving it out of the request. To keep the input language, pass None or
omit target_lang.
Breaking:translate_document() and translate_document_from_filepath()
raise DocumentTranslationException with document_handleNone for
invalid arguments, including a missing target_lang, with the ValueError
or TypeError as its __cause__, instead of raising it unwrapped. A missing
input file of translate_document_from_filepath() raises ValueError
unwrapped, not DocumentTranslationException. Catch DocumentTranslationException and read the error from its __cause__.
Breaking:translate_document_from_filepath() raises DocumentTranslationException with document_handleNone before any
request if output_path already exists, instead of overwriting the file.
Delete the file first to replace it.
Breaking:translate_document_upload() and translate_document() send
the given filename as the upload's file name for a file object too.
Before, filename was used only for str or bytes content, and a file
object was sent under its own name, or as file if it had none. The API
detects the input format from the file name's extension. Without filename, a file object is still sent under its own name. Omit filename
to keep the file object's name.
Breaking:import_translation_memory_from_filepath() and export_translation_memory_to_filepath() raise the new TranslationMemoryJobException (a DeepLException subclass) for every
failure except a missing input file, which still raises ValueError. The
underlying exception (for example QuotaExceededException, or the DeepLException of a failed job) is its __cause__; it copies http_status_code and should_retry, and carries job_id once the job was
created and job, the last job status retrieved. Catch TranslationMemoryJobException (or DeepLException) instead of the
underlying exception.
Breaking:export_translation_memory_to_filepath() raises TranslationMemoryJobException before creating the export job if output_path already exists, instead of overwriting the file. Delete the
file first to replace it.
Breaking:download_translation_memory_export() raises DeepLException instead of ValueError if the job has no download URL.
Catch DeepLException instead of ValueError.
Breaking:create_multilingual_glossary() raises ValueError if dictionaries is empty, before any request is sent. Pass at least one
dictionary.
Breaking:get_spoken_terms(), update_spoken_terms(), delete_spoken_terms(), get_spoken_terms_entries(), replace_spoken_terms_list() and delete_spoken_terms_list() raise ValueError if spoken_terms is an empty ID or a SpokenTerms without an
ID, before any request is sent. Pass the ID of the spoken terms list or a SpokenTerms read from the API.
Breaking:CustomInstruction.id is typed str, no longer Optional[str], and is a required keyword-only constructor argument. A
custom instruction response without id raises DeepLException. CustomInstruction is only returned by the API, which always sets id;
code that builds CustomInstruction objects must pass id=.
Breaking: The DeepLClient and DeepLAdminClient constructors raise ValueError if
a proxy URL has no host or a scheme other than http, https, socks4, socks4a, socks5 or socks5h, instead of failing on the first request.
A proxy URL without a scheme is still used as an http:// URL.
Catch ValueError from the constructor, or pass a valid proxy URL.
Breaking: the DeepLClient and DeepLAdminClient constructors no
longer check the type of proxy. A value that is neither a string nor a
dictionary raises Python's own error (AttributeError for a list) instead
of ValueError. Pass the proxy as a string or a dictionary.
Breaking: The DeepLClient and DeepLAdminClient constructors raise ValueError if server_url is not an absolute http or https URL with a host, instead
of failing on the first request with DeepLException. Catch ValueError
from the constructor, or pass a valid server URL.
Breaking:update_multilingual_glossary_dictionary_from_csv() and replace_multilingual_glossary_dictionary_from_csv() raise ValueError if
the CSV content is empty, before any request is sent, as the variants
taking a dictionary do. Before, an empty dictionary was sent. Pass CSV
content with at least one entry.
Breaking:create_glossary_from_csv() and the multilingual glossary *_from_csv() functions no longer check the type of what a file-like csv_data / csv returns from read(). create_glossary_from_csv() sends
it as the entries, and the multilingual functions pass it to the CSV
parser, which raises Python's own TypeError for a non-iterable. Before, a
result that was neither str nor bytes raised ValueError: Entries of the glossary are invalid. Make read() return str or bytes.
Breaking:DeepLClient.rephrase_text() sends writing_style and tone whenever they are not None, an empty string included, as every
other option; an empty string was silently dropped before. Migration: pass None to leave them unset.
Breaking:send_platform_info=None sends the platform information in
the User-Agent, as when the option is omitted; it sent only the library
version before. Migration: pass False to opt out.
Breaking:DeepLClient.translate_document_upload() and translate_document() send output_format whenever it is not None, an
empty string included, as every other option; an empty string was silently
dropped before. Migration: pass None to leave it unset.
Removed
Breaking: Removed Usage.any_limit_reached; use Usage.any_character_limit_reached,
which is True if character or api_key_character has reached its limit.
Like before, the speech minutes are not considered.
Breaking: Removed Usage.document and Usage.team_document; the API no longer
returns document usage. document_* and team_document_* fields in a usage
response are ignored. Remove code that reads them.
Breaking: Removed Usage.Detail.valid. Absent usage types are now None; check detail is not None instead.
Breaking: Removed the ConfiguredRules class of deepl.api_data. StyleRuleInfo.configured_rules now returns a plain dict; code that
imported or constructed ConfiguredRules must use a dict instead.
Breaking: Removed the deprecated Translator class; use DeepLClient, which
supports all of its functions with the same constructor arguments. Replace deepl.Translator(...) with deepl.DeepLClient(...).
Breaking: Removed the module deepl.translator. Import the classes it provided from deepl instead: the exceptions (AuthorizationException, DocumentNotReadyException, QuotaExceededException, TooManyRequestsException, ...) from deepl or deepl.exceptions, and the result and option types (TextResult, DocumentHandle, Usage, Formality, ...) from deepl or deepl.api_data.
Breaking: Removed the public module deepl.http_client; it is now the internal deepl._http_client. Code that used HttpClient, read_response_text() or iter_response_content() from it must use the client classes instead.
Breaking: Removed the module-level settings deepl.http_client.max_network_retries, deepl.http_client.min_connection_timeout and deepl.http_client.user_agent. Use the max_retries and timeout_s client
options, and a User-Agent entry in the headers client option.
Breaking: Removed the language code constants of Language (Language.GERMAN, Language.ENGLISH_AMERICAN, ...). Pass language codes as strings, for
example "de", or use the codes returned by get_source_languages() and get_target_languages().
Breaking: Removed translate_text_with_glossary(). Call translate_text() with the glossary argument and the glossary's source_lang and target_lang; for
an EN glossary pass target_lang="EN-GB" or "EN-US".
Breaking: Removed get_multilingual_glossary_entries(). Use get_multilingual_glossary_dictionary_entries(), which returns the MultilingualGlossaryDictionaryEntries directly instead of a MultilingualGlossaryDictionaryEntriesResponse.
Breaking: Removed the deprecated keyword names of the multilingual glossary
functions: use dictionaries instead of glossary_dicts, dictionary
instead of glossary_dict, csv instead of csv_data and glossary
instead of glossary_id.
Breaking: Removed the input_file keyword of upload_translation_memory_file(); use content.
Breaking: Removed the style keyword of rephrase_text(); use writing_style.
Breaking: Removed the skip_language_check argument of DeepLClient(), and the skip_cache argument of get_source_languages() and get_target_languages(). Both had no effect; delete them from calls.
Breaking: Removed auth_key_is_free_account(); use is_free_account_auth_key(),
which also ignores leading and trailing whitespace of the key.
Breaking: Removed Usage.Detail.limit_exceeded and Usage.any_limit_exceeded; use limit_reached and any_character_limit_reached.
Breaking: Removed SplitSentences.DEFAULT; use SplitSentences.ALL, which it was an
alias of.
Breaking: Removed DocumentTranslationException.document_request; use document_handle.
Breaking: Removed DocumentStatus.Status.DOWNLOADED, which is not a status the API
returns. A downloaded status from the API would be kept as the string "downloaded", like any status this version does not know. Remove
comparisons with it.
Breaking: Removed TranslationMemoryJobResult.STATUS_DOWNLOADED, which is not a job
status the API returns. A downloaded status from the API is kept as the
string "downloaded" and no longer counts as done, so wait_until_translation_memory_job_done() keeps polling on it. Remove
comparisons with it.
Breaking: Removed the deprecated GlossaryNotFoundException. Every
glossary function raises NotFoundException for HTTP 404, with the message Not found instead of Glossary not found, and get_multilingual_glossary_dictionary_entries() raises NotFoundException
if the glossary has no dictionary for the language pair. Catch NotFoundException instead.
Breaking: Removed MultilingualGlossaryDictionaryEntriesResponse, the
return type of the removed get_multilingual_glossary_entries(). get_multilingual_glossary_dictionary_entries() returns the MultilingualGlossaryDictionaryEntries directly.
Fixed
The deepl package exports all public types of deepl.api_data, among
them WritingStyle, WritingTone, WriteResult, CustomInstruction, StyleRuleInfo, the translation memory types and LanguageResourceName, LanguageInclude and LanguageSupport. Before, deepl.WritingStyle raised AttributeError, and ModelType was missing from __all__.
timeout_s of translate_document(), translate_document_from_filepath(), translate_document_wait_until_done(), wait_until_translation_memory_job_done(), import_translation_memory_from_filepath() and export_translation_memory_to_filepath() is annotated Optional[float],
like the client's timeout_s. A float was already accepted at runtime.
DeepLClient.upload_translation_memory_file(content_type=None) uploads
with application/xml instead of failing with DeepLException.
close(), set_app_info() and server_url of DeepLClient and DeepLAdminClient have type annotations: close() returns None, set_app_info() returns the client's own type and server_url is a str.
Before, calling close() failed mypy --strict with no-untyped-call, and set_app_info() and server_url were typed Any.
create_multilingual_glossary(), update_multilingual_glossary(), update_multilingual_glossary_dictionary() and replace_multilingual_glossary_dictionary() accept a dictionary read from
the API, and a MultilingualGlossaryDictionaryEntries whose entries is a
TSV string, which is trimmed and validated like a dict; they no longer
raise AttributeError. create_multilingual_glossary(), update_multilingual_glossary_dictionary() and replace_multilingual_glossary_dictionary() raise ValueError if the TSV
string holds no entries.