Skip to content

Latest commit

 

History

History
99 lines (74 loc) · 7.6 KB

File metadata and controls

99 lines (74 loc) · 7.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 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_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_bank_statement.py Analyze document text and pre-trained fields and values pertaining to bank statements using a prebuilt model
sample_analyze_check_us.py Analyze check images and extract check fields using a prebuilt model
sample_analyze_contracts.py Analyze document text and key fields in legal contracts using a prebuilt model
sample_analyze_credit_cards.py Analyze document text and key information on credit cards using a prebuilt model
sample_analyze_health_insurance_cards.py Analyze document text and pre-trained fields on US health insurance cards using a prebuilt model
sample_analyze_identity_documents.py Analyze document text and pre-trained fields and values pertaining to ID documents using a prebuilt model
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_marriage_certificates.py Analyze document text and fields in US marriage certificates using a prebuilt model
sample_analyze_mortgage_1003.py Analyze fields and values in the US Mortgage 1003 using a prebuilt model
sample_analyze_mortgage_1004.py Analyze fields and values in the US Mortgage 1004 using a prebuilt model
sample_analyze_mortgage_1005.py Analyze fields and values in the US Mortgage 1005 using a prebuilt model
sample_analyze_mortgage_1008.py Analyze fields and values in the US Mortgage 1008 using a prebuilt model
sample_analyze_mortgage_closing_disclosure.py Analyze fields and values in the US Mortgage Closing Disclosure using a prebuilt model
sample_analyze_pay_stub.py Analyze document text and structured information on pay stubs using a prebuilt model
sample_analyze_receipts.py Analyze document text and pre-trained fields and values pertaining to 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.
Below are US tax forms supported by the model:
US personal tax
US tax W-2
US tax W-4
US tax 1040
US tax 1095
US tax 1098
US tax 1099

Next steps

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