🌐
Microsoft Learn
learn.microsoft.com › en-us › python › api › azure-ai-formrecognizer › azure.ai.formrecognizer.documentanalysisclient
azure.ai.formrecognizer.DocumentAnalysisClient class | Microsoft Learn
from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer import DocumentAnalysisClient endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] classifier_id = os.getenv("CLASSIFIER_ID", classifier_id) document_analysis_client = DocumentAnalysisClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/forms/IRS-1040.pdf" poller = document_analysis_client.begin_classify_document_from_ur
🌐
Microsoft Learn
learn.microsoft.com › en-us › python › api › overview › azure › ai-formrecognizer-readme
Azure Form Recognizer client library for Python | Microsoft Learn
DocumentAnalysisClient provides operations for analyzing input documents using prebuilt and custom models through the begin_analyze_document and begin_analyze_document_from_url APIs.
🌐
PyPI
pypi.org › project › azure-ai-formrecognizer
azure-ai-formrecognizer · PyPI
DocumentAnalysisClient provides operations for analyzing input documents using prebuilt and custom models through the begin_analyze_document and begin_analyze_document_from_url APIs.
🌐
Microsoft Learn
learn.microsoft.com › en-us › python › api › azure-ai-formrecognizer › azure.ai.formrecognizer.aio.documentanalysisclient
azure.ai.formrecognizer.aio.DocumentAnalysisClient class | Microsoft Learn
from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer.aio import DocumentAnalysisClient endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] document_analysis_client = DocumentAnalysisClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) async with document_analysis_client: url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/receipt/contoso-receipt.png" poller = await document_analysis_client.begin_analyze_document_from_url(
🌐
GitHub
github.com › Azure › azure-sdk-for-python › blob › main › sdk › formrecognizer › azure-ai-formrecognizer › README.md
azure-sdk-for-python/sdk/formrecognizer/azure-ai-formrecognizer/README.md at main · Azure/azure-sdk-for-python · GitHub
DocumentAnalysisClient provides operations for analyzing input documents using prebuilt and custom models through the begin_analyze_document and begin_analyze_document_from_url APIs.
🌐
Microsoft Learning
microsoftlearning.github.io › mslearn-ai-document-intelligence › Instructions › Exercises › 01-use-prebuilt-models.html
Use prebuilt Document Intelligence models | Azure AI Document Intelligence Exercises
Python · key = "<API Key>" Locate the comment Create the client. Following that, on new lines, enter the following code: C# var cred = new AzureKeyCredential(apiKey); var client = new DocumentAnalysisClient(new Uri(endpoint), cred); Python · document_analysis_client = DocumentAnalysisClient( endpoint=endpoint, credential=AzureKeyCredential(key) ) Locate the comment Analyze the invoice.
🌐
C# Corner
c-sharpcorner.com › article › extract-information-from-documents-using-azure-form-recognizer-on-python
Extract information from documents using Azure Form Recognizer on Python
July 6, 2023 - You can do this by running the following command in your Python environment: ... Next, import the required libraries and authenticate with your Azure account. from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer import DocumentAnalysisClient import numpy as np import pandas as pd ENDPOINT = "<YOUR_ENDPOINT>" APIKEY = "<YOUR_API_KEY>" document_analysis_client = DocumentAnalysisClient(ENDPOINT, credential=AzureKeyCredential(APIKEY))
🌐
Medium
learnmycourse.medium.com › document-intelligence-using-azure-document-intelligence-9147bf4d43d6
Document intelligence using Azure Document Intelligence | by LEARNMYCOURSE | Medium
December 30, 2024 - Below is an example Python script to achieve this: from azure.ai.formrecognizer import DocumentAnalysisClient from azure.core.credentials import AzureKeyCredential from PyPDF2 import PdfReader
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 78183014 › can-i-use-azure-documentanalysisclient-with-no-credentials
python - Can I use Azure DocumentAnalysisClient with no credentials? - Stack Overflow
from azure.ai.formrecognizer import DocumentAnalysisClient client = DcoumentAnalysisClient(endpoint=my_endpoint, credential=...) python · azure-form-recognizer · Share · Improve this question · Follow · asked Mar 18, 2024 at 21:06 · user3124181 · 9031111 silver badges2727 bronze badges 0 ·
🌐
Azure Docs
docs.azure.cn › en-us › ai-services › document-intelligence › versioning › sdk-overview-v3-0
Document Intelligence SDK target REST API 2022-08-31 (GA) - Azure AI services | Azure Docs
February 10, 2026 - Python · using Azure; using Azure.AI.FormRecognizer.DocumentAnalysis; import com.azure.ai.formrecognizer.*; import com.azure.ai.formrecognizer.models.*; import com.azure.ai.formrecognizer.DocumentAnalysisClient.*; import com.azure.core.credential.AzureKeyCredential; const { AzureKeyCredential, DocumentAnalysisClient } = require("@azure/ai-form-recognizer"); from azure.ai.formrecognizer import DocumentAnalysisClient from azure.core.credentials import AzureKeyCredential ·
🌐
Microsoft Learn
learn.microsoft.com › en-us › python › api › overview › azure › ai-documentintelligence-readme
Azure AI Document Intelligence client library for Python | Microsoft Learn
from azure.core.credentials import AzureKeyCredential from azure.ai.documentintelligence import DocumentIntelligenceClient from azure.ai.documentintelligence.models import AnalyzeDocumentRequest, AnalyzeResult endpoint = os.environ["DOCUMENTINTELLIGENCE_ENDPOINT"] key = os.environ["DOCUMENTINTELLIGENCE_API_KEY"] document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_forms/receipt/contoso-receipt.png" poller = document_intelligence_client.begin_analyze_document( "prebuilt-receipt", AnalyzeDocumentRequest(url_source=url) ) receipts: AnalyzeResult = poller.result()
Top answer
1 of 3
6

