chub-dev 0.1.0 → 0.1.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +55 -0
  2. package/bin/chub-mcp +2 -0
  3. package/dist/airtable/docs/database/javascript/DOC.md +1437 -0
  4. package/dist/airtable/docs/database/python/DOC.md +1735 -0
  5. package/dist/amplitude/docs/analytics/javascript/DOC.md +1282 -0
  6. package/dist/amplitude/docs/analytics/python/DOC.md +1199 -0
  7. package/dist/anthropic/docs/claude-api/javascript/DOC.md +503 -0
  8. package/dist/anthropic/docs/claude-api/python/DOC.md +389 -0
  9. package/dist/asana/docs/tasks/DOC.md +1396 -0
  10. package/dist/assemblyai/docs/transcription/DOC.md +1043 -0
  11. package/dist/atlassian/docs/confluence/javascript/DOC.md +1347 -0
  12. package/dist/atlassian/docs/confluence/python/DOC.md +1604 -0
  13. package/dist/auth0/docs/identity/javascript/DOC.md +968 -0
  14. package/dist/auth0/docs/identity/python/DOC.md +1199 -0
  15. package/dist/aws/docs/s3/javascript/DOC.md +1773 -0
  16. package/dist/aws/docs/s3/python/DOC.md +1807 -0
  17. package/dist/binance/docs/trading/javascript/DOC.md +1315 -0
  18. package/dist/binance/docs/trading/python/DOC.md +1454 -0
  19. package/dist/braintree/docs/gateway/javascript/DOC.md +1278 -0
  20. package/dist/braintree/docs/gateway/python/DOC.md +1179 -0
  21. package/dist/chromadb/docs/embeddings-db/javascript/DOC.md +1263 -0
  22. package/dist/chromadb/docs/embeddings-db/python/DOC.md +1707 -0
  23. package/dist/clerk/docs/auth/javascript/DOC.md +1220 -0
  24. package/dist/clerk/docs/auth/python/DOC.md +274 -0
  25. package/dist/cloudflare/docs/workers/javascript/DOC.md +918 -0
  26. package/dist/cloudflare/docs/workers/python/DOC.md +994 -0
  27. package/dist/cockroachdb/docs/distributed-db/DOC.md +1500 -0
  28. package/dist/cohere/docs/llm/DOC.md +1335 -0
  29. package/dist/datadog/docs/monitoring/javascript/DOC.md +1740 -0
  30. package/dist/datadog/docs/monitoring/python/DOC.md +1815 -0
  31. package/dist/deepgram/docs/speech/javascript/DOC.md +885 -0
  32. package/dist/deepgram/docs/speech/python/DOC.md +685 -0
  33. package/dist/deepl/docs/translation/javascript/DOC.md +887 -0
  34. package/dist/deepl/docs/translation/python/DOC.md +944 -0
  35. package/dist/deepseek/docs/llm/DOC.md +1220 -0
  36. package/dist/directus/docs/headless-cms/javascript/DOC.md +1128 -0
  37. package/dist/directus/docs/headless-cms/python/DOC.md +1276 -0
  38. package/dist/discord/docs/bot/javascript/DOC.md +1090 -0
  39. package/dist/discord/docs/bot/python/DOC.md +1130 -0
  40. package/dist/elasticsearch/docs/search/DOC.md +1634 -0
  41. package/dist/elevenlabs/docs/text-to-speech/javascript/DOC.md +336 -0
  42. package/dist/elevenlabs/docs/text-to-speech/python/DOC.md +552 -0
  43. package/dist/firebase/docs/auth/DOC.md +1015 -0
  44. package/dist/gemini/docs/genai/javascript/DOC.md +691 -0
  45. package/dist/gemini/docs/genai/python/DOC.md +555 -0
  46. package/dist/github/docs/octokit/DOC.md +1560 -0
  47. package/dist/google/docs/bigquery/javascript/DOC.md +1688 -0
  48. package/dist/google/docs/bigquery/python/DOC.md +1503 -0
  49. package/dist/hubspot/docs/crm/javascript/DOC.md +1805 -0
  50. package/dist/hubspot/docs/crm/python/DOC.md +2033 -0
  51. package/dist/huggingface/docs/transformers/DOC.md +948 -0
  52. package/dist/intercom/docs/messaging/javascript/DOC.md +1844 -0
  53. package/dist/intercom/docs/messaging/python/DOC.md +1797 -0
  54. package/dist/jira/docs/issues/javascript/DOC.md +1420 -0
  55. package/dist/jira/docs/issues/python/DOC.md +1492 -0
  56. package/dist/kafka/docs/streaming/javascript/DOC.md +1671 -0
  57. package/dist/kafka/docs/streaming/python/DOC.md +1464 -0
  58. package/dist/landingai-ade/docs/api/DOC.md +620 -0
  59. package/dist/landingai-ade/docs/sdk/python/DOC.md +489 -0
  60. package/dist/landingai-ade/docs/sdk/typescript/DOC.md +542 -0
  61. package/dist/landingai-ade/skills/SKILL.md +489 -0
  62. package/dist/launchdarkly/docs/feature-flags/javascript/DOC.md +1191 -0
  63. package/dist/launchdarkly/docs/feature-flags/python/DOC.md +1671 -0
  64. package/dist/linear/docs/tracker/DOC.md +1554 -0
  65. package/dist/livekit/docs/realtime/javascript/DOC.md +303 -0
  66. package/dist/livekit/docs/realtime/python/DOC.md +163 -0
  67. package/dist/mailchimp/docs/marketing/DOC.md +1420 -0
  68. package/dist/meilisearch/docs/search/DOC.md +1241 -0
  69. package/dist/microsoft/docs/onedrive/javascript/DOC.md +1421 -0
  70. package/dist/microsoft/docs/onedrive/python/DOC.md +1549 -0
  71. package/dist/mongodb/docs/atlas/DOC.md +2041 -0
  72. package/dist/notion/docs/workspace-api/javascript/DOC.md +1435 -0
  73. package/dist/notion/docs/workspace-api/python/DOC.md +1400 -0
  74. package/dist/okta/docs/identity/javascript/DOC.md +1171 -0
  75. package/dist/okta/docs/identity/python/DOC.md +1401 -0
  76. package/dist/openai/docs/chat/javascript/DOC.md +407 -0
  77. package/dist/openai/docs/chat/python/DOC.md +568 -0
  78. package/dist/paypal/docs/checkout/DOC.md +278 -0
  79. package/dist/pinecone/docs/sdk/javascript/DOC.md +984 -0
  80. package/dist/pinecone/docs/sdk/python/DOC.md +1395 -0
  81. package/dist/plaid/docs/banking/javascript/DOC.md +1163 -0
  82. package/dist/plaid/docs/banking/python/DOC.md +1203 -0
  83. package/dist/playwright-community/skills/login-flows/SKILL.md +108 -0
  84. package/dist/postmark/docs/transactional-email/DOC.md +1168 -0
  85. package/dist/prisma/docs/orm/javascript/DOC.md +1419 -0
  86. package/dist/prisma/docs/orm/python/DOC.md +1317 -0
  87. package/dist/qdrant/docs/vector-search/javascript/DOC.md +1221 -0
  88. package/dist/qdrant/docs/vector-search/python/DOC.md +1653 -0
  89. package/dist/rabbitmq/docs/message-queue/javascript/DOC.md +1193 -0
  90. package/dist/rabbitmq/docs/message-queue/python/DOC.md +1243 -0
  91. package/dist/razorpay/docs/payments/javascript/DOC.md +1219 -0
  92. package/dist/razorpay/docs/payments/python/DOC.md +1330 -0
  93. package/dist/redis/docs/key-value/javascript/DOC.md +1851 -0
  94. package/dist/redis/docs/key-value/python/DOC.md +2054 -0
  95. package/dist/registry.json +2817 -0
  96. package/dist/replicate/docs/model-hosting/DOC.md +1318 -0
  97. package/dist/resend/docs/email/DOC.md +1271 -0
  98. package/dist/salesforce/docs/crm/javascript/DOC.md +1241 -0
  99. package/dist/salesforce/docs/crm/python/DOC.md +1183 -0
  100. package/dist/search-index.json +1 -0
  101. package/dist/sendgrid/docs/email-api/javascript/DOC.md +371 -0
  102. package/dist/sendgrid/docs/email-api/python/DOC.md +656 -0
  103. package/dist/sentry/docs/error-tracking/javascript/DOC.md +1073 -0
  104. package/dist/sentry/docs/error-tracking/python/DOC.md +1309 -0
  105. package/dist/shopify/docs/storefront/DOC.md +457 -0
  106. package/dist/slack/docs/workspace/javascript/DOC.md +933 -0
  107. package/dist/slack/docs/workspace/python/DOC.md +271 -0
  108. package/dist/square/docs/payments/javascript/DOC.md +1855 -0
  109. package/dist/square/docs/payments/python/DOC.md +1728 -0
  110. package/dist/stripe/docs/api/DOC.md +1727 -0
  111. package/dist/stripe/docs/payments/DOC.md +1726 -0
  112. package/dist/stytch/docs/auth/javascript/DOC.md +1813 -0
  113. package/dist/stytch/docs/auth/python/DOC.md +1962 -0
  114. package/dist/supabase/docs/client/DOC.md +1606 -0
  115. package/dist/twilio/docs/messaging/python/DOC.md +469 -0
  116. package/dist/twilio/docs/messaging/typescript/DOC.md +946 -0
  117. package/dist/vercel/docs/platform/DOC.md +1940 -0
  118. package/dist/weaviate/docs/vector-db/javascript/DOC.md +1268 -0
  119. package/dist/weaviate/docs/vector-db/python/DOC.md +1388 -0
  120. package/dist/zendesk/docs/support/javascript/DOC.md +2150 -0
  121. package/dist/zendesk/docs/support/python/DOC.md +2297 -0
  122. package/package.json +22 -6
  123. package/skills/get-api-docs/SKILL.md +84 -0
  124. package/src/commands/annotate.js +83 -0
  125. package/src/commands/build.js +12 -1
  126. package/src/commands/feedback.js +150 -0
  127. package/src/commands/get.js +83 -42
  128. package/src/commands/search.js +7 -0
  129. package/src/index.js +43 -17
  130. package/src/lib/analytics.js +90 -0
  131. package/src/lib/annotations.js +57 -0
  132. package/src/lib/bm25.js +170 -0
  133. package/src/lib/cache.js +69 -6
  134. package/src/lib/config.js +8 -3
  135. package/src/lib/identity.js +99 -0
  136. package/src/lib/registry.js +103 -20
  137. package/src/lib/telemetry.js +86 -0
  138. package/src/mcp/server.js +177 -0
  139. package/src/mcp/tools.js +251 -0
