Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
page_type languages products urlFragment
sample
python
azure
azure-cognitive-services
azure-form-recognizer
formrecognizer-samples

Samples for Azure Form Recognizer client library for Python

Note: Starting with version 2022-08-31, a new set of clients were introduced to leverage the newest features of the Document Intelligence service. Please see the Migration Guide for detailed instructions on how to update application code from client library version 3.1.X or lower to the latest version. Additionally, see the Changelog for more detailed information.

These code samples show common scenario operations with the Azure Form Recognizer client library.

All of these samples need the endpoint to your Form Recognizer resource (instructions on how to get endpoint), and your Form Recognizer API key (instructions on how to get key).

Samples for client library versions 3.2.0 and later

File Name Description
sample_authentication.py and sample_authentication_async.py Authenticate the client
sample_analyze_layout.py and sample_analyze_layout_async.py Extract text, selection marks, and table structures in a document
sample_analyze_general_documents.py and sample_analyze_general_documents_async.py Analyze document key-value pairs, tables, and selection marks using a prebuilt model
sample_analyze_read.py and sample_analyze_read_async.py Read document elements, such as pages and detected languages
sample_analyze_invoices.py and sample_analyze_invoices_async.py Analyze document text, selection marks, tables, and pre-trained fields and values pertaining to English invoices using a prebuilt model
sample_analyze_business_cards.py and sample_analyze_business_cards_async.py Analyze document text and pre-trained fields and values pertaining to English business cards using a prebuilt model
sample_analyze_identity_documents.py and sample_analyze_identity_documents_async.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 and sample_analyze_receipts_async.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 and sample_analyze_tax_us_w2_async.py Analyze document text and pre-trained fields and values pertaining to US tax W-2 forms using a prebuilt model
sample_analyze_custom_documents.py and sample_analyze_custom_documents_async.py Analyze custom documents with your custom model to extract text, field values, selection marks, and table data from documents
sample_build_model.py and sample_build_model_async.py Build a custom model
sample_compose_model.py and sample_compose_model_async.py Create a composed model from a collection of existing models to be called with a single model ID
sample_manage_models.py and sample_manage_models_async.py Manage the models in your account
sample_get_operations.py and sample_get_operations_async.py Get and list the document model operations created within the past 24 hours
sample_copy_model_to.py and sample_copy_model_to_async.py Copy a custom model from one Form Recognizer resource to another
sample_get_words_on_document_line.py and sample_get_words_on_document_line_async.py Get the words in a DocumentLine
sample_convert_to_and_from_dict.py and sample_convert_to_and_from_dict_async.py Convert model types to a dictionary that can be used to create JSON content, then convert the same dictionary back to the original model type
sample_get_elements_with_spans.py and sample_get_elements_with_spans_async.py Get elements, such as words, lines, and styles, in the result of an analyze operation by searching with spans
sample_classify_document.py and sample_classify_document_async.py Classify documents with a custom classification model.
sample_classify_document_from_url.py and sample_classify_document_from_url_async.py Classify documents from URL with a custom classification model.
sample_build_classifier.py and sample_build_classifier_async.py Build a custom document classifier.
sample_manage_classifiers.py and sample_manage_classifiers_async.py Manage custom document classification models.
sample_send_request.py and sample_send_request_async.py Use the send_request client method.
sample_analyze_addon_barcodes.py and sample_analyze_addon_barcodes_async.py Extract barcodes using the add-on capability.
sample_analyze_addon_fonts.py and sample_analyze_addon_fonts_async.py Extract font information using the add-on capability.
sample_analyze_addon_formulas.py and sample_analyze_addon_formulas_async.py Extract formulas using the add-on capability.
sample_analyze_addon_highres.py and sample_analyze_addon_highres_async.py Recognize text with improved quality using the add-on capability.
sample_analyze_addon_languages.py and sample_analyze_addon_languages_async.py Detect languages using the add-on capability.

Samples for client library versions 3.1.X

File Name Description
sample_authentication.py and sample_authentication_async.py Authenticate the client
sample_recognize_content.py and sample_recognize_content_async.py Recognize text, selection marks, and table structures in a document
sample_recognize_receipts.py and sample_recognize_receipts_async.py Recognize data from a file of a sales receipt using a prebuilt model
sample_recognize_receipts_from_url.py and sample_recognize_receipts_from_url_async.py Recognize data from a URL of a sales receipt using a prebuilt model
sample_recognize_business_cards.py and sample_recognize_business_cards_async.py Recognize data from a file of a business card using a prebuilt model
sample_recognize_identity_documents.py and sample_recognize_identity_documents_async.py Recognize data from a file of an ID document using a prebuilt model
sample_recognize_invoices.py and sample_recognize_invoices_async.py Recognize data from a file of an invoice using a prebuilt model
sample_recognize_custom_forms.py and sample_recognize_custom_forms_async.py Recognize forms with your custom model
sample_train_model_without_labels.py and sample_train_model_without_labels_async.py Train a custom model with unlabeled data
sample_train_model_with_labels.py and sample_train_model_with_labels_async.py Train a custom model with labeled data
sample_manage_custom_models.py and sample_manage_custom_models_async.py Manage the custom models in your account
sample_copy_model.py and sample_copy_model_async.py Copy a custom model from one Form Recognizer resource to another
sample_create_composed_model.py and sample_create_composed_model_async.py Create a composed model from a collection of existing models trained with labels
sample_strongly_typing_recognized_form.py and sample_strongly_typing_recognized_form_async.py Use the fields in your recognized forms to create an object with strongly-typed fields
sample_get_bounding_boxes.py and sample_get_bounding_boxes_async.py Get info to visualize the outlines of form content and fields, which can be used for manual validation
sample_differentiate_output_models_trained_with_and_without_labels.py and sample_differentiate_output_models_trained_with_and_without_labels_async.py See the differences in output when using a custom model trained with labeled data and one trained with unlabeled data
sample_differentiate_output_labeled_tables.py and sample_differentiate_output_labeled_tables_async.py See the differences in output when using a custom model trained with fixed vs. dynamic table tags
sample_convert_to_and_from_dict.py and sample_convert_to_and_from_dict_async.py Convert model types to a dictionary that can be used to create JSON content, then convert the same dictionary back to the original model type

Samples for client library versions 3.0.0 and below

Please see the samples here.

Prerequisites

Setup

  1. Install the Azure Form Recognizer client library for Python with pip:
pip install azure-ai-formrecognizer --pre
  1. Clone or download this sample repository
  2. Open the sample folder in Visual Studio Code or your IDE of choice.

Running 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

Next steps

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