Leveraging Azure Document Intelligence Layout API with markdown output will provide all content in a single response by default. You can split the markdown content per page, by looking at the page information (span offset and length) provided in the response.

See below code example (Python) which can be used to split the markdown content:

# Split markdown content per page
content_per_page = []
page_number = 1

for page in result.pages: 
    content = result.content[page.spans[0]['offset']: page.spans[0]['offset'] + page.spans[0]['length']]
    content_per_page.append({"page_number": page_number, "content": content})
    page_number+=1
2 of 3
1

using Azure Document Intelligence to extract content from documents and would like to separate the content page by page:

  • Followed this Azure AI Document Intelligence client with python
for page in result.pages:
    # Create a string to hold the Markdown content for this page
    markdown_content = ""
    
    # Iterate through each element on the page
    for element in page.lines:
        # Append each line to the markdown_content string
        markdown_content += f"{element.content}\n"
    
    # Append the markdown content to the markdown_pages list
    markdown_pages.append(markdown_content)

The below Python code extract content from documents and separates the content page by page

from azure.ai.formrecognizer import DocumentAnalysisClient
from azure.core.credentials import AzureKeyCredential

# Set up the client
endpoint ="https://your-service-endpoint.cognitiveservices.azure.com/"
api_key = "your-api-key"
client = DocumentAnalysisClient(endpoint, AzureKeyCredential(api_key))

# Analyze the document
document_url = "https://sampath1233sa23344545.blob.core.windows.net/sampathpujari/sample-layout_merged%20(1).pdf?sp=r&st=2024-04-17T11:50:23Z&se=2024-04-17T19:50:23Z&sv=2022-11-02&sr=b&sig=r6USzR4zcaECjsNw9HAbJ%2BvzRwrk3InrBmaXklxbs5c%3D"

# Begin document analysis
analysis_poller = client.begin_analyze_document_from_url("prebuilt-document", document_url)
result = analysis_poller.result()  # Wait for the analysis to complete and get the result

# Initialize a list to hold the markdown content for each page
markdown_pages = []

# Iterate through each page
for page in result.pages:
    # Create a string to hold the Markdown content for this page
    markdown_content = ""
    
    # Iterate through each element on the page
    for element in page.lines:
        # Append each line to the markdown_content string
        markdown_content += f"{element.content}\n"
    
    # Append the markdown content to the markdown_pages list
    markdown_pages.append(markdown_content)

# The markdown_pages list now contains the content of each page in Markdown format
for i, content in enumerate(markdown_pages):
    print(f"Page {i + 1}:\n{content}\n")


