azure-ai-translation-document


Nameazure-ai-translation-document JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/Azure/azure-sdk-for-python/tree/main/sdk
SummaryMicrosoft Azure Ai Translation Document Client Library for Python
upload_time2024-11-12 18:39:48
maintainerNone
docs_urlNone
authorMicrosoft Corporation
requires_python>=3.8
licenseMIT License
keywords azure azure sdk
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Azure Document Translation client library for Python

Azure Cognitive Services Document Translation is a cloud service that can be used to translate multiple and complex documents across languages and dialects while preserving original document structure and data format.
Use the client library for Document Translation to:

* Translate numerous, large files from an Azure Blob Storage container to a target container in your language of choice.
* Check the translation status and progress of each document in the translation operation.
* Apply a custom translation model or glossaries to tailor translation to your specific case.

[Source code][python-dt-src]
| [Package (PyPI)][python-dt-pypi]
| [Package (Conda)](https://anaconda.org/microsoft/azure-ai-translation-document/)
| [API reference documentation][python-dt-ref-docs]
| [Product documentation][python-dt-product-docs]
| [Samples][python-dt-samples]

## _Disclaimer_

_Azure SDK Python packages support for Python 2.7 has ended 01 January 2022. For more information and questions, please refer to https://github.com/Azure/azure-sdk-for-python/issues/20691_

## Getting started

### Prerequisites
* Python 3.8 or later is required to use this package.
* You must have an [Azure subscription][azure_subscription] and a
[Translator resource][DT_resource] to use this package.

### Install the package

Install the Azure Document Translation client library for Python with [pip][pip]:

```bash
pip install --pre azure-ai-translation-document
```

> Note: This version of the client library defaults to the v2024-05-01 version of the service

#### Create a Translator resource

The Document Translation feature supports [single-service access][single_service] only.
To access the service, create a Translator resource.

You can create the resource using

**Option 1:** [Azure Portal][azure_portal_create_DT_resource]

**Option 2:** [Azure CLI][azure_cli_create_DT_resource].
Below is an example of how you can create a Translator resource using the CLI:

```bash
# Create a new resource group to hold the Translator resource -
# if using an existing resource group, skip this step
az group create --name my-resource-group --location westus2
```

```bash
# Create document translation
az cognitiveservices account create \
    --name document-translation-resource \
    --custom-domain document-translation-resource \
    --resource-group my-resource-group \
    --kind TextTranslation \
    --sku S1 \
    --location westus2 \
    --yes
```

### Authenticate the client

In order to interact with the Document Translation feature service, you will need to create an instance of a client.
An **endpoint** and **credential** are necessary to instantiate the client object.

#### Looking up the endpoint

You can find the endpoint for your Translator resource using the
[Azure Portal][azure_portal_get_endpoint].

> Note that the service requires a custom domain endpoint. Follow the instructions in the above link to format your endpoint:
> https://{NAME-OF-YOUR-RESOURCE}.cognitiveservices.azure.com/

#### Get the API key

The API key can be found in the Azure Portal or by running the following Azure CLI command:

```az cognitiveservices account keys list --name "resource-name" --resource-group "resource-group-name"```

#### Create the client with AzureKeyCredential

To use an [API key][cognitive_authentication_api_key] as the `credential` parameter,
pass the key as a string into an instance of [AzureKeyCredential][azure-key-credential].

<!-- SNIPPET:sample_authentication.create_dt_client_with_key -->

```python
from azure.core.credentials import AzureKeyCredential
from azure.ai.translation.document import DocumentTranslationClient

endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"]
key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"]

document_translation_client = DocumentTranslationClient(endpoint, AzureKeyCredential(key))
```

<!-- END SNIPPET -->

#### Create the client with an Azure Active Directory credential

`AzureKeyCredential` authentication is used in the examples in this getting started guide, but you can also
authenticate with Azure Active Directory using the [azure-identity][azure_identity] library.

To use the [DefaultAzureCredential][default_azure_credential] type shown below, or other credential types provided
with the Azure SDK, please install the `azure-identity` package:

```pip install azure-identity```

You will also need to [register a new AAD application and grant access][register_aad_app] to your
Translator resource by assigning the `"Cognitive Services User"` role to your service principal.

Once completed, set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.

<!-- SNIPPET:sample_authentication.create_dt_client_with_aad -->

```python
"""DefaultAzureCredential will use the values from these environment
variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
"""
from azure.identity import DefaultAzureCredential
from azure.ai.translation.document import DocumentTranslationClient

endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"]
credential = DefaultAzureCredential()

document_translation_client = DocumentTranslationClient(endpoint, credential)
```

<!-- END SNIPPET -->

## Key concepts

The Document Translation service requires that you upload your files to an Azure Blob Storage source container and provide
a target container where the translated documents can be written. Additional information about setting this up can be found in
the service documentation:

- [Set up Azure Blob Storage containers][source_containers] with your documents
- Optionally apply [glossaries][glossary] or a [custom model for translation][custom_model]
- Allow access to your storage account with either of the following options:
    - Generate [SAS tokens][sas_token] to your containers (or files) with the appropriate [permissions][sas_token_permissions]
    - Create and use a [managed identity][managed_identity] to grant access to your storage account

### DocumentTranslationClient

Interaction with the Document Translation client library begins with an instance of the `DocumentTranslationClient`.
The client provides operations for:

 - Creating a translation operation to translate documents in your source container(s) and write results to you target container(s).
 - Checking the status of individual documents in the translation operation and monitoring each document's progress.
 - Enumerating all past and current translation operations.
 - Identifying supported glossary and document formats.

### Translation Input

Input to the `begin_translation` client method can be provided in two different ways:

1) A single source container with documents can be translated to a different language:

```python
from azure.core.credentials import AzureKeyCredential
from azure.ai.translation.document import DocumentTranslationClient

document_translation_client = DocumentTranslationClient("<endpoint>", AzureKeyCredential("<api_key>"))
poller = document_translation_client.begin_translation("<sas_url_to_source>", "<sas_url_to_target>", "<target_language>")
```

2) Or multiple different sources can be provided each with their own targets.

<!-- SNIPPET:sample_translate_multiple_inputs.multiple_translation -->

