Repository navigation
TL;DR: new APIs in this release: the Admin API, spoken terms and style profiles.
Translation memories, style rules and multilingual glossaries gained many options and fixes.
Read Changed and Deprecated before upgrading; no public API is removed in this release.
Added
- Added the
headersoption to theTranslator,DeepLClientand
DeepLAdminClientconstructors: extra HTTP headers sent with every request
to the DeepL API. A header replaces the library's header of the same name,
includingUser-AgentandAuthorization;Content-Type,
Content-Length,Transfer-Encoding,Hostand anAcceptthe library
sets for a call keep the library's value. Translation memory storage URLs
get only theUser-Agent. - Added the
app_infooption, anAppInfo(app_name, app_version), to the
Translator,DeepLClientandDeepLAdminClientconstructors, the same as
callingset_app_info(). - Added
NotFoundException, raised for HTTP 404 on every endpoint.
GlossaryNotFoundExceptionis now its subclass. - Added
is_free_account_auth_key(), which replacesauth_key_is_free_account(). - Added the
extra_body_parametersoption tocreate_style_rule(),
update_style_rule_name(),update_style_rule_configured_rules(),
create_style_rule_custom_instruction()and
update_style_rule_custom_instruction(). get_style_rule_custom_instruction(),
update_style_rule_custom_instruction()and
delete_style_rule_custom_instruction()accept aCustomInstructionobject
asinstruction_id, as well as an ID string.- Added the
max_retriesandtimeout_soptions to theTranslator,
DeepLClientandDeepLAdminClientconstructors, to set the maximum number
of retries and the minimum per-attempt timeout in seconds for each client. - Added the
style_profileoption totranslate_text()and the document
translation functions (translate_document(),
translate_document_from_filepath(),translate_document_upload()) to
translate with a style profile, as a style profile ID orStyleProfile
object. The CLI accepts it as--style-profile-id. - Added the
DeepLAdminClientclass for the Admin API. It must be created with
an admin API key and supports managing developer keys
(create_developer_key(),list_developer_keys(),
deactivate_developer_key(),rename_developer_key(),
set_developer_key_usage_limits()) and retrieving usage analytics
(get_usage_analytics(),get_custom_tag_usage_analytics()) with
the result typesDeveloperKey,DeveloperKeyUsageLimits,
AdminUsageReport,AdminUsageBreakdown,KeyUsage,CustomTagUsageReport,
CustomTagUsageandCustomTagUsageBreakdown, and the request options
DeveloperKeyUsageLimitsUpdate,AdminUsageGroupByand
CustomTagUsageAggregateBy.
The developer key methods that send a request body accept
extra_body_parameters.
create_developer_key()is retried only when the request was not sent:
after HTTP 429, a DNS resolution failure, a refused connection or a connect
timeout.AdminUsageReport.total_usage,
AdminUsageBreakdown.speech_to_speech_minutesand
CustomTagUsageBreakdown.speech_to_speech_minutesareNonewhen the
report does not contain them, and a response withoutusage_reportor
custom_tag_usage_reportraisesDeepLException. - Added
get_languages_for_resource()method to theDeepLClientclass to
retrieve the languages supported by a resource, with per-feature support
information, via the/v3/languagesendpoint. Resources are given as
LanguageResourceNamevalues or strings; results areLanguageSupport
objects. Malformed responses raiseDeepLException. - Added
get_language_resources()method to theDeepLClientclass to
retrieve the API resources and their features via the
/v3/languages/resourcesendpoint. Results are returned as
LanguageResourceandResourceFeatureobjects;needs_source_support
andneeds_target_supportareFalsewhen the API omits them. - Added
Languageconstants for the target variantsde-CH,de-DE,
es-ES,fr-CA, andfr-FR. - Added the
enable_watermarkoption totranslate_document(),
translate_document_upload()andtranslate_document_from_filepath(). Set
it toTrueto add a "Translated by DeepL" watermark todocxandpdf
output. - Added the API Pro usage fields to
Usage:api_key_character,
speech_to_text_minutesandspeech_to_speech_minutes(as
Optional[Usage.Detail]),start_timeandend_time(the billing period),
andproducts, a list ofUsage.Productobjects with per-product usage.
They areNonewhen the response does not contain them;productsentries
that are not JSON objects are skipped. - Added the Spoken Terms API (
/v3/spoken-terms) to theDeepLClientclass:
create_spoken_terms(),list_spoken_terms(),get_spoken_terms(),
update_spoken_terms(),get_spoken_terms_entries(),
replace_spoken_terms_list(),delete_spoken_terms()and
delete_spoken_terms_list(), with theSpokenTerms,SpokenTermsListand
SpokenTermsEntriestypes.create_spoken_terms(),update_spoken_terms()
andreplace_spoken_terms_list()acceptextra_body_parameters. Collection
IDs are URL-encoded in the request path, terms are stripped of leading and
trailing whitespace before they are validated and sent, and a malformed
response raisesDeepLException. - Added the style profile API (
/v3/style_profiles) to theDeepLClient
class:list_style_profiles(),create_style_profile(),
get_style_profile(),update_style_profile()and
delete_style_profile(), with theStyleProfiletype. Theglossary_ids,
style_rule_idsandtranslation_memory_idsoptions of
create_style_profile()andupdate_style_profile()accept IDs or
GlossaryInfo,MultilingualGlossaryInfo,StyleRuleInfoand
TranslationMemoryInfoobjects, and both functions accept
extra_body_parameters. A style profile response that is not a JSON object,
or lacks a validstyle_profile_id,name,creation_timeor
updated_time, raisesDeepLException. - Added the
TagHandlingMode(HTML,XML) andTagHandlingVersion(V1,
V2) enums. Thetag_handlingandtag_handling_versionoptions of
translate_text()accept them as well as strings. - Added
tag_handling_versiontoTextResult: the tag handling version the
API used, orNonewhen the response does not contain it. translate_text()acceptssource_langandtarget_langpositionally after
the text, for exampletranslate_text("Hello", None, "DE"). Keyword use is
unchanged; omittingtarget_langstill raisesTypeError.- Added the
document_idproperty toDocumentStatus, read from the status
response oftranslate_document_get_status()(falling back to the handle's
document ID). translate_document(),translate_document_from_filepath()and
translate_document_upload()now also acceptsource_langand
target_langas positional arguments after the input (and output)
arguments, for exampletranslate_document_upload(file, "EN", "DE").
Keyword use is unchanged.- Added the
writing_styleandextra_body_parametersoptions to
rephrase_text(), and theextra_body_parametersoption to
correct_text().writing_styleandtoneaccept aWritingStyleor
WritingTonemember or a string. - Added
update_multilingual_glossary()to theDeepLClientclass to rename a
multilingual glossary and/or merge dictionaries into it in one request,
sending only the options that are set. - Added
get_multilingual_glossary_dictionary_entries()to theDeepLClient
class, returning theMultilingualGlossaryDictionaryEntriesof one dictionary
and raisingGlossaryNotFoundExceptionif the glossary has none for the
language pair. - Added the
extra_body_parametersoption tocreate_multilingual_glossary(),
create_multilingual_glossary_from_csv(),
update_multilingual_glossary_name(),
update_multilingual_glossary_dictionary(),
update_multilingual_glossary_dictionary_from_csv(),
replace_multilingual_glossary_dictionary()and
replace_multilingual_glossary_dictionary_from_csv(). get_multilingual_glossary()accepts aMultilingualGlossaryInfoobject, as
glossary, besides a glossary ID.- Added the argument names
dictionaries(create_multilingual_glossary()),
dictionary(update_multilingual_glossary_dictionary(),
replace_multilingual_glossary_dictionary()),csv(the
*_multilingual_glossary*_from_csv()functions) andglossary
(get_multilingual_glossary()). MultilingualGlossaryInfo,MultilingualGlossaryDictionaryInfoand
MultilingualGlossaryDictionaryEntriesare exported from thedeeplpackage.- Added
MultilingualGlossaryDictionaryInfo.to_json(). - Added the
content_typeandextra_body_parametersoptions to
import_translation_memory_from_filepath(), and theextra_body_parameters
option tocreate_translation_memory_import().content_typeis declared
when creating the import job and sent with the upload; extra body parameters
are added to the request that creates the import job and replace keys of
the same name. - Added the
TranslationMemoryJobStatusenum.TranslationMemoryJob.status
andTranslationMemoryJobResult.statusnow return its members for the
statusesawaiting_input,processing,completed,failedand
expired, and the plain string for any other value. Members are strings
that compare equal to the API value, so existing comparisons with strings
and theTranslationMemoryJobResult.STATUS_*constants keep working. - Added the
contentparameter name toupload_translation_memory_file()
for the file content, replacinginput_file. Positional calls are
unaffected. DocumentTranslationExceptionacceptsshould_retryand
http_status_code.translate_document()and
translate_document_from_filepath()copy both from the underlying
DeepLException; before they were alwaysFalseandNone.
Changed
- With
timeout_s,wait_until_translation_memory_job_done()now cuts its
last sleep short; previously it could run up to 5 seconds past the timeout. import_translation_memory_from_filepath()now reads the file and
export_translation_memory_to_filepath()now checks the output path before
creating the job, so theseOSErrors are raised without creating a job;
previously the job was created first.translate_text()now acceptsglossaryandglossary_idswithout
source_lang, and DeepL uses the glossary dictionary for the detected
language pair; previously it raisedValueError. Document translation with a
glossary still requiressource_lang.- A path in
server_urlis now kept; previously the last path segment was
dropped. - HTTP 401 responses now raise
AuthorizationException; previously
DeepLException. - Creating a
Translatornow emits aDeprecationWarning; previously it did
not. - HTTP 404 responses raise
NotFoundExceptioninstead ofDeepLException
(glossary functions keep raisingGlossaryNotFoundException, now a
subclass ofNotFoundException). - The
User-Agentplatform information now ends withpython/<version>;
previously it also included therequestsversion. - Target languages
ENandPTare now sent to the API, which translates them
intoEN-USandPT-PT; previously they were rejected client-side. get_source_languages(),get_target_languages(), and
get_glossary_languages()now use the/v3/languagesendpoint
internally instead of the deprecated/v2/languagesand
/v2/glossary-language-pairsendpoints. Public signatures and return
types are unchanged, but the returned language lists may now include
additional languages.- The default
chunk_sizeoftranslate_document_download()and
download_translation_memory_export()is now 64 KiB instead of 1 byte, so
downloads intooutput_fileno longer write one byte per call. The written
content is unchanged; an explicitchunk_sizestill applies. DocumentStatus.statusis now typedUnion[DocumentStatus.Status, str]: a
status value the API returns that this version does not know is kept as a
string instead of raisingValueError. Type-checked code that reads
status.status.valuemay need anisinstance(..., DocumentStatus.Status)
guard;str(status)returns the status string in both cases.
Deprecated
Translatoris deprecated in favour ofDeepLClient, which supports all its
functions, and will be removed in the next major version.GlossaryNotFoundExceptionis deprecated, catchNotFoundExceptioninstead.
It will be removed in the next major version.auth_key_is_free_account()is deprecated, useis_free_account_auth_key().
Calling it emits aDeprecationWarning.- The module-level setting
deepl.http_client.user_agentis deprecated in
favour of aUser-Agententry in theheadersoption, and will be removed in
the next major version. Assigning it emits aDeprecationWarning. - Calling
translate_document_download()or
download_translation_memory_export()withoutoutput_filenow emits a
DeprecationWarning. It still returns the streamingrequests.Response; in
the next major versionoutput_filewill be required and both methods will
returnNone. - Passing
skip_language_checktoTranslator()orDeepLClient(), or
skip_cachetoget_source_languages()orget_target_languages(), now
emits aDeprecationWarning. Both parameters have no effect and will be
removed in the next major version. Their defaults changed fromFalseto
None; passingFalseexplicitly also warns. - The module-level settings
deepl.http_client.max_network_retriesand
deepl.http_client.min_connection_timeoutare deprecated in favour of the
max_retriesandtimeout_sclient options, and will be removed in the
next major version. They still apply to clients created without these
options. Assigning either setting emits aDeprecationWarning. - The language code constants of
Language(Language.GERMAN,
Language.ENGLISH_AMERICAN, ...) are deprecated and will be removed in the
next major version. Pass language codes as strings, for example"de", or
use the codes returned byget_source_languages()and
get_target_languages(). The constants keep working and emit no warning. - The
stylekeyword ofrephrase_text()is deprecated in favour of
writing_styleand emits aDeprecationWarning. It keeps working; if both
are given,writing_styleis used. get_multilingual_glossary_entries()is deprecated, use
get_multilingual_glossary_dictionary_entries().- The argument names
glossary_dicts,glossary_dict,csv_dataand
glossary_idof the multilingual glossary functions are deprecated, use
dictionaries,dictionary,csvandglossary. - The
input_filekeyword ofupload_translation_memory_file()is
deprecated in favour ofcontentand will be removed in the next major
version. Passing it emits aDeprecationWarning. SplitSentences.DEFAULTis deprecated, useSplitSentences.ALL, which it is
an alias of.translate_text_with_glossary()is deprecated, usetranslate_text()with
theglossaryparameter. Calling it emits aDeprecationWarning.
Fixed
- A glossary CSV row without a target term now raises a
ValueErrornaming
the row; previously a bareIndexError(it is still anIndexError). - A connection that is reset or breaks off while a non-streamed response body
is read is now retried like other connection failures, and raises
ConnectionExceptionwithshould_retryTrueonce retries are used up.
create_developer_key()is still not retried after it. translate_document_download()now streams the translated document to
output_filein chunks, instead of first reading the whole document into
memory for the debug log.- A connection reset or timeout while
translate_document_download()or
download_translation_memory_export()reads the downloaded file now raises
ConnectionException, instead of arequestsexception. - HTTP 3xx responses that are not followed as redirects (e.g. 300, 304, or a
redirect withoutLocation) now raiseDeepLExceptionwith
http_status_code, instead of being parsed as a successful response. - TLS and certificate failures, and proxy failures (including a failure to
connect to the proxy), are no longer retried and raiseConnectionException
withshould_retryFalse. - Query string values encode a space as
%20instead of+. - Fixed errors from the pre-signed translation memory upload and download URLs
reportingshould_retryas [secure] for HTTP 429 and 5xx, and dropping the
response body of a failed download from the message. - A failed
export_translation_memory_to_filepath()no longer leaves a
partially written file behind. DeepLException.should_retryis nowTruefor every HTTP 5xx error. It was
Falsefor all of them except 503, although they are retried.- An error response whose
messageordetailis not a string (a number,
object ornull) no longer raisesTypeError; the value is included as
JSON,nullis left out. - Leading and trailing whitespace in the authentication key is removed before
it is sent and before the:fxcheck that selects the API Free server. A
key of only whitespace is rejected withValueError. - Fixed
translate_text()raisingTypeErrorwhen a translation in the
response has nobilled_characters.TextResult.billed_charactersis now
Nonein that case. - Fixed
translate_text()raisingIndexErrorwhen the response holds fewer
translations than texts sent. It now raisesDeepLException. - Fixed
translate_document_get_status()raisingValueErrorand
translate_document_wait_until_done()stopping when the API returns a
document status this version does not know.DocumentStatus.statuskeeps
such a status as a string, and polling continues. - Fixed
translate_document()andtranslate_document_from_filepath()
sendingformality=defaultwhenformalitywas not set. It is now sent
only when given. - Fixed
translate_document_get_status()andtranslate_document_download()
not URL-encoding the document ID in the request path. - Fixed
translate_document_upload()returning an emptyDocumentHandlewhen
the response lacksdocument_idordocument_key, and raising
AttributeErrorwhen the response body is not a JSON object. Both now
raiseDeepLException. - Fixed the type annotation of
DocumentStatus.error_message, which is a
string, not an integer. - Fixed the style rule functions inserting the style rule ID and custom
instruction ID into the request path without escaping them, so an ID
containing/,?or#addressed a different resource. - Fixed the style rule functions raising a raw
KeyError,ValueError,
TypeErrororAttributeErroron a malformedStyleRuleInfoor
CustomInstructionresponse. They now raiseDeepLException. - Fixed the
DeprecationWarningmessages ofUsage.Detail.limit_exceededand
Usage.any_limit_exceeded, which named the replacement instead of the
deprecated property. They now read "limit_exceeded is deprecated, use
limit_reached" and "any_limit_exceeded is deprecated, use any_limit_reached". - Fixed the
Language.ENGLISHandLanguage.PORTUGUESEcomments that
claimed they are only usable as source languages. - Fixed
create_glossary_from_csv()failing with "Object of type bytes is not
JSON serializable" when the CSV data is given as bytes or as a file opened in
binary mode. - Fixed the
rephraseCLI command always failing with an unexpected keyword
argument error.--show-detected-sourcenow prints the detected source
language of each text. - Fixed the
translateCLI alias of thetextcommand failing with
'action_translate'. - Fixed the
extra_body_parametersdocumentation, which claimed that entries
do not overwrite request fields set by the library. They do, since 1.24.0. - Fixed
MultilingualGlossaryInfo.to_json()raisingTypeErrorwhen called on
an instance. - Fixed
rephrase_text()andcorrect_text()failing with "Object of type
... is not JSON serializable" whentarget_langis aLanguageobject or
the style or tone is aWritingStyleorWritingTonemember. The value is
now sent as its string code. rephrase_text()andcorrect_text()now raiseDeepLExceptionwhen the
response has noimprovementslist, fewer improvements than input texts, or
an improvement withouttext. Before, this raisedIndexErroror
AttributeError, or silently returned a shorter list.get_source_languages()andget_target_languages()now raise
DeepLExceptionwhen the response is not a list (they returned an empty
list before) or a language in it is missing its code or name (instead of a
rawKeyError,AttributeErrororTypeError). A nullfeaturesfield is
treated as no features.- Glossary IDs are URL-encoded in
/v3/glossariesrequest paths, and the
language pair in the query ofget_multilingual_glossary_entries()and
delete_multilingual_glossary_dictionary()is URL-encoded.
delete_multilingual_glossary_dictionary()now also strips regional variants
(EN-GBbecomesEN), like the other multilingual glossary functions. - A malformed multilingual glossary response raises
DeepLExceptioninstead of
a rawKeyError,TypeErrororValueError. MultilingualGlossaryInfo.to_json()returns a JSON-serialisable dictionary:
creation_timeas an ISO 8601 string anddictionariesas dictionaries.- Fixed the translation memory functions sending translation memory and job
IDs unencoded in the request path. IDs are now URL-encoded, so characters
such as/,?or spaces no longer change the requested URL. - Fixed the translation memory functions raising a raw
KeyError,
TypeErrororAttributeErrorwhen the API returns a malformed response.
They now raiseDeepLException.list_translation_memories()also raises
DeepLExceptionfor a non-JSON response instead of returning an empty list. - Fixed
get_usage()returning aUsagewith every value invalid when the
response body is not a JSON object. It now raisesDeepLException. translate_document_download()now raises errors with the API's error
message. Before, a 400, 404 or 456 response raised without it, and other
statuses reportedcontent: <file>.translate_document_wait_until_done()(andtranslate_document()with
timeout_s) shortens its last wait to the timeout, so it no longer runs up
to 5 seconds pasttimeout_s.