Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Samples for Azure Document Intelligence client library for Python(Layout model)

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

All of these samples need the endpoint to your Document Intelligence resource (instructions on how to get endpoint), and your Document Intelligence API key (instructions on how to get key).

Prerequisites

Set your environment variables

At a command prompt, run the following commands, replacing <yourKey> and <yourEndpoint> with the values from your resource in the Azure portal.

  • For Windows:
    setx DI_KEY <yourKey>
    setx DI_ENDPOINT <yourEndpoint>
    You need to restart any running programs that read the environment variable.
  • For macOS:
    export key=<yourKey>
    export endpoint=<yourEndpoint>
    • This is a temporary environment variable setting method that only lasts until you close the terminal session.
    • To set an environment variable permanently, visit: https://aka.ms/V3.1-set-environment-variables-for-macOS
  • For Linux:
    export DI_KEY=<yourKey>
    export DI_ENDPOINT=<yourEndpoint>
    • This is a temporary environment variable setting method that only lasts until you close the terminal session.
    • To set an environment variable permanently, visit: https://aka.ms/V3.1-set-environment-variables-for-Linux

Setup

  1. Install the Azure Document Intelligence client library for Python with pip:
pip install azure-ai-formrecognizer==3.3.0
  1. Clone or download this sample repository
  2. Open the sample folder in Visual Studio Code or your IDE of choice.

Create your Python application

  1. Create a new Python file called "sample_analyze_layout.py" in an editor or IDE.
  2. Open the "sample_analyze_layout.py" file and insert the provided code sample into your application.
  3. At a command prompt, use the following code to run the Python code: python sample_analyze_layout.py

Run the samples

  1. Open a terminal window and cd to the directory that the samples are saved in.
  2. Set the environment variables specified in the sample file you wish to run.
  3. Follow the usage described in the file, e.g. python sample_analyze_layout.py
File Name Usage scenarios
sample_analyze_layout.py Extract text, selection marks, and table structures in a document

Next steps

Check out the API reference documentation to learn more about what you can do with the Azure Document Intelligence client library.