Skip to content

Latest commit

 

History

History
82 lines (59 loc) · 5 KB

File metadata and controls

82 lines (59 loc) · 5 KB

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).

You can check all samples from here.

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 DOCUMENTINTELLIGENCE_API_KEY <yourKey>
    setx DOCUMENTINTELLIGENCE_ENDPOINT <yourEndpoint>
    You need to restart any running programs that read the environment variable.
  • For macOS:
    export DOCUMENTINTELLIGENCE_API_KEY=<yourKey>
    export DOCUMENTINTELLIGENCE_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/set-environment-variables-for-macOS
  • For Linux:
    export DOCUMENTINTELLIGENCE_API_KEY=<yourKey>
    export DOCUMENTINTELLIGENCE_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/set-environment-variables-for-Linux

Setup

  1. Install the Azure Document Intelligence client library for Python with pip:
pip install azure-ai-documentintelligence
  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.