Registry / azure / azure-ai-textanalytics

azure-ai-textanalytics

JSON →
library5.4.0pypypi✓ verified 22d ago

The Azure AI Text Analytics client library for Python provides a robust interface for interacting with the Azure Cognitive Service for Language. This cloud-based service offers a suite of Natural Language Processing (NLP) features, including sentiment analysis, named entity recognition, language detection, key phrase extraction, and more. Currently at version 5.4.0, the library is actively maintained as part of the Azure SDK for Python, with frequent minor and patch releases to support the evolving Azure Language service APIs.

pip install azure-ai-textanalytics
INSTALL
IMPORT
SIG · AZURE-AI-TEXTANALY
A
azure-ai-textanalytics
azurepythonv5.4.0
Install
2.5s avg
Import
527ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.558s · 27.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.496s · 28MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TextAnalyticsClient
from azure.ai.textanalytics import TextAnalyticsClient
AzureKeyCredential
from azure.core.credentials import AzureKeyCredential
LanguageDetectionAction
from azure.ai.textanalytics import LanguageDetectionAction
azure.cognitiveservices.language.textanalytics
from azure.cognitiveservices.language.textanalytics import TextAnalyticsClient
This is the old, deprecated package name. Migrate to azure-ai-textanalytics.

This quickstart demonstrates how to instantiate a `TextAnalyticsClient` using an API key and endpoint, and then perform sentiment analysis on a batch of documents. Ensure you replace placeholder credentials with your actual Azure Language service endpoint and API key, preferably via environment variables.

