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).
- Azure subscription - Create one for free.
- Python 3.7 or later. Your Python installation should include pip. You can check if you have pip installed by running
pip --version
on the command line. Get pip by installing the latest version of Python. - Install the latest version of Visual Studio Code or your preferred IDE. * For more information, see Getting Started with Python in Visual Studio Code.
- An Azure AI services or Document Intelligence resource. * Once you have your Azure subscription,Create a single-service or multi-service resource. You can use the free pricing tier (F0) to try the service and upgrade to a paid tier for production later.
- Get endpoint and keys to your Document Intelligence resource.
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
- Install the Azure Document Intelligence client library for Python with pip:
pip install azure-ai-formrecognizer==3.3.0
- Clone or download this sample repository
- Open the sample folder in Visual Studio Code or your IDE of choice.
- Create a new Python file called "sample_analyze_layout.py" in an editor or IDE.
- Open the "sample_analyze_layout.py" file and insert the provided code sample into your application.
- At a command prompt, use the following code to run the Python code: python sample_analyze_layout.py
- Open a terminal window and
cd
to the directory that the samples are saved in. - Set the environment variables specified in the sample file you wish to run.
- 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 |
Check out the API reference documentation to learn more about what you can do with the Azure Document Intelligence client library.