Skip to content

Latest commit

 

History

History
85 lines (62 loc) · 5.6 KB

File metadata and controls

85 lines (62 loc) · 5.6 KB

Samples for Azure Document Intelligence client library for Python(Prebuilt 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 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

Setup

  1. Install the Azure Document Intelligence client library for Python with pip:
pip install azure-ai-documentintelligence --pre
  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_receipts.py" in an editor or IDE.
  2. Open the "sample_analyze_receipts.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_receipts.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_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

Next steps

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