import os from azure.core.credentials import AzureKeyCredential from azure.ai.textanalytics import TextAnalyticsClient # Set environment variables for endpoint and key # AZURE_LANGUAGE_ENDPOINT='https://YOUR_RESOURCE_NAME.cognitiveservices.azure.com/' # AZURE_LANGUAGE_KEY='YOUR_API_KEY' endpoint = os.environ.get('AZURE_LANGUAGE_ENDPOINT', 'YOUR_LANGUAGE_ENDPOINT') key = os.environ.get('AZURE_LANGUAGE_KEY', 'YOUR_LANGUAGE_KEY') if endpoint == 'YOUR_LANGUAGE_ENDPOINT' or key == 'YOUR_LANGUAGE_KEY': print("Please set the 'AZURE_LANGUAGE_ENDPOINT' and 'AZURE_LANGUAGE_KEY' environment variables.") else: try: text_analytics_client = TextAnalyticsClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) documents = [ "I had a wonderful trip to Seattle last week.", "The coffee was terrible and the staff was rude.", "The city was beautiful, but the weather was rainy." ] response = text_analytics_client.analyze_sentiment(documents=documents) for doc in response: if not doc.is_error: print(f"Document Text: {documents[doc.id]}") print(f"Overall Sentiment: {doc.sentiment}") print("Sentence sentiments:") for sentence in doc.sentences: print(f" Sentence: {sentence.text}") print(f" Sentiment: {sentence.sentiment}") print(f" Positive score: {round(sentence.confidence_scores.positive, 2)}") print(f" Neutral score: {round(sentence.confidence_scores.neutral, 2)}") print(f" Negative score: {round(sentence.confidence_scores.negative, 2)}\n") else: print(f"Document ID: {doc.id}, Error: {doc.error}") except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
breakingThe legacy package `azure-cognitiveservices-language-textanalytics` is deprecated and no longer maintained. Users should migrate to `azure-ai-textanalytics`. This migration involves changes in package name, import paths, and potentially API calls due to the underlying Azure Language service's shift to date-based API versioning from version 5.2.x onwards.
fix
Uninstall the old package (`pip uninstall azure-cognitiveservices-language-textanalytics`), install the new one (`pip install azure-ai-textanalytics`), and update import statements and client initialization as per the official documentation.
affects: Prior to 5.0.0 (for users of the legacy package)
gotchaThe `TextAnalyticsClient` defaults to a specific stable API version of the Azure Language service (e.g., '2023-04-01' for library version 5.4.0). New features released in later service API versions (including preview versions) might not be available unless you explicitly specify the desired `api_version` during client instantiation.
fix
Pass the `api_version` keyword argument to the `TextAnalyticsClient` constructor (e.g., `TextAnalyticsClient(endpoint, credential, api_version="2024-07-01-preview")`) to access newer features or target a specific service API version.
affects: All 5.x.x versions
gotchaAzure Active Directory (AAD) authentication (using credentials from `azure-identity`) is not supported with regional endpoints (e.g., `https://westus2.api.cognitive.microsoft.com/`). To use AAD authentication, your Azure AI Language resource must have a custom subdomain configured.
fix
Configure a custom subdomain for your Azure AI Language resource in the Azure Portal and use that custom endpoint when initializing the `TextAnalyticsClient` with AAD credentials.
affects: All 5.x.x versions
gotchaFor executing multiple different text analysis actions (e.g., sentiment analysis, entity recognition, key phrase extraction) in a single request on a batch of documents, the `begin_analyze_actions` method should be used. Direct client methods like `analyze_sentiment` are designed for performing a single type of analysis on a collection of documents.
fix
Utilize `client.begin_analyze_actions()` with a list of action models (e.g., `[RecognizeEntitiesAction(), AnalyzeSentimentAction()]`) for batch processing of diverse NLP tasks. This often leads to more efficient API usage.
affects: All 5.x.x versions
Errors
Common errors & fixes
ImportError: cannot import name 'PollingReturnType' from 'azure.core.polling._poller'
This error occurs due to a version mismatch between the 'azure-ai-textanalytics' and 'azure-core' packages, where the installed version of 'azure-core' lacks the 'PollingReturnType' class required by 'azure-ai-textanalytics'.
fix
Upgrade both packages to compatible versions by running: 'pip install --upgrade azure-ai-textanalytics azure-core'.
ModuleNotFoundError: No module named 'azure.ai.textanalytics'
This error indicates that the 'azure-ai-textanalytics' package is not installed in the Python environment.
fix
Install the package using: 'pip install azure-ai-textanalytics'.
AttributeError: module 'azure.ai.textanalytics' has no attribute 'TextAnalyticsClient'
This error occurs when the 'TextAnalyticsClient' class is not found in the 'azure.ai.textanalytics' module, possibly due to an incorrect import statement or an outdated package version.
fix
Ensure the correct import statement: 'from azure.ai.textanalytics import TextAnalyticsClient' and verify that the package is up-to-date by running: 'pip install --upgrade azure-ai-textanalytics'.
ModuleNotFoundError: No module named 'azure-ai-textanalytics'
The `azure-ai-textanalytics` package is not installed in your Python environment, or the Python interpreter being used does not have access to the installed package.
fix
Ensure the package is installed using `pip install azure-ai-textanalytics` and that your development environment is using the correct Python interpreter where the package is installed.
AttributeError: 'TextAnalyticsClient' object has no attribute 'begin_analyze_healthcare_entities'
This error typically occurs when attempting to use a feature (like healthcare analytics or summarization) that is not available in the installed version of the `azure-ai-textanalytics` library or the Azure Language service resource is not configured for that specific functionality.
fix
Update the `azure-ai-textanalytics` package to the latest version using `pip install --upgrade azure-ai-textanalytics` and verify your Azure Language service resource supports the desired feature and is in the correct region and pricing tier.
Upgrade
Version history
5.4.0latest on PyPI · released Mar 5, 2026
Audit
Dependencies
azure-corerequiredCore Azure SDK functionalities.
azure-identityoptionalRequired for Azure Active Directory (AAD) authentication.
Agent activity
51 hits · last 30 days
node
42
OpenAI (training)
1
Resources
azure-ai-textanalytics — pip install azure-ai-textanalytics · libregistry