Skip to main content

DeepL Haystack Integration

Haystack integration with DeepL translation services provider.

CI/CD Tests Coverage Status Tests types - Mypy Ruff
Package PyPI PyPI - Downloads PyPI - Python Version GitHub

Documentation: https://haystack.deepset.ai/integrations/deepl

Source Code: https://github.com/dribia/deepl-haystack


Installation

This project resides in the Python Package Index (PyPI), so it can easily be installed with pip:

pip install deepl-haystack

Usage

The DeepL Haystack integration provides two Haystack components: DeepLTextTranslator and DeepLDocumentTranslator. These components can be used to translate text and documents, respectively, using the DeepL API.

Examples

To run these examples you'll need a working DeepL API key. You can get one by signing up at the DeepL API website.

Standalone Text Translation

from haystack.utils import Secret

from deepl_haystack import DeepLTextTranslator

translator = DeepLTextTranslator(
    api_key=Secret.from_token("your_api_key_here"), source_lang="EN", target_lang="ES"
)

translated_text = translator.run("Hello, world!")
print(translated_text)
# {'translation': '¡Hola, mundo!', 'meta': {'source_lang': 'EN', 'target_lang': 'ES'}}

Standalone Document Translation

from haystack.dataclasses import Document
from haystack.utils import Secret

from deepl_haystack import DeepLDocumentTranslator

translator = DeepLDocumentTranslator(
    api_key=Secret.from_token("your_api_key_here"), source_lang="EN", target_lang="ES"
)

documents_to_translate = [
    Document(content="Hello, world!"),
    Document(content="Goodbye, Joe!", meta={"name": "Joe"}),
]

translated_documents = translator.run(documents_to_translate)
print("\n".join([f"{doc.content}, {doc.meta}" for doc in translated_documents]))
# ¡Hola, mundo!, {'source_lang': 'EN', 'target_lang': 'ES'}
# ¡Adiós, Joe!, {'name': 'Joe', 'source_lang': 'EN', 'target_lang': 'ES'}

Haystack Pipeline Integration

from haystack import Pipeline
from haystack.components.converters import TextFileToDocument
from haystack.components.writers import DocumentWriter
from haystack.dataclasses.byte_stream import ByteStream
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.utils import Secret

from deepl_haystack import DeepLDocumentTranslator

document_store = InMemoryDocumentStore()

pipeline = Pipeline()
pipeline.add_component(instance=TextFileToDocument(), name="converter")
pipeline.add_component(
    instance=DeepLDocumentTranslator(
        api_key=Secret.from_token("your_api_key_here"),
        target_lang="ES",
    ),
    name="translator",
)
pipeline.add_component(
    instance=DocumentWriter(document_store=document_store), name="document_store"
)
pipeline.connect("converter", "translator")
pipeline.connect("translator", "document_store")
pipeline.run({"converter": {"sources": [ByteStream.from_string("Hello world!")]}})
print(document_store.filter_documents())
# [Document(id=..., content: '¡Hola, mundo!', meta: {'source_lang': 'EN', 'language': 'ES'})]

Contributing

uv is the best way to interact with this project, to install it, follow the official uv installation guide.

With uv installed, one can install the project dependencies with:

uv sync

Then, to run the project unit tests:

make test-unit

To run the linters (ruff and mypy):

make lint

To apply all code formatting:

make format

And finally, to run the project integration tests (which actually use the DeepL API), you should either have the DEEPL_API_KEY environment variable set, or create a .env file:

DEEPL_API_KEY=your_api_key_here

And run:

make test-integration

License

deepl-haystack is distributed under the terms of the MIT license. Check the LICENSE file for further details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deepl_haystack-0.4.1.tar.gz (112.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deepl_haystack-0.4.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file deepl_haystack-0.4.1.tar.gz.

File metadata

  • Download URL: deepl_haystack-0.4.1.tar.gz
  • Upload date:
  • Size: 112.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for deepl_haystack-0.4.1.tar.gz
Algorithm Hash digest
SHA256 ebcb1ec729bde134c9ff5d7ac70f05e5f06a0b190bde0c30f7a9b917584ba99f
MD5 6298ad6cc4cc1e3d1bb983fea298f26a
BLAKE2b-256 73c7e70a4b51125e7a10229acfbf748ae6ef8e5a3efddbcede5c3ecc4eaf3089

See more details on using hashes here.

File details

Details for the file deepl_haystack-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: deepl_haystack-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for deepl_haystack-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b460d760f4c96df611dc57324865ac45cdeace24f9b88bd4d4403659612f4d22
MD5 53d8fbd2ee8ae6ac6d65df22ce6ab9da
BLAKE2b-256 9ecc0998bd7f265db3b8c917a09fbad777959d0f6f0de7648a85c36edc8eaae6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page