Samples for Azure Form Recognizer client library for Python

These code samples show common scenario operations with the Azure Form Recognizer client library. The async versions of the samples require Python 3.5 or later.

These sample programs show common scenarios for the Form Recognizer client's offerings.

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).

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

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_recognize_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.

Advanced Sample File Name Description
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