```python
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.translation.document import DocumentTranslationClient, DocumentTranslationInput, TranslationTarget

endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"]
key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"]
source_container_url_1 = os.environ["AZURE_SOURCE_CONTAINER_URL_1"]
source_container_url_2 = os.environ["AZURE_SOURCE_CONTAINER_URL_2"]
target_container_url_fr = os.environ["AZURE_TARGET_CONTAINER_URL_FR"]
target_container_url_ar = os.environ["AZURE_TARGET_CONTAINER_URL_AR"]
target_container_url_es = os.environ["AZURE_TARGET_CONTAINER_URL_ES"]

client = DocumentTranslationClient(endpoint, AzureKeyCredential(key))

poller = client.begin_translation(
    inputs=[
        DocumentTranslationInput(
            source_url=source_container_url_1,
            targets=[
                TranslationTarget(target_url=target_container_url_fr, language="fr"),
                TranslationTarget(target_url=target_container_url_ar, language="ar"),
            ],
        ),
        DocumentTranslationInput(
            source_url=source_container_url_2,
            targets=[TranslationTarget(target_url=target_container_url_es, language="es")],
        ),
    ]
)
result = poller.result()

print(f"Status: {poller.status()}")
print(f"Created on: {poller.details.created_on}")
print(f"Last updated on: {poller.details.last_updated_on}")
print(f"Total number of translations on documents: {poller.details.documents_total_count}")

print("\nOf total documents...")
print(f"{poller.details.documents_failed_count} failed")
print(f"{poller.details.documents_succeeded_count} succeeded")

for document in result:
    print(f"Document ID: {document.id}")
    print(f"Document status: {document.status}")
    if document.status == "Succeeded":
        print(f"Source document location: {document.source_document_url}")
        print(f"Translated document location: {document.translated_document_url}")
        print(f"Translated to language: {document.translated_to}\n")
    elif document.error:
        print(f"Error Code: {document.error.code}, Message: {document.error.message}\n")
```

<!-- END SNIPPET -->

> Note: the target_url for each target language must be unique.

To translate documents under a folder, or only translate certain documents, see [sample_begin_translation_with_filters.py][sample_begin_translation_with_filters].
See the service documentation for all [supported languages][supported_languages].

### Long-Running Operations

Long-running operations are operations which consist of an initial request sent to the service to start an operation,
followed by polling the service at intervals to determine whether the operation has completed or failed, and if it has
succeeded, to get the result.

