TextAnalysisClient Class

The language service API is a suite of natural language processing (NLP) skills built with best-in-class Microsoft machine learning algorithms. The API can be used to analyze unstructured text for tasks such as sentiment analysis, key phrase extraction, language detection and question answering. Further documentation can be found at https://learn.microsoft.com/azure/cognitive-services/language-service/overview.

Constructor

TextAnalysisClient(endpoint: str, credential: AzureKeyCredential | TokenCredential, **kwargs: Any)

Parameters

Name Description
endpoint
Required
str

Supported Cognitive Services endpoint (e.g., https://<resource-name>.api.cognitiveservices.azure.com). Required.

credential
Required

Credential used to authenticate requests to the service. Is either a key credential type or a token credential type. Required.

Keyword-Only Parameters

Name Description
api_version
str

The API version to use for this operation. Known values are "2026-05-15-preview" and None. Default value is None. If not set, the operation's default API version will be used. Note that overriding this default value may result in unsupported behavior.

polling_interval
int

Default waiting time between two polls for LRO operations if no Retry-After header is present.

Methods

analyze_text

Request text analysis over a collection of documents.

begin_analyze_text_job

Submit a collection of text documents for analysis. Specify one or more unique tasks to be executed as a long-running operation.

begin_cancel_job

Cancel a long-running Text Analysis job.

Cancel a long-running Text Analysis job.

close
get_job_status

Get analysis status and results.

Get the status of an analysis job. A job can consist of one or more tasks. After all tasks succeed, the job transitions to the succeeded state and results are available for each task.

send_request

Runs the network request through the client's chained policies.


>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

analyze_text

Request text analysis over a collection of documents.

analyze_text(body: AnalyzeTextInput | TextEntityLinkingInput | TextEntityRecognitionInput | TextKeyPhraseExtractionInput | TextLanguageDetectionInput | TextPiiEntitiesRecognitionInput | TextSentimentAnalysisInput | IO[bytes], *, show_stats: bool | None = None, **kwargs: Any) -> AnalyzeTextResult

Parameters

Name Description
body
Required
AnalyzeTextInput or <xref:azure.ai.textanalytics.types.AnalyzeTextInput> or IO[bytes]

The input documents to analyze. Is either a AnalyzeTextInput type or a IO[bytes] type. Required.

Keyword-Only Parameters

Name Description
show_stats

(Optional) if set to true, response will contain request and document level statistics. Default value is None.

Default value: None

Returns

Type Description

AnalyzeTextResult. The AnalyzeTextResult is compatible with MutableMapping

Exceptions

Type Description

begin_analyze_text_job

Submit a collection of text documents for analysis. Specify one or more unique tasks to be executed as a long-running operation.

begin_analyze_text_job(body: ~collections.abc.MutableMapping[str, ~typing.Any] | ~azure.ai.textanalytics.types.AnalyzeTextSubmitJobRequest | ~typing.IO[bytes] = <object object>, *, text_input: ~azure.ai.textanalytics.models._models.MultiLanguageTextInput = <object object>, actions: list[azure.ai.textanalytics.models._models.AnalyzeTextOperationAction] = <object object>, display_name: str | None = None, default_language: str | None = None, cancel_after: float | None = None, **kwargs: ~typing.Any) -> LROPoller[AnalyzeTextOperationState]

Parameters

Name Description
body
<xref:JSON> or AnalyzeTextSubmitJobRequest or IO[bytes]

Is one of the following types: JSON, AnalyzeTextSubmitJobRequest, IO[bytes] Required.

Keyword-Only Parameters

Name Description
text_input

Contains the input to be analyzed. Required.

Default value: <object object at 0x000001B22DC5C110>
actions

List of tasks to be performed as part of the LRO. Required.

Default value: <object object at 0x000001B22DC5C110>
display_name
str

Name for the task. Default value is None.

Default value: None
default_language
str

Default language to use for records requesting automatic language detection. Default value is None.

Default value: None
cancel_after

Optional duration in seconds after which the job will be canceled if not completed. Default value is None.

Default value: None

Returns

Type Description

An instance of LROPoller that returns AnalyzeTextOperationState

Exceptions

Type Description

begin_cancel_job

Cancel a long-running Text Analysis job.

Cancel a long-running Text Analysis job.

begin_cancel_job(job_id: str, **kwargs: Any) -> LROPoller[None]

Parameters

Name Description
job_id
Required
str

The job ID to cancel. Required.

Returns

Type Description

An instance of LROPoller that returns None

Exceptions

Type Description

close

close() -> None

get_job_status

Get analysis status and results.

Get the status of an analysis job. A job can consist of one or more tasks. After all tasks succeed, the job transitions to the succeeded state and results are available for each task.

get_job_status(job_id: str, *, show_stats: bool | None = None, top: int | None = None, skip: int | None = None, **kwargs: Any) -> AnalyzeTextOperationState

Parameters

Name Description
job_id
Required
str

job ID. Required.

Keyword-Only Parameters

Name Description
show_stats

(Optional) if set to true, response will contain request and document level statistics. Default value is None.

Default value: None
top
int

The maximum number of resources to return from the collection. Default value is None.

Default value: None
skip
int

An offset into the collection of the first resource to be returned. Default value is None.

Default value: None

Returns

Type Description

AnalyzeTextOperationState. The AnalyzeTextOperationState is compatible with MutableMapping

Exceptions

Type Description

send_request

Runs the network request through the client's chained policies.


>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

send_request(request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse

Parameters

Name Description
request
Required

The network request you want to make. Required.

Keyword-Only Parameters

Name Description
stream

Whether the response payload will be streamed. Defaults to False.

Default value: False

Returns

Type Description

The response of your network call. Does not do error handling on your response.