DeepL/deepl-python
Official Python library for the DeepL language translation API.
DeepL Python Library
What it is – An official Python client for the DeepL API, a commercial language‑AI service that provides high‑quality machine translation, text‑improvement (re‑phrasing), and document translation.
Key capabilities
- Text translation –
translate_text()accepts a single string or a list, auto‑detects the source language, and returns the translated text together with metadata (detected source, billed characters, model used). Options let you control sentence splitting, formality, glossaries, custom instructions, model type (quality‑ vs latency‑optimized), tag handling (HTML/XML), and more. - Write/Improve API –
rephrase_text()can rewrite or improve a passage in the same language or change its variant (e.g., US vs. UK English). You can request a style (academic, business, casual, simple) or tone (confident, diplomatic, etc.). - Document translation –
translate_document()/translate_document_from_filepath()handle full files (DOCX, PDF, etc.) by uploading, polling, and downloading the translated version. You can also call the lower‑level upload/status/download functions yourself. - Glossaries – Create, list, retrieve, and delete multilingual glossaries (user‑defined term mappings) via the new v3 endpoints. Glossaries can be supplied directly or uploaded from CSV.
- Advanced features – Translation memory, style rules, custom instructions (up to 10 per request), and fine‑grained XML tag handling (splitting, ignoring, etc.).
Typical usage
import deepl
client = deepl.DeepLClient("YOUR_AUTH_KEY")
# Simple text translation
result = client.translate_text("Hello, world!", target_lang="FR")
print(result.text) # → Bonjour, le monde !
# Re‑phrase English text in a business style
improved = client.rephrase_text(
"A rainbouw has seven colours.",
target_lang="EN-US",
style=deepl.WritingStyle.BUSINESS.value,
)
print(improved.text)
Installation & requirements
- Install with
pip install --upgrade deepl(Python 3.9‑3.13 supported). - Depends on
requests(≥ 2.32.4). On Ubuntu 22.04 you may need thepython3‑cachecontrolpackage.
Who might use it – Developers building translation‑enabled apps, localization pipelines, content‑creation tools, or any service that needs to call DeepL’s translation or text‑improvement capabilities programmatically.
All information above is taken directly from the repository’s README.
Related
- Project
- Project
- Project
- Project
- Project