{"id":5747,"library":"azure-ai-textanalytics","title":"Azure AI Text Analytics Client Library for Python","description":"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.","status":"active","version":"5.4.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python","tags":["Azure","AI","Text Analytics","NLP","Cognitive Services","Sentiment Analysis","Entity Recognition","Key Phrase Extraction","Language Detection","Summarization"],"install":[{"cmd":"pip install azure-ai-textanalytics","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core Azure SDK functionalities.","package":"azure-core"},{"reason":"Required for Azure Active Directory (AAD) authentication.","package":"azure-identity","optional":true}],"imports":[{"symbol":"TextAnalyticsClient","correct":"from azure.ai.textanalytics import TextAnalyticsClient"},{"symbol":"AzureKeyCredential","correct":"from azure.core.credentials import AzureKeyCredential"},{"symbol":"LanguageDetectionAction","correct":"from azure.ai.textanalytics import LanguageDetectionAction"},{"note":"This is the old, deprecated package name. Migrate to azure-ai-textanalytics.","wrong":"from azure.cognitiveservices.language.textanalytics import TextAnalyticsClient","symbol":"azure.cognitiveservices.language.textanalytics"}],"quickstart":{"code":"import os\nfrom azure.core.credentials import AzureKeyCredential\nfrom azure.ai.textanalytics import TextAnalyticsClient\n\n# Set environment variables for endpoint and key\n# AZURE_LANGUAGE_ENDPOINT='https://YOUR_RESOURCE_NAME.cognitiveservices.azure.com/'\n# AZURE_LANGUAGE_KEY='YOUR_API_KEY'\n\nendpoint = os.environ.get('AZURE_LANGUAGE_ENDPOINT', 'YOUR_LANGUAGE_ENDPOINT')\nkey = os.environ.get('AZURE_LANGUAGE_KEY', 'YOUR_LANGUAGE_KEY')\n\nif endpoint == 'YOUR_LANGUAGE_ENDPOINT' or key == 'YOUR_LANGUAGE_KEY':\n    print(\"Please set the 'AZURE_LANGUAGE_ENDPOINT' and 'AZURE_LANGUAGE_KEY' environment variables.\")\nelse:\n    try:\n        text_analytics_client = TextAnalyticsClient(\n            endpoint=endpoint, \n            credential=AzureKeyCredential(key)\n        )\n\n        documents = [\n            \"I had a wonderful trip to Seattle last week.\",\n            \"The coffee was terrible and the staff was rude.\",\n            \"The city was beautiful, but the weather was rainy.\"\n        ]\n\n        response = text_analytics_client.analyze_sentiment(documents=documents)\n\n        for doc in response:\n            if not doc.is_error:\n                print(f\"Document Text: {documents[doc.id]}\")\n                print(f\"Overall Sentiment: {doc.sentiment}\")\n                print(\"Sentence sentiments:\")\n                for sentence in doc.sentences:\n                    print(f\"  Sentence: {sentence.text}\")\n                    print(f\"  Sentiment: {sentence.sentiment}\")\n                    print(f\"  Positive score: {round(sentence.confidence_scores.positive, 2)}\")\n                    print(f\"  Neutral score: {round(sentence.confidence_scores.neutral, 2)}\")\n                    print(f\"  Negative score: {round(sentence.confidence_scores.negative, 2)}\\n\")\n            else:\n                print(f\"Document ID: {doc.id}, Error: {doc.error}\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":"Prior to 5.0.0 (for users of the legacy package)"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All 5.x.x versions"},{"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.","message":"Azure 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.","severity":"gotcha","affected_versions":"All 5.x.x versions"},{"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.","message":"For 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.","severity":"gotcha","affected_versions":"All 5.x.x versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}