Methods that translate documents are modeled as long-running operations.
The client exposes a `begin_<method-name>` method that returns a `DocumentTranslationLROPoller` or `AsyncDocumentTranslationLROPoller`. Callers should wait
for the operation to complete by calling `result()` on the poller object returned from the `begin_<method-name>` method.
Sample code snippets are provided to illustrate using long-running operations [below](#examples "Examples").

## Examples

The following section provides several code snippets covering some of the most common Document Translation tasks, including:

* [Translate your documents](#translate-your-documents "Translate Your Documents")
* [Translate multiple inputs](#translate-multiple-inputs "Translate Multiple Inputs")
* [List translation operations](#list-translation-operations "List Translation Operations")

### Translate your documents

Translate all the documents in your source container to the target container. To translate documents under a folder, or only translate certain documents, see [sample_begin_translation_with_filters.py][sample_begin_translation_with_filters].

```python
from azure.core.credentials import AzureKeyCredential
from azure.ai.translation.document import DocumentTranslationClient

endpoint = "https://<resource-name>.cognitiveservices.azure.com/"
credential = AzureKeyCredential("<api_key>")
source_container_sas_url_en = "<sas-url-en>"
target_container_sas_url_es = "<sas-url-es>"

document_translation_client = DocumentTranslationClient(endpoint, credential)

poller = document_translation_client.begin_translation(source_container_sas_url_en, target_container_sas_url_es, "es")

result = poller.result()

print(f"Status: {poller.status()}")
print(f"Created on: {poller.details.created_on}")
print(f"Last updated on: {poller.details.last_updated_on}")
print(f"Total number of translations on documents: {poller.details.documents_total_count}")

print("\nOf total documents...")
print(f"{poller.details.documents_failed_count} failed")
print(f"{poller.details.documents_succeeded_count} succeeded")

for document in result:
    print(f"Document ID: {document.id}")
    print(f"Document status: {document.status}")
    if document.status == "Succeeded":
        print(f"Source document location: {document.source_document_url}")
        print(f"Translated document location: {document.translated_document_url}")
        print(f"Translated to language: {document.translated_to}\n")
    else:
        print(f"Error Code: {document.error.code}, Message: {document.error.message}\n")
```

### Translate multiple inputs

Begin translating with documents in multiple source containers to multiple target containers in different languages.

<!-- SNIPPET:sample_translate_multiple_inputs.multiple_translation -->

```python
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.translation.document import DocumentTranslationClient, DocumentTranslationInput, TranslationTarget

endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"]
key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"]
source_container_url_1 = os.environ["AZURE_SOURCE_CONTAINER_URL_1"]
source_container_url_2 = os.environ["AZURE_SOURCE_CONTAINER_URL_2"]
target_container_url_fr = os.environ["AZURE_TARGET_CONTAINER_URL_FR"]
target_container_url_ar = os.environ["AZURE_TARGET_CONTAINER_URL_AR"]
target_container_url_es = os.environ["AZURE_TARGET_CONTAINER_URL_ES"]

client = DocumentTranslationClient(endpoint, AzureKeyCredential(key))

poller = client.begin_translation(
    inputs=[
        DocumentTranslationInput(
            source_url=source_container_url_1,
            targets=[
                TranslationTarget(target_url=target_container_url_fr, language="fr"),
                TranslationTarget(target_url=target_container_url_ar, language="ar"),
            ],
        ),
        DocumentTranslationInput(
            source_url=source_container_url_2,
            targets=[TranslationTarget(target_url=target_container_url_es, language="es")],
        ),
    ]
)
result = poller.result()

print(f"Status: {poller.status()}")
print(f"Created on: {poller.details.created_on}")
print(f"Last updated on: {poller.details.last_updated_on}")
print(f"Total number of translations on documents: {poller.details.documents_total_count}")

print("\nOf total documents...")
print(f"{poller.details.documents_failed_count} failed")
print(f"{poller.details.documents_succeeded_count} succeeded")

for document in result:
    print(f"Document ID: {document.id}")
    print(f"Document status: {document.status}")
    if document.status == "Succeeded":
        print(f"Source document location: {document.source_document_url}")
        print(f"Translated document location: {document.translated_document_url}")
        print(f"Translated to language: {document.translated_to}\n")
    elif document.error:
        print(f"Error Code: {document.error.code}, Message: {document.error.message}\n")
```

<!-- END SNIPPET -->

### List translation operations

Enumerate over the translation operations submitted for the resource.

<!-- SNIPPET:sample_list_translations.list_translations -->

```python
from azure.core.credentials import AzureKeyCredential
from azure.ai.translation.document import DocumentTranslationClient

endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"]
key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"]

client = DocumentTranslationClient(endpoint, AzureKeyCredential(key))
operations = client.list_translation_statuses()

for operation in operations:
    print(f"ID: {operation.id}")
    print(f"Status: {operation.status}")
    print(f"Created on: {operation.created_on}")
    print(f"Last updated on: {operation.last_updated_on}")
    print(f"Total number of operations on documents: {operation.documents_total_count}")
    print(f"Total number of characters charged: {operation.total_characters_charged}")

    print("\nOf total documents...")
    print(f"{operation.documents_failed_count} failed")
    print(f"{operation.documents_succeeded_count} succeeded")
    print(f"{operation.documents_canceled_count} canceled\n")
```

<!-- END SNIPPET -->

To see how to use the Document Translation client library with Azure Storage Blob to upload documents, create SAS tokens
for your containers, and download the finished translated documents, see this [sample][sample_translation_with_azure_blob].
Note that you will need to install the [azure-storage-blob][azure_storage_blob] library to run this sample.

## Advanced Topics

The following section provides some insights for some advanced translation features such as glossaries and custom translation models.

### **Glossaries**

Glossaries are domain-specific dictionaries. For example, if you want to translate some medical-related documents, you may need support for the many words, terminology, and idioms in the medical field which you can't find in the standard translation dictionary, or you simply need specific translation. This is why Document Translation provides support for glossaries.

#### **How To Create Glossary File**

Document Translation supports glossaries in the following formats:

|**File Type**|**Extension**|**Description**|**Samples**|
|---------------|---------------|---------------|---------------|
|Tab-Separated Values/TAB|.tsv, .tab|Read more on [wikipedia][tsv_files_wikipedia]|[glossary_sample.tsv][sample_tsv_file]|
|Comma-Separated Values|.csv|Read more on [wikipedia][csv_files_wikipedia]|[glossary_sample.csv][sample_csv_file]|
|Localization Interchange File Format|.xlf, .xliff|Read more on [wikipedia][xlf_files_wikipedia]|[glossary_sample.xlf][sample_xlf_file]|

View all supported formats [here][supported_glossary_formats].

#### **How Use Glossaries in Document Translation**

In order to use glossaries with Document Translation, you first need to upload your glossary file to a blob container, and then provide the SAS URL to the file as in the code samples [sample_translation_with_glossaries.py][sample_translation_with_glossaries].

### **Custom Translation Models**

Instead of using Document Translation's engine for translation, you can use your own custom Azure machine/deep learning model.

#### **How To Create a Custom Translation Model**

For more info on how to create, provision, and deploy your own custom Azure translation model, please follow the instructions here: [Build, deploy, and use a custom model for translation][custom_translation_article]

#### **How To Use a Custom Translation Model With Document Translation**

In order to use a custom translation model with Document Translation, you first 
need to create and deploy your model, then follow the code sample [sample_translation_with_custom_model.py][sample_translation_with_custom_model] to use with Document Translation.

## Troubleshooting

### General

Document Translation client library will raise exceptions defined in [Azure Core][azure_core_exceptions].

### Logging

This library uses the standard
[logging][python_logging] library for logging.

Basic information about HTTP sessions (URLs, headers, etc.) is logged at `INFO` level.

Detailed `DEBUG` level logging, including request/response bodies and **unredacted**
headers, can be enabled on the client or per-operation with the `logging_enable` keyword argument.

See full SDK logging documentation with examples [here][sdk_logging_docs].

### Optional Configuration

Optional keyword arguments can be passed in at the client and per-operation level.
The azure-core [reference documentation][azure_core_ref_docs]
describes available configurations for retries, logging, transport protocols, and more.

## Next steps

The following section provides several code snippets illustrating common patterns used in the Document Translation Python client library.
More samples can be found under the [samples][samples] directory.

### More sample code

These code samples show common scenario operations with the Azure Document Translation client library.

* Client authentication: [sample_authentication.py][sample_authentication]
* Begin translating documents: [sample_begin_translation.py][sample_begin_translation]
* Translate with multiple inputs: [sample_translate_multiple_inputs.py][sample_translate_multiple_inputs]
* Check the status of documents: [sample_check_document_statuses.py][sample_check_document_statuses]
* List all submitted translation operations: [sample_list_translations.py][sample_list_translations]
* Apply a custom glossary to translation: [sample_translation_with_glossaries.py][sample_translation_with_glossaries]
* Use Azure Blob Storage to set up translation resources: [sample_translation_with_azure_blob.py][sample_translation_with_azure_blob]

### Async samples

This library also includes a complete set of async APIs. To use them, you must
first install an async transport, such as [aiohttp](https://pypi.org/project/aiohttp/). Async clients
are found under the `azure.ai.translation.document.aio` namespace.

* Client authentication: [sample_authentication_async.py][sample_authentication_async]
* Begin translating documents: [sample_begin_translation_async.py][sample_begin_translation_async]
* Translate with multiple inputs: [sample_translate_multiple_inputs_async.py][sample_translate_multiple_inputs_async]
* Check the status of documents: [sample_check_document_statuses_async.py][sample_check_document_statuses_async]
* List all submitted translation operations: [sample_list_translations_async.py][sample_list_translations_async]
* Apply a custom glossary to translation: [sample_translation_with_glossaries_async.py][sample_translation_with_glossaries_async]
* Use Azure Blob Storage to set up translation resources: [sample_translation_with_azure_blob_async.py][sample_translation_with_azure_blob_async]

### Additional documentation

For more extensive documentation on Azure Cognitive Services Document Translation, see the [Document Translation documentation][python-dt-product-docs] on docs.microsoft.com.

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com][cla].

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any additional questions or comments.

<!-- LINKS -->

[python-dt-src]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/azure/ai/translation/document
[python-dt-pypi]: https://aka.ms/azsdk/python/texttranslation/pypi
[python-dt-product-docs]: https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview
[python-dt-ref-docs]: https://aka.ms/azsdk/python/documenttranslation/docs
[python-dt-samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples

[azure_subscription]: https://azure.microsoft.com/free/
[DT_resource]: https://learn.microsoft.com/azure/ai-services/translator/document-translation/overview
[single_service]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=singleservice%2Cwindows
[pip]: https://pypi.org/project/pip/
[azure_portal_create_DT_resource]: https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesTextTranslation
[azure_cli_create_DT_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account-cli?tabs=windows
[azure-key-credential]: https://aka.ms/azsdk/python/core/azurekeycredential
[supported_languages]: https://docs.microsoft.com/azure/cognitive-services/translator/language-support#translate
[source_containers]: https://aka.ms/azsdk/documenttranslation/sas-permissions
[custom_model]: https://docs.microsoft.com/azure/cognitive-services/translator/custom-translator/quickstart-build-deploy-custom-model
[glossary]: https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview#supported-glossary-formats
[sas_token]: https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/create-sas-tokens?tabs=Containers#create-your-sas-tokens-with-azure-storage-explorer
[sas_token_permissions]: https://aka.ms/azsdk/documenttranslation/sas-permissions
[azure_storage_blob]: https://pypi.org/project/azure-storage-blob/

[azure_core_ref_docs]: https://aka.ms/azsdk/python/core/docs
[azure_core_exceptions]: https://aka.ms/azsdk/python/core/docs#module-azure.core.exceptions
[python_logging]: https://docs.python.org/3/library/logging.html
[azure_cli_endpoint_lookup]: https://docs.microsoft.com/cli/azure/cognitiveservices/account?view=azure-cli-latest#az-cognitiveservices-account-show
[azure_portal_get_endpoint]: https://learn.microsoft.com/azure/ai-services/translator/document-translation/quickstarts/document-translation-sdk?tabs=dotnet&pivots=programming-language-python
[cognitive_authentication_api_key]: https://learn.microsoft.com/azure/ai-services/translator/document-translation/quickstarts/document-translation-sdk?tabs=dotnet&pivots=programming-language-python
[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-azure-active-directory
[custom_subdomain]: https://docs.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain
[azure_identity]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
[managed_identity]: https://aka.ms/azsdk/documenttranslation/managed-identity
[sdk_logging_docs]: https://docs.microsoft.com/azure/developer/python/sdk/azure-sdk-logging

[samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples
[sample_authentication]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_authentication.py
[sample_authentication_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_authentication_async.py
[sample_begin_translation]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_begin_translation.py
[sample_begin_translation_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_begin_translation_async.py
[sample_translate_multiple_inputs]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_translate_multiple_inputs.py
[sample_translate_multiple_inputs_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translate_multiple_inputs_async.py
[sample_check_document_statuses]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_check_document_statuses.py
[sample_check_document_statuses_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_check_document_statuses_async.py
[sample_list_translations]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_list_translations.py
[sample_list_translations_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_list_translations_async.py
[sample_translation_with_glossaries]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_translation_with_glossaries.py
[sample_translation_with_glossaries_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translation_with_glossaries_async.py
[sample_translation_with_azure_blob]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_translation_with_azure_blob.py
[sample_translation_with_azure_blob_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translation_with_azure_blob_async.py
[sample_translation_with_custom_model]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_translation_with_custom_model.py
[sample_translation_with_custom_model_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translation_with_custom_model_async.py
[sample_begin_translation_with_filters]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_begin_translation_with_filters.py

[supported_glossary_formats]: https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview#supported-glossary-formats
[custom_translation_article]: https://docs.microsoft.com/azure/cognitive-services/translator/custom-translator/quickstart-build-deploy-custom-model
[tsv_files_wikipedia]: https://wikipedia.org/wiki/Tab-separated_values
[xlf_files_wikipedia]: https://wikipedia.org/wiki/XLIFF
[csv_files_wikipedia]: https://wikipedia.org/wiki/Comma-separated_values
[sample_tsv_file]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/assets/glossary_sample.tsv
[sample_csv_file]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/assets/glossary_sample.csv
[sample_xlf_file]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/assets/glossary_sample.xlf

[cla]: https://cla.microsoft.com
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
[coc_contact]: mailto:opencode@microsoft.com

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk",
    "name": "azure-ai-translation-document",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "azure, azure sdk",
    "author": "Microsoft Corporation",
    "author_email": "azpysdkhelp@microsoft.com",
    "download_url": "https://files.pythonhosted.org/packages/27/9b/416929c4d6d7e8e37bfeb7293c7ca326e652a8610f1308007caa831df40e/azure_ai_translation_document-1.1.0.tar.gz",
    "platform": null,
    "description": "# Azure Document Translation client library for Python\n\nAzure Cognitive Services Document Translation is a cloud service that can be used to translate multiple and complex documents across languages and dialects while preserving original document structure and data format.\nUse the client library for Document Translation to:\n\n* Translate numerous, large files from an Azure Blob Storage container to a target container in your language of choice.\n* Check the translation status and progress of each document in the translation operation.\n* Apply a custom translation model or glossaries to tailor translation to your specific case.\n\n[Source code][python-dt-src]\n| [Package (PyPI)][python-dt-pypi]\n| [Package (Conda)](https://anaconda.org/microsoft/azure-ai-translation-document/)\n| [API reference documentation][python-dt-ref-docs]\n| [Product documentation][python-dt-product-docs]\n| [Samples][python-dt-samples]\n\n## _Disclaimer_\n\n_Azure SDK Python packages support for Python 2.7 has ended 01 January 2022. For more information and questions, please refer to https://github.com/Azure/azure-sdk-for-python/issues/20691_\n\n## Getting started\n\n### Prerequisites\n* Python 3.8 or later is required to use this package.\n* You must have an [Azure subscription][azure_subscription] and a\n[Translator resource][DT_resource] to use this package.\n\n### Install the package\n\nInstall the Azure Document Translation client library for Python with [pip][pip]:\n\n```bash\npip install --pre azure-ai-translation-document\n```\n\n> Note: This version of the client library defaults to the v2024-05-01 version of the service\n\n#### Create a Translator resource\n\nThe Document Translation feature supports [single-service access][single_service] only.\nTo access the service, create a Translator resource.\n\nYou can create the resource using\n\n**Option 1:** [Azure Portal][azure_portal_create_DT_resource]\n\n**Option 2:** [Azure CLI][azure_cli_create_DT_resource].\nBelow is an example of how you can create a Translator resource using the CLI:\n\n```bash\n# Create a new resource group to hold the Translator resource -\n# if using an existing resource group, skip this step\naz group create --name my-resource-group --location westus2\n```\n\n```bash\n# Create document translation\naz cognitiveservices account create \\\n    --name document-translation-resource \\\n    --custom-domain document-translation-resource \\\n    --resource-group my-resource-group \\\n    --kind TextTranslation \\\n    --sku S1 \\\n    --location westus2 \\\n    --yes\n```\n\n### Authenticate the client\n\nIn order to interact with the Document Translation feature service, you will need to create an instance of a client.\nAn **endpoint** and **credential** are necessary to instantiate the client object.\n\n#### Looking up the endpoint\n\nYou can find the endpoint for your Translator resource using the\n[Azure Portal][azure_portal_get_endpoint].\n\n> Note that the service requires a custom domain endpoint. Follow the instructions in the above link to format your endpoint:\n> https://{NAME-OF-YOUR-RESOURCE}.cognitiveservices.azure.com/\n\n#### Get the API key\n\nThe API key can be found in the Azure Portal or by running the following Azure CLI command:\n\n```az cognitiveservices account keys list --name \"resource-name\" --resource-group \"resource-group-name\"```\n\n#### Create the client with AzureKeyCredential\n\nTo use an [API key][cognitive_authentication_api_key] as the `credential` parameter,\npass the key as a string into an instance of [AzureKeyCredential][azure-key-credential].\n\n<!-- SNIPPET:sample_authentication.create_dt_client_with_key -->\n\n```python\nfrom azure.core.credentials import AzureKeyCredential\nfrom azure.ai.translation.document import DocumentTranslationClient\n\nendpoint = os.environ[\"AZURE_DOCUMENT_TRANSLATION_ENDPOINT\"]\nkey = os.environ[\"AZURE_DOCUMENT_TRANSLATION_KEY\"]\n\ndocument_translation_client = DocumentTranslationClient(endpoint, AzureKeyCredential(key))\n```\n\n<!-- END SNIPPET -->\n\n#### Create the client with an Azure Active Directory credential\n\n`AzureKeyCredential` authentication is used in the examples in this getting started guide, but you can also\nauthenticate with Azure Active Directory using the [azure-identity][azure_identity] library.\n\nTo use the [DefaultAzureCredential][default_azure_credential] type shown below, or other credential types provided\nwith the Azure SDK, please install the `azure-identity` package:\n\n```pip install azure-identity```\n\nYou will also need to [register a new AAD application and grant access][register_aad_app] to your\nTranslator resource by assigning the `\"Cognitive Services User\"` role to your service principal.\n\nOnce completed, set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:\n`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.\n\n<!-- SNIPPET:sample_authentication.create_dt_client_with_aad -->\n\n```python\n\"\"\"DefaultAzureCredential will use the values from these environment\nvariables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET\n\"\"\"\nfrom azure.identity import DefaultAzureCredential\nfrom azure.ai.translation.document import DocumentTranslationClient\n\nendpoint = os.environ[\"AZURE_DOCUMENT_TRANSLATION_ENDPOINT\"]\ncredential = DefaultAzureCredential()\n\ndocument_translation_client = DocumentTranslationClient(endpoint, credential)\n```\n\n<!-- END SNIPPET -->\n\n## Key concepts\n\nThe Document Translation service requires that you upload your files to an Azure Blob Storage source container and provide\na target container where the translated documents can be written. Additional information about setting this up can be found in\nthe service documentation:\n\n- [Set up Azure Blob Storage containers][source_containers] with your documents\n- Optionally apply [glossaries][glossary] or a [custom model for translation][custom_model]\n- Allow access to your storage account with either of the following options:\n    - Generate [SAS tokens][sas_token] to your containers (or files) with the appropriate [permissions][sas_token_permissions]\n    - Create and use a [managed identity][managed_identity] to grant access to your storage account\n\n### DocumentTranslationClient\n\nInteraction with the Document Translation client library begins with an instance of the `DocumentTranslationClient`.\nThe client provides operations for:\n\n - Creating a translation operation to translate documents in your source container(s) and write results to you target container(s).\n - Checking the status of individual documents in the translation operation and monitoring each document's progress.\n - Enumerating all past and current translation operations.\n - Identifying supported glossary and document formats.\n\n### Translation Input\n\nInput to the `begin_translation` client method can be provided in two different ways:\n\n1) A single source container with documents can be translated to a different language:\n\n```python\nfrom azure.core.credentials import AzureKeyCredential\nfrom azure.ai.translation.document import DocumentTranslationClient\n\ndocument_translation_client = DocumentTranslationClient(\"<endpoint>\", AzureKeyCredential(\"<api_key>\"))\npoller = document_translation_client.begin_translation(\"<sas_url_to_source>\", \"<sas_url_to_target>\", \"<target_language>\")\n```\n\n2) Or multiple different sources can be provided each with their own targets.\n\n<!-- SNIPPET:sample_translate_multiple_inputs.multiple_translation -->\n\n```python\nimport os\nfrom azure.core.credentials import AzureKeyCredential\nfrom azure.ai.translation.document import DocumentTranslationClient, DocumentTranslationInput, TranslationTarget\n\nendpoint = os.environ[\"AZURE_DOCUMENT_TRANSLATION_ENDPOINT\"]\nkey = os.environ[\"AZURE_DOCUMENT_TRANSLATION_KEY\"]\nsource_container_url_1 = os.environ[\"AZURE_SOURCE_CONTAINER_URL_1\"]\nsource_container_url_2 = os.environ[\"AZURE_SOURCE_CONTAINER_URL_2\"]\ntarget_container_url_fr = os.environ[\"AZURE_TARGET_CONTAINER_URL_FR\"]\ntarget_container_url_ar = os.environ[\"AZURE_TARGET_CONTAINER_URL_AR\"]\ntarget_container_url_es = os.environ[\"AZURE_TARGET_CONTAINER_URL_ES\"]\n\nclient = DocumentTranslationClient(endpoint, AzureKeyCredential(key))\n\npoller = client.begin_translation(\n    inputs=[\n        DocumentTranslationInput(\n            source_url=source_container_url_1,\n            targets=[\n                TranslationTarget(target_url=target_container_url_fr, language=\"fr\"),\n                TranslationTarget(target_url=target_container_url_ar, language=\"ar\"),\n            ],\n        ),\n        DocumentTranslationInput(\n            source_url=source_container_url_2,\n            targets=[TranslationTarget(target_url=target_container_url_es, language=\"es\")],\n        ),\n    ]\n)\nresult = poller.result()\n\nprint(f\"Status: {poller.status()}\")\nprint(f\"Created on: {poller.details.created_on}\")\nprint(f\"Last updated on: {poller.details.last_updated_on}\")\nprint(f\"Total number of translations on documents: {poller.details.documents_total_count}\")\n\nprint(\"\\nOf total documents...\")\nprint(f\"{poller.details.documents_failed_count} failed\")\nprint(f\"{poller.details.documents_succeeded_count} succeeded\")\n\nfor document in result:\n    print(f\"Document ID: {document.id}\")\n    print(f\"Document status: {document.status}\")\n    if document.status == \"Succeeded\":\n        print(f\"Source document location: {document.source_document_url}\")\n        print(f\"Translated document location: {document.translated_document_url}\")\n        print(f\"Translated to language: {document.translated_to}\\n\")\n    elif document.error:\n        print(f\"Error Code: {document.error.code}, Message: {document.error.message}\\n\")\n```\n\n<!-- END SNIPPET -->\n\n> Note: the target_url for each target language must be unique.\n\nTo translate documents under a folder, or only translate certain documents, see [sample_begin_translation_with_filters.py][sample_begin_translation_with_filters].\nSee the service documentation for all [supported languages][supported_languages].\n\n### Long-Running Operations\n\nLong-running operations are operations which consist of an initial request sent to the service to start an operation,\nfollowed by polling the service at intervals to determine whether the operation has completed or failed, and if it has\nsucceeded, to get the result.\n\nMethods that translate documents are modeled as long-running operations.\nThe client exposes a `begin_<method-name>` method that returns a `DocumentTranslationLROPoller` or `AsyncDocumentTranslationLROPoller`. Callers should wait\nfor the operation to complete by calling `result()` on the poller object returned from the `begin_<method-name>` method.\nSample code snippets are provided to illustrate using long-running operations [below](#examples \"Examples\").\n\n## Examples\n\nThe following section provides several code snippets covering some of the most common Document Translation tasks, including:\n\n* [Translate your documents](#translate-your-documents \"Translate Your Documents\")\n* [Translate multiple inputs](#translate-multiple-inputs \"Translate Multiple Inputs\")\n* [List translation operations](#list-translation-operations \"List Translation Operations\")\n\n### Translate your documents\n\nTranslate all the documents in your source container to the target container. To translate documents under a folder, or only translate certain documents, see [sample_begin_translation_with_filters.py][sample_begin_translation_with_filters].\n\n```python\nfrom azure.core.credentials import AzureKeyCredential\nfrom azure.ai.translation.document import DocumentTranslationClient\n\nendpoint = \"https://<resource-name>.cognitiveservices.azure.com/\"\ncredential = AzureKeyCredential(\"<api_key>\")\nsource_container_sas_url_en = \"<sas-url-en>\"\ntarget_container_sas_url_es = \"<sas-url-es>\"\n\ndocument_translation_client = DocumentTranslationClient(endpoint, credential)\n\npoller = document_translation_client.begin_translation(source_container_sas_url_en, target_container_sas_url_es, \"es\")\n\nresult = poller.result()\n\nprint(f\"Status: {poller.status()}\")\nprint(f\"Created on: {poller.details.created_on}\")\nprint(f\"Last updated on: {poller.details.last_updated_on}\")\nprint(f\"Total number of translations on documents: {poller.details.documents_total_count}\")\n\nprint(\"\\nOf total documents...\")\nprint(f\"{poller.details.documents_failed_count} failed\")\nprint(f\"{poller.details.documents_succeeded_count} succeeded\")\n\nfor document in result:\n    print(f\"Document ID: {document.id}\")\n    print(f\"Document status: {document.status}\")\n    if document.status == \"Succeeded\":\n        print(f\"Source document location: {document.source_document_url}\")\n        print(f\"Translated document location: {document.translated_document_url}\")\n        print(f\"Translated to language: {document.translated_to}\\n\")\n    else:\n        print(f\"Error Code: {document.error.code}, Message: {document.error.message}\\n\")\n```\n\n### Translate multiple inputs\n\nBegin translating with documents in multiple source containers to multiple target containers in different languages.\n\n<!-- SNIPPET:sample_translate_multiple_inputs.multiple_translation -->\n\n```python\nimport os\nfrom azure.core.credentials import AzureKeyCredential\nfrom azure.ai.translation.document import DocumentTranslationClient, DocumentTranslationInput, TranslationTarget\n\nendpoint = os.environ[\"AZURE_DOCUMENT_TRANSLATION_ENDPOINT\"]\nkey = os.environ[\"AZURE_DOCUMENT_TRANSLATION_KEY\"]\nsource_container_url_1 = os.environ[\"AZURE_SOURCE_CONTAINER_URL_1\"]\nsource_container_url_2 = os.environ[\"AZURE_SOURCE_CONTAINER_URL_2\"]\ntarget_container_url_fr = os.environ[\"AZURE_TARGET_CONTAINER_URL_FR\"]\ntarget_container_url_ar = os.environ[\"AZURE_TARGET_CONTAINER_URL_AR\"]\ntarget_container_url_es = os.environ[\"AZURE_TARGET_CONTAINER_URL_ES\"]\n\nclient = DocumentTranslationClient(endpoint, AzureKeyCredential(key))\n\npoller = client.begin_translation(\n    inputs=[\n        DocumentTranslationInput(\n            source_url=source_container_url_1,\n            targets=[\n                TranslationTarget(target_url=target_container_url_fr, language=\"fr\"),\n                TranslationTarget(target_url=target_container_url_ar, language=\"ar\"),\n            ],\n        ),\n        DocumentTranslationInput(\n            source_url=source_container_url_2,\n            targets=[TranslationTarget(target_url=target_container_url_es, language=\"es\")],\n        ),\n    ]\n)\nresult = poller.result()\n\nprint(f\"Status: {poller.status()}\")\nprint(f\"Created on: {poller.details.created_on}\")\nprint(f\"Last updated on: {poller.details.last_updated_on}\")\nprint(f\"Total number of translations on documents: {poller.details.documents_total_count}\")\n\nprint(\"\\nOf total documents...\")\nprint(f\"{poller.details.documents_failed_count} failed\")\nprint(f\"{poller.details.documents_succeeded_count} succeeded\")\n\nfor document in result:\n    print(f\"Document ID: {document.id}\")\n    print(f\"Document status: {document.status}\")\n    if document.status == \"Succeeded\":\n        print(f\"Source document location: {document.source_document_url}\")\n        print(f\"Translated document location: {document.translated_document_url}\")\n        print(f\"Translated to language: {document.translated_to}\\n\")\n    elif document.error:\n        print(f\"Error Code: {document.error.code}, Message: {document.error.message}\\n\")\n```\n\n<!-- END SNIPPET -->\n\n### List translation operations\n\nEnumerate over the translation operations submitted for the resource.\n\n<!-- SNIPPET:sample_list_translations.list_translations -->\n\n```python\nfrom azure.core.credentials import AzureKeyCredential\nfrom azure.ai.translation.document import DocumentTranslationClient\n\nendpoint = os.environ[\"AZURE_DOCUMENT_TRANSLATION_ENDPOINT\"]\nkey = os.environ[\"AZURE_DOCUMENT_TRANSLATION_KEY\"]\n\nclient = DocumentTranslationClient(endpoint, AzureKeyCredential(key))\noperations = client.list_translation_statuses()\n\nfor operation in operations:\n    print(f\"ID: {operation.id}\")\n    print(f\"Status: {operation.status}\")\n    print(f\"Created on: {operation.created_on}\")\n    print(f\"Last updated on: {operation.last_updated_on}\")\n    print(f\"Total number of operations on documents: {operation.documents_total_count}\")\n    print(f\"Total number of characters charged: {operation.total_characters_charged}\")\n\n    print(\"\\nOf total documents...\")\n    print(f\"{operation.documents_failed_count} failed\")\n    print(f\"{operation.documents_succeeded_count} succeeded\")\n    print(f\"{operation.documents_canceled_count} canceled\\n\")\n```\n\n<!-- END SNIPPET -->\n\nTo see how to use the Document Translation client library with Azure Storage Blob to upload documents, create SAS tokens\nfor your containers, and download the finished translated documents, see this [sample][sample_translation_with_azure_blob].\nNote that you will need to install the [azure-storage-blob][azure_storage_blob] library to run this sample.\n\n## Advanced Topics\n\nThe following section provides some insights for some advanced translation features such as glossaries and custom translation models.\n\n### **Glossaries**\n\nGlossaries are domain-specific dictionaries. For example, if you want to translate some medical-related documents, you may need support for the many words, terminology, and idioms in the medical field which you can't find in the standard translation dictionary, or you simply need specific translation. This is why Document Translation provides support for glossaries.\n\n#### **How To Create Glossary File**\n\nDocument Translation supports glossaries in the following formats:\n\n|**File Type**|**Extension**|**Description**|**Samples**|\n|---------------|---------------|---------------|---------------|\n|Tab-Separated Values/TAB|.tsv, .tab|Read more on [wikipedia][tsv_files_wikipedia]|[glossary_sample.tsv][sample_tsv_file]|\n|Comma-Separated Values|.csv|Read more on [wikipedia][csv_files_wikipedia]|[glossary_sample.csv][sample_csv_file]|\n|Localization Interchange File Format|.xlf, .xliff|Read more on [wikipedia][xlf_files_wikipedia]|[glossary_sample.xlf][sample_xlf_file]|\n\nView all supported formats [here][supported_glossary_formats].\n\n#### **How Use Glossaries in Document Translation**\n\nIn order to use glossaries with Document Translation, you first need to upload your glossary file to a blob container, and then provide the SAS URL to the file as in the code samples [sample_translation_with_glossaries.py][sample_translation_with_glossaries].\n\n### **Custom Translation Models**\n\nInstead of using Document Translation's engine for translation, you can use your own custom Azure machine/deep learning model.\n\n#### **How To Create a Custom Translation Model**\n\nFor more info on how to create, provision, and deploy your own custom Azure translation model, please follow the instructions here: [Build, deploy, and use a custom model for translation][custom_translation_article]\n\n#### **How To Use a Custom Translation Model With Document Translation**\n\nIn order to use a custom translation model with Document Translation, you first \nneed to create and deploy your model, then follow the code sample [sample_translation_with_custom_model.py][sample_translation_with_custom_model] to use with Document Translation.\n\n## Troubleshooting\n\n### General\n\nDocument Translation client library will raise exceptions defined in [Azure Core][azure_core_exceptions].\n\n### Logging\n\nThis library uses the standard\n[logging][python_logging] library for logging.\n\nBasic information about HTTP sessions (URLs, headers, etc.) is logged at `INFO` level.\n\nDetailed `DEBUG` level logging, including request/response bodies and **unredacted**\nheaders, can be enabled on the client or per-operation with the `logging_enable` keyword argument.\n\nSee full SDK logging documentation with examples [here][sdk_logging_docs].\n\n### Optional Configuration\n\nOptional keyword arguments can be passed in at the client and per-operation level.\nThe azure-core [reference documentation][azure_core_ref_docs]\ndescribes available configurations for retries, logging, transport protocols, and more.\n\n## Next steps\n\nThe following section provides several code snippets illustrating common patterns used in the Document Translation Python client library.\nMore samples can be found under the [samples][samples] directory.\n\n### More sample code\n\nThese code samples show common scenario operations with the Azure Document Translation client library.\n\n* Client authentication: [sample_authentication.py][sample_authentication]\n* Begin translating documents: [sample_begin_translation.py][sample_begin_translation]\n* Translate with multiple inputs: [sample_translate_multiple_inputs.py][sample_translate_multiple_inputs]\n* Check the status of documents: [sample_check_document_statuses.py][sample_check_document_statuses]\n* List all submitted translation operations: [sample_list_translations.py][sample_list_translations]\n* Apply a custom glossary to translation: [sample_translation_with_glossaries.py][sample_translation_with_glossaries]\n* Use Azure Blob Storage to set up translation resources: [sample_translation_with_azure_blob.py][sample_translation_with_azure_blob]\n\n### Async samples\n\nThis library also includes a complete set of async APIs. To use them, you must\nfirst install an async transport, such as [aiohttp](https://pypi.org/project/aiohttp/). Async clients\nare found under the `azure.ai.translation.document.aio` namespace.\n\n* Client authentication: [sample_authentication_async.py][sample_authentication_async]\n* Begin translating documents: [sample_begin_translation_async.py][sample_begin_translation_async]\n* Translate with multiple inputs: [sample_translate_multiple_inputs_async.py][sample_translate_multiple_inputs_async]\n* Check the status of documents: [sample_check_document_statuses_async.py][sample_check_document_statuses_async]\n* List all submitted translation operations: [sample_list_translations_async.py][sample_list_translations_async]\n* Apply a custom glossary to translation: [sample_translation_with_glossaries_async.py][sample_translation_with_glossaries_async]\n* Use Azure Blob Storage to set up translation resources: [sample_translation_with_azure_blob_async.py][sample_translation_with_azure_blob_async]\n\n### Additional documentation\n\nFor more extensive documentation on Azure Cognitive Services Document Translation, see the [Document Translation documentation][python-dt-product-docs] on docs.microsoft.com.\n\n## Contributing\n\nThis project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com][cla].\n\nWhen you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.\n\nThis project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any additional questions or comments.\n\n<!-- LINKS -->\n\n[python-dt-src]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/azure/ai/translation/document\n[python-dt-pypi]: https://aka.ms/azsdk/python/texttranslation/pypi\n[python-dt-product-docs]: https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview\n[python-dt-ref-docs]: https://aka.ms/azsdk/python/documenttranslation/docs\n[python-dt-samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples\n\n[azure_subscription]: https://azure.microsoft.com/free/\n[DT_resource]: https://learn.microsoft.com/azure/ai-services/translator/document-translation/overview\n[single_service]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account?tabs=singleservice%2Cwindows\n[pip]: https://pypi.org/project/pip/\n[azure_portal_create_DT_resource]: https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesTextTranslation\n[azure_cli_create_DT_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account-cli?tabs=windows\n[azure-key-credential]: https://aka.ms/azsdk/python/core/azurekeycredential\n[supported_languages]: https://docs.microsoft.com/azure/cognitive-services/translator/language-support#translate\n[source_containers]: https://aka.ms/azsdk/documenttranslation/sas-permissions\n[custom_model]: https://docs.microsoft.com/azure/cognitive-services/translator/custom-translator/quickstart-build-deploy-custom-model\n[glossary]: https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview#supported-glossary-formats\n[sas_token]: https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/create-sas-tokens?tabs=Containers#create-your-sas-tokens-with-azure-storage-explorer\n[sas_token_permissions]: https://aka.ms/azsdk/documenttranslation/sas-permissions\n[azure_storage_blob]: https://pypi.org/project/azure-storage-blob/\n\n[azure_core_ref_docs]: https://aka.ms/azsdk/python/core/docs\n[azure_core_exceptions]: https://aka.ms/azsdk/python/core/docs#module-azure.core.exceptions\n[python_logging]: https://docs.python.org/3/library/logging.html\n[azure_cli_endpoint_lookup]: https://docs.microsoft.com/cli/azure/cognitiveservices/account?view=azure-cli-latest#az-cognitiveservices-account-show\n[azure_portal_get_endpoint]: https://learn.microsoft.com/azure/ai-services/translator/document-translation/quickstarts/document-translation-sdk?tabs=dotnet&pivots=programming-language-python\n[cognitive_authentication_api_key]: https://learn.microsoft.com/azure/ai-services/translator/document-translation/quickstarts/document-translation-sdk?tabs=dotnet&pivots=programming-language-python\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-azure-active-directory\n[custom_subdomain]: https://docs.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain\n[azure_identity]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity\n[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential\n[managed_identity]: https://aka.ms/azsdk/documenttranslation/managed-identity\n[sdk_logging_docs]: https://docs.microsoft.com/azure/developer/python/sdk/azure-sdk-logging\n\n[samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples\n[sample_authentication]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_authentication.py\n[sample_authentication_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_authentication_async.py\n[sample_begin_translation]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_begin_translation.py\n[sample_begin_translation_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_begin_translation_async.py\n[sample_translate_multiple_inputs]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_translate_multiple_inputs.py\n[sample_translate_multiple_inputs_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translate_multiple_inputs_async.py\n[sample_check_document_statuses]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_check_document_statuses.py\n[sample_check_document_statuses_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_check_document_statuses_async.py\n[sample_list_translations]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_list_translations.py\n[sample_list_translations_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_list_translations_async.py\n[sample_translation_with_glossaries]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_translation_with_glossaries.py\n[sample_translation_with_glossaries_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translation_with_glossaries_async.py\n[sample_translation_with_azure_blob]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_translation_with_azure_blob.py\n[sample_translation_with_azure_blob_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translation_with_azure_blob_async.py\n[sample_translation_with_custom_model]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_translation_with_custom_model.py\n[sample_translation_with_custom_model_async]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/async_samples/sample_translation_with_custom_model_async.py\n[sample_begin_translation_with_filters]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/sample_begin_translation_with_filters.py\n\n[supported_glossary_formats]: https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/overview#supported-glossary-formats\n[custom_translation_article]: https://docs.microsoft.com/azure/cognitive-services/translator/custom-translator/quickstart-build-deploy-custom-model\n[tsv_files_wikipedia]: https://wikipedia.org/wiki/Tab-separated_values\n[xlf_files_wikipedia]: https://wikipedia.org/wiki/XLIFF\n[csv_files_wikipedia]: https://wikipedia.org/wiki/Comma-separated_values\n[sample_tsv_file]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/assets/glossary_sample.tsv\n[sample_csv_file]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/assets/glossary_sample.csv\n[sample_xlf_file]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-document/samples/assets/glossary_sample.xlf\n\n[cla]: https://cla.microsoft.com\n[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/\n[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/\n[coc_contact]: mailto:opencode@microsoft.com\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Microsoft Azure Ai Translation Document Client Library for Python",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk"
    },
    "split_keywords": [
        "azure",
        " azure sdk"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "47690a2f44d4c41157bf4b690148cdb83f8bc9c9c94494d0f80dd462aefa3061",
                "md5": "a2e3feef7aca5115a7421e72d409a44e",
                "sha256": "5ef71b0b78f36d13e13bdd40f0b6d1225d727a8abb6f5cfed4d53cac491d6273"
            },
            "downloads": -1,
            "filename": "azure_ai_translation_document-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a2e3feef7aca5115a7421e72d409a44e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 94790,
            "upload_time": "2024-11-12T18:39:50",
            "upload_time_iso_8601": "2024-11-12T18:39:50.625646Z",
            "url": "https://files.pythonhosted.org/packages/47/69/0a2f44d4c41157bf4b690148cdb83f8bc9c9c94494d0f80dd462aefa3061/azure_ai_translation_document-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "279b416929c4d6d7e8e37bfeb7293c7ca326e652a8610f1308007caa831df40e",
                "md5": "182bc10075fe8d6620ae2e199ccc1afa",
                "sha256": "3e1d8ac697ff969e9b3474b8daec6af48742a95ec2f5198f6e76071233c3ee10"
            },
            "downloads": -1,
            "filename": "azure_ai_translation_document-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "182bc10075fe8d6620ae2e199ccc1afa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 120559,
            "upload_time": "2024-11-12T18:39:48",
            "upload_time_iso_8601": "2024-11-12T18:39:48.533699Z",
            "url": "https://files.pythonhosted.org/packages/27/9b/416929c4d6d7e8e37bfeb7293c7ca326e652a8610f1308007caa831df40e/azure_ai_translation_document-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-12 18:39:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Azure",
    "github_project": "azure-sdk-for-python",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "azure-ai-translation-document"
}
        
Elapsed time: 0.41252s