@@ -0,0 +1,944 @@
1
+ ---
2
+ name: translation
3
+ description: "DeepL API client for Python with text and document translation, glossary management, and language detection"
4
+ metadata:
5
+ languages: "python"
6
+ versions: "1.23.0"
7
+ updated-on: "2026-03-02"
8
+ source: maintainer
9
+ tags: "deepl,translation,language,localization,api"
10
+ ---
11
+
12
+ # DeepL API Coding Guidelines (Python)
13
+
14
+ You are a DeepL API coding expert. Help me with writing code using the DeepL API calling the official Python SDK.
15
+
16
+ You can find the official SDK documentation and code samples here:
17
+ https://www.deepl.com/docs-api/
18
+
19
+ ## Golden Rule: Use the Correct and Current SDK
20
+
21
+ Always use the official DeepL Python SDK to call the DeepL API, which is the standard library for all DeepL API interactions.
22
+
23
+ **Library Name:** DeepL Python SDK
24
+ **PyPI Package:** `deepl`
25
+ **Current Version:** 1.23.0
26
+
27
+ **Installation:**
28
+ - **Correct:** `pip install deepl`
29
+ - **Incorrect:** `pip install pydeepl`, `pip install deepl-api`, `pip install deepl.py`
30
+
31
+ **APIs and Usage:**
32
+ - **Correct:** `import deepl`
33
+ - **Correct:** `translator = deepl.DeepLClient(auth_key)`
34
+ - **Incorrect:** `from deepl import Translator` (old API)
35
+ - **Incorrect:** `import pydeepl`
36
+
37
+ ## Initialization and API Key
38
+
39
+ Set the `DEEPL_AUTH_KEY` environment variable or pass the API key directly.
40
+
41
+ ```python
42
+ import deepl
43
+
44
+ # Using environment variable
45
+ import os
46
+ auth_key = os.environ.get('DEEPL_AUTH_KEY')
47
+ translator = deepl.DeepLClient(auth_key)
48
+
49
+ # Or pass API key directly (not recommended for production)
50
+ # translator = deepl.DeepLClient("your-api-key-here")
51
+ ```
52
+
53
+ ### Getting an API Key
54
+
55
+ Create a DeepL API account to receive your authentication key. With a DeepL API Free account, you can translate up to 500,000 characters per month for free.
56
+
57
+ ## Text Translation
58
+
59
+ ### Basic Translation
60
+
61
+ Translate a single text string:
62
+
63
+ ```python
64
+ import deepl
65
+
66
+ auth_key = os.environ.get('DEEPL_AUTH_KEY')
67
+ translator = deepl.DeepLClient(auth_key)
68
+
69
+ result = translator.translate_text("Hello, world!", target_lang="FR")
70
+ print(result.text) # "Bonjour, le monde !"
71
+ ```
72
+
73
+ The `translate_text` method:
74
+ - First parameter: text to translate (string or list of strings)
75
+ - `target_lang` parameter: target language code (required)
76
+ - `source_lang` parameter: source language code (optional, auto-detects if not specified)
77
+
78
+ ### Auto-Detection of Source Language
79
+
80
+ ```python
81
+ result = translator.translate_text("Hello, world!", target_lang="DE")
82
+ print(result.text) # "Hallo, Welt!"
83
+ print(result.detected_source_lang) # "EN"
84
+ ```
85
+
86
+ ### Specifying Source Language
87
+
88
+ ```python
89
+ result = translator.translate_text(
90
+ "Hello, world!",
91
+ source_lang="EN",
92
+ target_lang="ES"
93
+ )
94
+ print(result.text) # "¡Hola, mundo!"
95
+ ```
96
+
97
+ ### Multiple Texts Translation
98
+
99
+ Translate multiple texts in a single API call:
100
+
101
+ ```python
102
+ texts = [
103
+ "Hello, world!",
104
+ "How are you?",
105
+ "Good morning"
106
+ ]
107
+
108
+ results = translator.translate_text(texts, target_lang="JA")
109
+ for result in results:
110
+ print(result.text)
111
+ # こんにちは、世界!
112
+ # お元気ですか?
113
+ # おはようございます
114
+ ```
115
+
116
+ ### TextResult Properties
117
+
118
+ Each translation result contains:
119
+
120
+ ```python
121
+ result = translator.translate_text("Hello", target_lang="DE")
122
+
123
+ print(result.text) # Translated text: "Hallo"
124
+ print(result.detected_source_lang) # Source language: "EN"
125
+ print(result.billed_characters) # Characters charged
126
+ print(result.model_type_used) # Model type if specified
127
+ ```
128
+
129
+ ## Translation Options
130
+
131
+ ### Formality Control
132
+
133
+ Control the formality level of translations for supported languages (DE, FR, IT, ES, NL, PL, PT-BR, PT-PT, JA, RU):
134
+
135
+ ```python
136
+ # Informal translation
137
+ informal = translator.translate_text(
138
+ "How are you?",
139
+ target_lang="DE",
140
+ formality="less"
141
+ )
142
+ print(informal.text) # "Wie geht es dir?"
143
+
144
+ # Formal translation
145
+ formal = translator.translate_text(
146
+ "How are you?",
147
+ target_lang="DE",
148
+ formality="more"
149
+ )
150
+ print(formal.text) # "Wie geht es Ihnen?"
151
+ ```
152
+
153
+ Formality options:
154
+ - `"less"` - informal language
155
+ - `"more"` - formal language
156
+ - `"default"` - standard formality
157
+ - `"prefer_less"` - informal if available, otherwise default
158
+ - `"prefer_more"` - formal if available, otherwise default
159
+
160
+ ### Context Parameter
161
+
162
+ Provide additional context to improve translation accuracy (not translated, not billed):
163
+
164
+ ```python
165
+ result = translator.translate_text(
166
+ "bank",
167
+ source_lang="EN",
168
+ target_lang="DE",
169
+ context="financial institution"
170
+ )
171
+ print(result.text) # "Bank" (financial context)
172
+
173
+ result2 = translator.translate_text(
174
+ "bank",
175
+ source_lang="EN",
176
+ target_lang="DE",
177
+ context="riverside"
178
+ )
179
+ print(result2.text) # "Ufer" (riverbank)
180
+ ```
181
+
182
+ ### Model Type Selection
183
+
184
+ Choose between quality-optimized and latency-optimized models:
185
+
186
+ ```python
187
+ # Quality-optimized (higher quality, slower)
188
+ quality_result = translator.translate_text(
189
+ "Complex technical document",
190
+ source_lang="EN",
191
+ target_lang="DE",
192
+ model_type="quality_optimized"
193
+ )
194
+
195
+ # Latency-optimized (faster, still high quality)
196
+ fast_result = translator.translate_text(
197
+ "Simple message",
198
+ source_lang="EN",
199
+ target_lang="DE",
200
+ model_type="latency_optimized"
201
+ )
202
+ ```
203
+
204
+ ### Split Sentences Option
205
+
206
+ Control how text is split into sentences:
207
+
208
+ ```python
209
+ # Split by newlines and punctuation (default)
210
+ result1 = translator.translate_text(
211
+ "First sentence. Second sentence.",
212
+ target_lang="DE",
213
+ split_sentences="1"
214
+ )
215
+
216
+ # No splitting
217
+ result2 = translator.translate_text(
218
+ "First sentence. Second sentence.",
219
+ target_lang="DE",
220
+ split_sentences="0"
221
+ )
222
+
223
+ # Split by punctuation only (not newlines)
224
+ result3 = translator.translate_text(
225
+ "First sentence.\nSecond sentence.",
226
+ target_lang="DE",
227
+ split_sentences="nonewlines"
228
+ )
229
+ ```
230
+
231
+ ### Preserve Formatting
232
+
233
+ Prevent automatic format correction:
234
+
235
+ ```python
236
+ result = translator.translate_text(
237
+ "Hello, world!",
238
+ target_lang="DE",
239
+ preserve_formatting=True
240
+ )
241
+ # Preserves extra spaces
242
+ ```
243
+
244
+ ### HTML and XML Tag Handling
245
+
246
+ Parse and preserve markup tags:
247
+
248
+ ```python
249
+ # HTML tag handling
250
+ html_result = translator.translate_text(
251
+ "<p>Hello, <strong>world</strong>!</p>",
252
+ target_lang="DE",
253
+ tag_handling="html"
254
+ )
255
+ print(html_result.text) # "<p>Hallo, <strong>Welt</strong>!</p>"
256
+
257
+ # XML tag handling
258
+ xml_result = translator.translate_text(
259
+ "<text>Hello, <emphasis>world</emphasis>!</text>",
260
+ target_lang="DE",
261
+ tag_handling="xml"
262
+ )
263
+ ```
264
+
265
+ ### XML-Specific Options
266
+
267
+ Advanced XML handling options:
268
+
269
+ ```python
270
+ result = translator.translate_text(
271
+ "<root><p>First paragraph</p><ignore>Do not translate</ignore></root>",
272
+ source_lang="EN",
273
+ target_lang="DE",
274
+ tag_handling="xml",
275
+ outline_detection=False, # Disable automatic tag detection
276
+ splitting_tags=["p", "div"], # Tags that split sentences
277
+ non_splitting_tags=["span"], # Tags that don't split sentences
278
+ ignore_tags=["ignore", "code"] # Tags with untranslated content
279
+ )
280
+ ```
281
+
282
+ ## Text Improvement (Write API)
283
+
284
+ The Write API allows you to rephrase and improve text quality.
285
+
286
+ ### Basic Text Rephrasing
287
+
288
+ ```python
289
+ result = translator.rephrase_text(
290
+ "A rainbouw has seven colours.",
291
+ target_lang="EN-US"
292
+ )
293
+ print(result.text) # "A rainbow has seven colors."
294
+ ```
295
+
296
+ ### Style Options
297
+
298
+ Apply different writing styles:
299
+
300
+ ```python
301
+ # Business style
302
+ result = translator.rephrase_text(
303
+ "Thanks for your email. I'll get back to you soon.",
304
+ target_lang="EN",
305
+ style="business"
306
+ )
307
+
308
+ # Academic style
309
+ result = translator.rephrase_text(
310
+ "This study shows that...",
311
+ target_lang="EN",
312
+ style="academic"
313
+ )
314
+
315
+ # Casual style
316
+ result = translator.rephrase_text(
317
+ "I am writing to inform you...",
318
+ target_lang="EN",
319
+ style="casual"
320
+ )
321
+
322
+ # Simple style
323
+ result = translator.rephrase_text(
324
+ "The implementation of the aforementioned protocol...",
325
+ target_lang="EN",
326
+ style="simple"
327
+ )
328
+ ```
329
+
330
+ Available styles: `"business"`, `"academic"`, `"casual"`, `"simple"`, `"default"`
331
+
332
+ ### Tone Options
333
+
334
+ Apply different tones:
335
+
336
+ ```python
337
+ # Friendly tone
338
+ result = translator.rephrase_text(
339
+ "Please submit your report by Friday.",
340
+ target_lang="EN",
341
+ tone="friendly"
342
+ )
343
+
344
+ # Confident tone
345
+ result = translator.rephrase_text(
346
+ "I think this approach might work.",
347
+ target_lang="EN",
348
+ tone="confident"
349
+ )
350
+
351
+ # Diplomatic tone
352
+ result = translator.rephrase_text(
353
+ "This is wrong.",
354
+ target_lang="EN",
355
+ tone="diplomatic"
356
+ )
357
+
358
+ # Enthusiastic tone
359
+ result = translator.rephrase_text(
360
+ "This is a good result.",
361
+ target_lang="EN",
362
+ tone="enthusiastic"
363
+ )
364
+ ```
365
+
366
+ Available tones: `"friendly"`, `"confident"`, `"diplomatic"`, `"enthusiastic"`, `"default"`
367
+
368
+ ### Optional Style/Tone Application
369
+
370
+ Use `"prefer_"` prefix for optional application:
371
+
372
+ ```python
373
+ result = translator.rephrase_text(
374
+ "The meeting is scheduled for tomorrow.",
375
+ target_lang="EN",
376
+ tone="prefer_diplomatic"
377
+ )
378
+ # Applies diplomatic tone if suitable, otherwise uses default
379
+ ```
380
+
381
+ ## Document Translation
382
+
383
+ ### Basic Document Translation
384
+
385
+ Translate entire documents while preserving formatting:
386
+
387
+ ```python
388
+ import deepl
389
+
390
+ auth_key = os.environ.get('DEEPL_AUTH_KEY')
391
+ translator = deepl.DeepLClient(auth_key)
392
+
393
+ # Using file paths
394
+ translator.translate_document_from_filepath(
395
+ "/path/to/input.docx",
396
+ "/path/to/output.docx",
397
+ target_lang="DE"
398
+ )
399
+ ```
400
+
401
+ ### Document Translation with Options
402
+
403
+ ```python
404
+ translator.translate_document_from_filepath(
405
+ "Manual.pdf",
406
+ "Anleitung.pdf",
407
+ target_lang="DE",
408
+ formality="more"
409
+ )
410
+ ```
411
+
412
+ ### Using File Objects
413
+
414
+ ```python
415
+ with open("input.docx", "rb") as in_file, \
416
+ open("output.docx", "wb") as out_file:
417
+ translator.translate_document(
418
+ in_file,
419
+ out_file,
420
+ target_lang="DE",
421
+ formality="more"
422
+ )
423
+ ```
424
+
425
+ ### Supported Document Formats
426
+
427
+ DeepL supports various document formats:
428
+ - **Text documents:** docx, pptx, pdf, htm, html, txt
429
+ - **Spreadsheets:** xlsx
430
+ - **Others:** Check DeepL API documentation for complete list
431
+
432
+ ### Document Translation Error Handling
433
+
434
+ Handle errors and retrieve document handle for recovery:
435
+
436
+ ```python
437
+ try:
438
+ translator.translate_document_from_filepath(
439
+ "input.pdf",
440
+ "output.pdf",
441
+ target_lang="FR"
442
+ )
443
+ except deepl.DocumentTranslationException as error:
444
+ doc_id = error.document_handle.id
445
+ doc_key = error.document_handle.key
446
+ print(f"Document ID: {doc_id}")
447
+ print(f"Document Key: {doc_key}")
448
+ except deepl.DeepLException as error:
449
+ print(f"Error: {error}")
450
+ ```
451
+
452
+ ### Lower-Level Document Translation Methods
453
+
454
+ For advanced control over the document translation process:
455
+
456
+ ```python
457
+ # Upload document
458
+ with open("input.docx", "rb") as in_file:
459
+ handle = translator.translate_document_upload(
460
+ in_file,
461
+ target_lang="DE",
462
+ formality="more"
463
+ )
464
+
465
+ # Check translation status
466
+ status = translator.translate_document_get_status(handle)
467
+ print(f"Status: {status.status}")
468
+ print(f"Billed characters: {status.billed_characters}")
469
+
470
+ # Wait until translation is complete
471
+ translator.translate_document_wait_until_done(handle)
472
+
473
+ # Download translated document
474
+ with open("output.docx", "wb") as out_file:
475
+ translator.translate_document_download(handle, out_file)
476
+ ```
477
+
478
+ ### Polling Document Status
479
+
480
+ ```python
481
+ import time
482
+
483
+ with open("input.pdf", "rb") as in_file:
484
+ handle = translator.translate_document_upload(in_file, target_lang="FR")
485
+
486
+ while True:
487
+ status = translator.translate_document_get_status(handle)
488
+
489
+ if status.status == "done":
490
+ with open("output.pdf", "wb") as out_file:
491
+ translator.translate_document_download(handle, out_file)
492
+ break
493
+ elif status.status == "error":
494
+ raise Exception("Document translation failed")
495
+
496
+ time.sleep(5) # Wait 5 seconds before checking again
497
+ ```
498
+
499
+ ## Multilingual Glossaries (v3 API)
500
+
501
+ Glossaries allow you to specify custom translations for specific terms and phrases.
502
+
503
+ ### Creating Glossaries
504
+
505
+ ```python
506
+ from deepl import MultilingualGlossaryDictionaryEntries
507
+
508
+ # Define glossary entries
509
+ entries = {"artist": "Maler", "prize": "Gewinn"}
510
+ dictionaries = [
511
+ MultilingualGlossaryDictionaryEntries("EN", "DE", entries)
512
+ ]
513
+
514
+ # Create glossary
515
+ my_glossary = translator.create_multilingual_glossary(
516
+ "My glossary",
517
+ dictionaries
518
+ )
519
+
520
+ print(f"Glossary ID: {my_glossary.glossary_id}")
521
+ print(f"Created: {my_glossary.creation_time}")
522
+ ```
523
+
524
+ ### Creating Glossary from CSV
525
+
526
+ ```python
527
+ # CSV format:
528
+ # source,target
529
+ # artist,Maler
530
+ # prize,Gewinn
531
+
532
+ with open("glossary.csv", "r", encoding="utf-8") as f:
533
+ csv_data = f.read()
534
+
535
+ glossary = translator.create_multilingual_glossary_from_csv(
536
+ "CSV glossary",
537
+ source_lang="EN",
538
+ target_lang="DE",
539
+ csv_data=csv_data
540
+ )
541
+ ```
542
+
543
+ ### Listing Glossaries
544
+
545
+ ```python
546
+ glossaries = translator.list_multilingual_glossaries()
547
+
548
+ for g in glossaries:
549
+ print(f"Name: {g.name}")
550
+ print(f"ID: {g.glossary_id}")
551
+ print(f"Created: {g.creation_time}")
552
+ for dict_entry in g.dictionaries:
553
+ print(f" {dict_entry.source_lang} -> {dict_entry.target_lang}: {dict_entry.entry_count} entries")
554
+ ```
555
+
556
+ ### Retrieving Specific Glossary
557
+
558
+ ```python
559
+ # Get by ID
560
+ glossary = translator.get_multilingual_glossary("glossary-id-here")
561
+
562
+ # Find by name
563
+ glossaries = translator.list_multilingual_glossaries()
564
+ my_glossary = next((g for g in glossaries if g.name == "My glossary"), None)
565
+ ```
566
+
567
+ ### Viewing Glossary Entries
568
+
569
+ ```python
570
+ entries = translator.get_multilingual_glossary_entries(
571
+ glossary,
572
+ "EN",
573
+ "DE"
574
+ )
575
+ print(entries.dictionaries[0])
576
+ ```
577
+
578
+ ### Using Glossaries in Translation
579
+
580
+ ```python
581
+ # Using glossary ID
582
+ result = translator.translate_text(
583
+ "The artist won the prize",
584
+ source_lang="EN",
585
+ target_lang="DE",
586
+ glossary="glossary-id-here"
587
+ )
588
+
589
+ # Using glossary object
590
+ glossaries = translator.list_multilingual_glossaries()
591
+ my_glossary = glossaries[0]
592
+
593
+ result = translator.translate_text(
594
+ "The artist won the prize",
595
+ source_lang="EN",
596
+ target_lang="DE",
597
+ glossary=my_glossary
598
+ )
599
+
600
+ print(result.text) # Uses custom translations from glossary
601
+ ```
602
+
603
+ ### Editing Glossaries
604
+
605
+ #### Update Glossary Dictionary (Merge)
606
+
607
+ ```python
608
+ from deepl import MultilingualGlossaryDictionaryEntries
609
+
610
+ # Merge new entries with existing ones
611
+ new_entries = {"hello": "hallo", "prize": "Gewinn"}
612
+ glossary_dict = MultilingualGlossaryDictionaryEntries(
613
+ "EN", "DE", new_entries
614
+ )
615
+ translator.update_multilingual_glossary_dictionary(
616
+ glossary,
617
+ glossary_dict
618
+ )
619
+ ```
620
+
621
+ #### Replace Glossary Dictionary
622
+
623
+ ```python
624
+ # Replace all entries completely
625
+ replacement = {"goodbye": "Auf Wiedersehen"}
626
+ glossary_dict = MultilingualGlossaryDictionaryEntries(
627
+ "EN", "DE", replacement
628
+ )
629
+ translator.replace_multilingual_glossary_dictionary(
630
+ glossary,
631
+ glossary_dict
632
+ )
633
+ ```
634
+
635
+ #### Update from CSV
636
+
637
+ ```python
638
+ with open("new.csv", "r", encoding="utf-8") as f:
639
+ csv_data = f.read()
640
+
641
+ translator.update_multilingual_glossary_dictionary_from_csv(
642
+ glossary="glossary-id-here",
643
+ source_lang="EN",
644
+ target_lang="DE",
645
+ csv_data=csv_data
646
+ )
647
+ ```
648
+
649
+ #### Rename Glossary
650
+
651
+ ```python
652
+ glossary = translator.update_multilingual_glossary_name(
653
+ glossary,
654
+ "New name"
655
+ )
656
+ ```
657
+
658
+ ### Deleting Glossaries
659
+
660
+ ```python
661
+ # Delete entire glossary
662
+ translator.delete_multilingual_glossary(glossary)
663
+
664
+ # Delete specific dictionary from glossary
665
+ translator.delete_multilingual_glossary_dictionary(
666
+ glossary,
667
+ glossary.dictionaries[0]
668
+ )
669
+ ```
670
+
671
+ ### Glossary Supported Languages
672
+
673
+ Check which language pairs support glossaries:
674
+
675
+ ```python
676
+ glossary_languages = translator.get_glossary_languages()
677
+
678
+ for lang_pair in glossary_languages:
679
+ print(f"{lang_pair.source_lang} -> {lang_pair.target_lang}")
680
+ ```
681
+
682
+ ## Language Detection and Information
683
+
684
+ ### Detecting Language
685
+
686
+ Detect the language of text without translating:
687
+
688
+ ```python
689
+ # Detect single text
690
+ detected = translator.detect_language("Bonjour, comment allez-vous?")
691
+ print(detected) # 'fr'
692
+
693
+ # Detect multiple texts
694
+ texts = ["Hello", "Bonjour", "Hola"]
695
+ languages = translator.detect_language(texts)
696
+ for text, lang in zip(texts, languages):
697
+ print(f'"{text}" is {lang}')
698
+ # "Hello" is en
699
+ # "Bonjour" is fr
700
+ # "Hola" is es
701
+ ```
702
+
703
+ ### Getting Supported Languages
704
+
705
+ ```python
706
+ # Get all supported languages
707
+ languages = translator.get_languages()
708
+ for lang in languages:
709
+ print(f"{lang.code}: {lang.name}")
710
+
711
+ # Get source languages
712
+ source_languages = translator.get_source_languages()
713
+
714
+ # Get target languages
715
+ target_languages = translator.get_target_languages()
716
+ for lang in target_languages:
717
+ print(f"{lang.code}: {lang.name}")
718
+ if hasattr(lang, 'supports_formality') and lang.supports_formality:
719
+ print(" Supports formality")
720
+
721
+ # Get glossary-supported languages
722
+ glossary_languages = translator.get_glossary_languages()
723
+ ```
724
+
725
+ Language object properties:
726
+ - `code` - ISO 639-1 language code (e.g., 'en', 'de', 'fr')
727
+ - `name` - Display name (e.g., 'English', 'German', 'French')
728
+ - `supports_formality` - Boolean (target languages only)
729
+
730
+ ## Usage Monitoring
731
+
732
+ ### Checking Account Usage
733
+
734
+ Monitor your character usage and account limits:
735
+
736
+ ```python
737
+ usage = translator.get_usage()
738
+
739
+ print(f"Characters used: {usage.character.count}")
740
+ print(f"Character limit: {usage.character.limit}")
741
+
742
+ if usage.character.limit_reached:
743
+ print("Character limit reached!")
744
+
745
+ # Calculate remaining characters
746
+ remaining = usage.character.limit - usage.character.count
747
+ print(f"Remaining characters: {remaining}")
748
+
749
+ # Document usage (if available)
750
+ if hasattr(usage, 'document'):
751
+ print(f"Documents translated: {usage.document.count}")
752
+ print(f"Document limit: {usage.document.limit}")
753
+ ```
754
+
755
+ ### Account Tiers
756
+
757
+ - **DeepL API Free:** 500,000 characters/month, up to 2 active API keys
758
+ - **DeepL API Pro:** Pay-as-you-go, up to 25 active API keys, cost control limits
759
+
760
+ ## Error Handling
761
+
762
+ ### Common Error Patterns
763
+
764
+ ```python
765
+ try:
766
+ result = translator.translate_text("Hello", target_lang="DE")
767
+ print(result.text)
768
+ except deepl.AuthorizationException:
769
+ print("Authentication failed. Check your API key.")
770
+ except deepl.QuotaExceededException:
771
+ print("Quota exceeded. Monthly character limit reached.")
772
+ except deepl.TooManyRequestsException:
773
+ print("Too many requests. Please slow down.")
774
+ except deepl.DeepLException as error:
775
+ print(f"Translation error: {error}")
776
+ ```
777
+
778
+ ### Document Translation Errors
779
+
780
+ ```python
781
+ try:
782
+ translator.translate_document_from_filepath(
783
+ "input.docx",
784
+ "output.docx",
785
+ target_lang="DE"
786
+ )
787
+ except deepl.DocumentTranslationException as error:
788
+ # Document was uploaded but translation failed
789
+ doc_id = error.document_handle.id
790
+ doc_key = error.document_handle.key
791
+ print(f"Can retry with document ID: {doc_id}")
792
+ except deepl.DeepLException as error:
793
+ # Upload or other error
794
+ print(f"Error: {error}")
795
+ ```
796
+
797
+ ## Advanced Configuration
798
+
799
+ ### Custom Server URL
800
+
801
+ For DeepL API Pro plans with custom endpoints:
802
+
803
+ ```python
804
+ translator = deepl.DeepLClient(
805
+ auth_key,
806
+ server_url="https://api.deepl.com" # Pro endpoint
807
+ # or "https://api-free.deepl.com" for Free endpoint
808
+ )
809
+ ```
810
+
811
+ ### HTTP Options
812
+
813
+ Configure timeout and other HTTP options:
814
+
815
+ ```python
816
+ translator = deepl.DeepLClient(
817
+ auth_key,
818
+ max_retries=5,
819
+ timeout=30.0 # seconds
820
+ )
821
+ ```
822
+
823
+ ## Async Support
824
+
825
+ DeepL Python SDK does not currently provide native async/await support. For async operations, use a thread pool executor:
826
+
827
+ ```python
828
+ import asyncio
829
+ from concurrent.futures import ThreadPoolExecutor
830
+
831
+ executor = ThreadPoolExecutor(max_workers=5)
832
+ translator = deepl.DeepLClient(auth_key)
833
+
834
+ async def translate_async(text, target_lang):
835
+ loop = asyncio.get_event_loop()
836
+ result = await loop.run_in_executor(
837
+ executor,
838
+ translator.translate_text,
839
+ text,
840
+ None,
841
+ target_lang
842
+ )
843
+ return result.text
844
+
845
+ async def main():
846
+ result = await translate_async("Hello, world!", "FR")
847
+ print(result)
848
+
849
+ asyncio.run(main())
850
+ ```
851
+
852
+ ## Complete Translation Example
853
+
854
+ ```python
855
+ import deepl
856
+ import os
857
+
858
+ auth_key = os.environ.get('DEEPL_AUTH_KEY')
859
+ translator = deepl.DeepLClient(auth_key)
860
+
861
+ def complete_example():
862
+ try:
863
+ # 1. Check usage
864
+ usage = translator.get_usage()
865
+ remaining = usage.character.limit - usage.character.count
866
+ print(f"Remaining: {remaining} characters")
867
+
868
+ # 2. Get supported languages
869
+ target_langs = translator.get_target_languages()
870
+ german_lang = next((l for l in target_langs if l.code == 'DE'), None)
871
+ if german_lang and hasattr(german_lang, 'supports_formality'):
872
+ print(f"German supports formality: {german_lang.supports_formality}")
873
+
874
+ # 3. Translate with options
875
+ result = translator.translate_text(
876
+ "How are you doing today?",
877
+ target_lang="DE",
878
+ formality="more"
879
+ )
880
+ print(f"Translation: {result.text}")
881
+ print(f"Detected source: {result.detected_source_lang}")
882
+
883
+ # 4. Translate document
884
+ translator.translate_document_from_filepath(
885
+ "document.pdf",
886
+ "dokument.pdf",
887
+ target_lang="DE",
888
+ formality="more"
889
+ )
890
+
891
+ print("Translation complete!")
892
+ except deepl.DeepLException as error:
893
+ print(f"Error: {error}")
894
+
895
+ complete_example()
896
+ ```
897
+
898
+ ## Type Hints Support
899
+
900
+ The DeepL Python SDK includes type hints for better IDE support:
901
+
902
+ ```python
903
+ from typing import List
904
+ import deepl
905
+
906
+ auth_key: str = os.environ.get('DEEPL_AUTH_KEY')
907
+ translator: deepl.DeepLClient = deepl.DeepLClient(auth_key)
908
+
909
+ def translate_texts(texts: List[str], target: str) -> List[str]:
910
+ results: List[deepl.TextResult] = translator.translate_text(
911
+ texts,
912
+ target_lang=target
913
+ )
914
+ return [result.text for result in results]
915
+
916
+ translations: List[str] = translate_texts(
917
+ ["Hello", "Goodbye"],
918
+ "FR"
919
+ )
920
+ ```
921
+
922
+ ## Python Version Support
923
+
924
+ The deepl Python package supports Python 3.9, 3.10, 3.11, 3.12, and 3.13.
925
+
926
+ ## Legacy API (v1/v2) - Deprecated
927
+
928
+ If you're using the old `Translator` class from earlier versions, migrate to `DeepLClient`:
929
+
930
+ ```python
931
+ # Old API (deprecated)
932
+ # translator = deepl.Translator(auth_key)
933
+
934
+ # New API (current)
935
+ translator = deepl.DeepLClient(auth_key)
936
+ ```
937
+
938
+ The method names remain mostly the same, but `DeepLClient` is the recommended approach.
939
+
940
+ ## Additional Resources
941
+
942
+ - Official Documentation: https://www.deepl.com/docs-api/
943
+ - GitHub Repository: https://github.com/DeepLcom/deepl-python
944
+ - PyPI Package: https://pypi.org/project/deepl/