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.
- Azure subscription - Create one for free.
- Python 3.8 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 DOCUMENTINTELLIGENCE_API_KEY <yourKey>
setx DOCUMENTINTELLIGENCE_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/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
- Install the Azure Document Intelligence client library for Python with pip:
pip install azure-ai-documentintelligence --pre
- 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_receipts.py" in an editor or IDE.
- Open the "sample_analyze_receipts.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_receipts.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_receipts.py
File Name | Usage scenarios |
---|---|
sample_analyze_invoices.py | Analyze document text, selection marks, tables, and pre-trained fields and values pertaining to English invoices using a prebuilt model |
sample_analyze_identity_documents.py | Analyze document text and pre-trained fields and values pertaining to US driver licenses and international passports using a prebuilt model |
sample_analyze_receipts.py | Analyze document text and pre-trained fields and values pertaining to English sales receipts using a prebuilt model |
sample_analyze_tax_us_w2.py | Analyze document text and pre-trained fields and values pertaining to US tax W-2 forms using a prebuilt model |
Check out the API reference documentation to learn more about what you can do with the Azure Document Intelligence client library.