SDKs overview
DeepL offers a range of Software Development Kits (SDKs) designed to simplify integration with its machine translation API. These SDKs provide language-specific bindings that encapsulate the underlying HTTP requests and responses, allowing developers to interact with DeepL's services using native programming constructs. The primary functions exposed through these SDKs typically include text translation, document translation, and language detection, aligning with the core capabilities of the DeepL API reference. By utilizing an SDK, developers can reduce boilerplate code, handle authentication more securely, and manage API request and response parsing more efficiently, contributing to faster development cycles and more maintainable applications.
The SDKs abstract common API interactions, such as setting up authentication with an API key and managing rate limits or error handling, which are crucial for robust application development. DeepL's official SDKs are maintained by the company and aim to provide consistent functionality and support across various popular programming languages. This standardization helps ensure that developers can expect reliable performance and up-to-date features as the DeepL API evolves.
Beyond official offerings, community-contributed libraries may also exist, providing additional language support or specialized functionalities. While official SDKs are generally recommended for their direct support and maintenance, community libraries can sometimes offer solutions for niche requirements or alternative integration patterns. Developers typically evaluate these options based on project needs, language preference, and the level of support and maturity of each library.
Official SDKs by language
DeepL provides official SDKs for several programming languages, enabling developers to integrate translation capabilities into their applications directly. These SDKs handle the underlying API communication, authentication, and data parsing, streamlining the development process. Each SDK is designed to reflect the idioms and best practices of its respective language.
| Language | Package/Module | Installation Command | Maturity |
|---|---|---|---|
| Python | deepl |
pip install deepl |
Official, Stable |
| Java | com.deepl.api |
Maven: add dependency; Gradle: add implementation | Official, Stable |
| C# | DeepL.Net |
dotnet add package DeepL.Net |
Official, Stable |
| PHP | deepl/deepl-php |
composer require deepl/deepl-php |
Official, Stable |
| Node.js | deepl-node |
npm install deepl-node |
Official, Stable |
| Go | github.com/DeepLcom/deepl-go |
go get github.com/DeepLcom/deepl-go |
Official, Stable |
| Ruby | deepl-ruby |
gem install deepl-ruby |
Official, Stable |
Each of these SDKs is actively maintained by DeepL, ensuring compatibility with the latest API versions and providing features such as automatic retry mechanisms, robust error handling, and support for all available translation parameters. Developers can find detailed documentation and usage examples for each specific SDK within the DeepL developer documentation.
Installation
Installing a DeepL SDK typically involves using the standard package manager for the respective programming language. The process is designed to be straightforward, allowing developers to quickly add the library to their project dependencies. Detailed instructions for each language are provided in the DeepL documentation, ensuring that the correct versions and dependencies are installed.
Python
For Python, the deepl package is installed using pip, the Python package installer. It is recommended to use a virtual environment to manage dependencies.
pip install deepl
Java
Java projects typically use Maven or Gradle for dependency management. Developers would add the DeepL Java library as a dependency in their pom.xml (Maven) or build.gradle (Gradle) file. For Maven, the dependency entry looks like this:
<dependency>
<groupId>com.deepl.api</groupId>
<artifactId>deepl-java</artifactId>
<version>1.x.x</version> <!-- Replace with the latest version -->
</dependency>
C#
For C# applications, the DeepL .NET library (DeepL.Net) is installed via NuGet, the package manager for .NET. This can be done through the .NET CLI:
dotnet add package DeepL.Net
PHP
PHP projects commonly use Composer for dependency management. The DeepL PHP library is added to a project using the composer require command:
composer require deepl/deepl-php
Node.js
Node.js developers can install the deepl-node package using npm or yarn, the popular package managers for JavaScript projects:
npm install deepl-node
Or with Yarn:
yarn add deepl-node
Go
Go modules are used to manage dependencies in Go projects. The DeepL Go library can be fetched and added to your project's go.mod file using the go get command:
go get github.com/DeepLcom/deepl-go
Ruby
Ruby projects use Bundler and RubyGems for dependency management. The deepl-ruby gem is installed using the gem install command or by adding it to your Gemfile and running bundle install:
gem install deepl-ruby
Quickstart example
This Python example demonstrates how to use the DeepL Python SDK to translate text from English to German. It covers initialization with an API key, calling the translation method, and printing the result. This foundational pattern is generally consistent across other DeepL SDKs, with language-specific syntax variations.
import deepl
import os
# Replace 'YOUR_DEEPL_API_KEY' with your actual DeepL API key.
# It's recommended to store your API key securely, e.g., in an environment variable.
auth_key = os.getenv("DEEPL_AUTH_KEY") # Get API key from environment variable
if auth_key is None:
print("Error: DEEPL_AUTH_KEY environment variable not set. Please set your DeepL API key.")
exit(1)
translator = deepl.Translator(auth_key)
# Source text to be translated
source_text = "Hello, world! How are you today?"
# Target language (e.g., 'de' for German)
target_language = "de"
try:
# Perform the translation
result = translator.translate_text(source_text, target_lang=target_language)
# Print the translated text
print(f"Original text: {source_text}")
print(f"Translated text ({target_language.upper()}): {result.text}")
# Example with formality parameter (if supported by target language)
# result_formal = translator.translate_text(source_text, target_lang="de", formality="prefer_formal")
# print(f"Translated text (German, formal): {result_formal.text}")
except deepl.exceptions.DeepLException as e:
print(f"DeepL API Error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
Before running this code, ensure your DeepL API key is set as an environment variable named DEEPL_AUTH_KEY. This practice enhances security by preventing the API key from being hardcoded directly into the source file. The DeepL API supports various source and target languages, and additional parameters can be passed to the translate_text method to control aspects like formality, glossary usage, and tag handling, as detailed in the DeepL API documentation. Integrating external APIs often involves managing secrets securely, a practice noted in general API security guidelines such as those provided by Twilio's API key security documentation.
Community libraries
While DeepL provides official SDKs for major programming languages, the open-source community may develop and maintain additional libraries or connectors. These community-driven projects can offer support for languages not covered by official SDKs, provide specialized integrations with other platforms, or implement unique features not present in the official offerings.
Community libraries are typically found on platforms like GitHub, PyPI, npm, or other language-specific package repositories. Developers interested in using community-contributed tools should consider their maturity, maintenance status, and the size and activity of their respective communities. Factors such as regular updates, clear documentation, and responsiveness to issues are important considerations when evaluating third-party libraries for production environments.
For example, while DeepL offers direct SDKs, developers in less common environments might find wrappers or integrations built by other users. These can range from simple API wrappers to more complex frameworks that integrate DeepL with content management systems, translation memory tools, or other enterprise applications. Always verify the source and security practices of any third-party library before incorporating it into a project, especially when handling sensitive data or API keys. The Mozilla Developer Network's guide on Fetch API usage, while not DeepL specific, offers general best practices for connecting to web services.