Output:

  • Refer to this for Analyze complex documents with Azure Document Intelligence Markdown Output
🌐
PyPI
pypi.org › project › azure-ai-documentintelligence
azure-ai-documentintelligence · PyPI
Microsoft Azure AI Document Intelligence Client Library for Python
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › ai-services › document-intelligence › how-to-guides › use-sdk-rest-api
Use Document Intelligence client library or REST API - Foundry Tools | Microsoft Learn
To interact with the Document Intelligence service, you need to create an instance of the DocumentAnalysisClient class. To do so, instantiate the client with your key and endpoint from the Azure portal.
🌐
Cohorte
cohorte.co › blog › automating document analysis with azure ai document intelligence: a comprehensive step-by-step guide — coho…
Automating Document Analysis with Azure AI Document Intelligence: A Comprehensive Step-by-Step Guide — Cohorte Engineering Blog
Ensure you have Python installed. Install the Azure AI Document Intelligence client library: ... from azure.ai.formrecognizer import DocumentAnalysisClient from azure.core.credentials import AzureKeyCredential
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › ai-services › document-intelligence › versioning › sdk-overview-v4-0
Document Intelligence SDK target REST API v4.0 - Foundry Tools | Microsoft Learn
The Document Intelligence software development kit (SDK) is a set of libraries and tools that enable you to easily integrate Document Intelligence models and capabilities into your applications. Document Intelligence SDK is available across platforms in C#/.NET, Java, JavaScript, and Python programming languages.
🌐
Azure Docs
docs.azure.cn › en-us › ai-services › document-intelligence › versioning › sdk-overview-v4-0
Document Intelligence SDK target REST API v4.0 - Azure AI services | Azure Docs
The Document Intelligence software development kit (SDK) is a set of libraries and tools that enable you to easily integrate Document Intelligence models and capabilities into your applications. Document Intelligence SDK is available across platforms in C#/.NET, Java, JavaScript, and Python programming languages.
Top answer
1 of 3
1

It is possible to override the API version while initialising the DocumentIntelligenceClient to use a different version than the one that the Python client library was developed for.

However, please note that Microsoft warns that:

overriding this default value (for api_version) may result in unsupported behavior

The below code sample shows using the api_version to override the API version from 2024-02-29-preview to 2024-07-31-preview while using the 1.0.0b2 version of the azure-ai-documentintelligence client library.

# pip install azure-ai-documentintelligence==1.0.0b2
from azure.ai.documentintelligence import DocumentIntelligenceClient
document_intelligence_client = DocumentIntelligenceClient(
            endpoint = <<Your endpoint>>,
            credential = <<Your credential>>,
            api_version = "2024-07-31-preview"
        )

Also, note that Microsoft is yet to release an official client library that targets the 2024-07-31-preview version of the API. However, once they do release the official client library supporting the 2024-07-31-preview version of the API, we should update to that version of the client library and remove the api_version parameter while initialising the document intelligence client.

2 of 3
0

According to this doc the Document Intelligence 2024-02-29-preview REST API is now available. This preview API introduces new and updated capabilities:

  • Public preview version 2024-02-29-preview is currently available only in the following Azure regions:

    • East US
    • West US2
    • West Europe

Install the library using pip

pip install azure-ai-documentintelligence==1.0.0b2
pip install azure-ai-formrecognizer
  • Get started with Azure AI Document Intelligence latest preview version (2024-02-29-preview) reference doc

from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient
from azure.core.exceptions import HttpResponseError

# Replace these values with your actual endpoint and key
endpoint = "<your-endpoint>"
key = "<your-key>"

# Sample document URL
formUrl = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-layout.pdf"

try:
    # Create Document Analysis client
    document_analysis_client = DocumentAnalysisClient(
        endpoint=endpoint, credential=AzureKeyCredential(key)
    )

    # Analyze the document layout
    poller = document_analysis_client.begin_analyze_document_from_url('prebuilt-layout', formUrl, locale='de')
    results = poller.result()

    # Process the analysis results
    print("Document analysis results:")
    print(results)

except HttpResponseError as e:
    print("HTTP Response Error:", e.response.status_code, e.message)

except Exception as ex:
    print("An unexpected error occurred:", ex)

Output: