### Install ABBYY Document AI SDK with Poetry Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/python.md Details how to install the ABBYY Document AI Python SDK using Poetry, a modern dependency management tool. Poetry simplifies project setup by using a `pyproject.toml` file. ```Python poetry add abbyy-document-ai ``` -------------------------------- ### Install ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/quickstart.md Shows the pip command to install the official ABBYY Document AI SDK for Python. This SDK provides convenient methods for interacting with the Document AI API, abstracting away direct HTTP requests. ```bash pip install abbyy-document-ai ``` -------------------------------- ### Synchronous ABBYY Document AI SDK Example Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/python.md Presents a synchronous example of using the ABBYY Document AI SDK to interact with the API. It shows how to initialize the `DocumentAi` client with an API key (from environment variables) and how to list documents with built-in pagination handling. ```Python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.documents.list(cursor="") while res is not None: # Handle items res = res.next() ``` -------------------------------- ### Install ABBYY Document AI SDK with pip Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/python.md Provides instructions for installing the ABBYY Document AI Python SDK using the `pip` package manager. This is the default method for installing Python packages from PyPI. ```Python pip install abbyy-document-ai ``` -------------------------------- ### Example JSON Output of Extracted Invoice Fields Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/quickstart.md Provides a comprehensive JSON example of the structured data extracted from an invoice by the ABBYY Document AI API. It includes detailed metadata, general invoice fields like number, date, and total, along with information about the business unit, vendor, and an array of line items with their respective details. ```json { "meta": { "id": "r23qpmmjsc7f93o3", "name": "Invoice%20CA_1.pdf", "createdAt": "2025-04-01 20:41:26.510152", "status": "Processed", "pageCount": 1 }, "fields": { "invoiceNumber": "9435435", "invoiceDate": "2021-11-11", "total": 4620, "currency": "CAD", "businessUnit": { "name": "M GROUP INC.", "address": "770-21ST AVENUE N\nSASKATOON SK S1K7R1\nCANADA", "country": "CA" }, "vendor": { "name": "ANADAYA CANADA", "address": "262 Merrier Avenue, Toronto, Ontario Т1Т 3R29" }, "reversedCharged": false, "invoiceType": { "invoice": true, "creditNote": false }, "purchaseOrder": [ { "orderChecked": false } ], "lineItems": [ { "isValid": false, "position": 1, "articleNumberVendor": "864UW7", "description": "RECEIVER (19003)", "quantity": 2, "unitPrice": 385, "netPrice": 770, "currency": "CAD" }, { "isValid": false, "position": 2, "articleNumberVendor": "864UW7", "description": "RECEIVER (85813)", "quantity": 2, "unitPrice": 385, "netPrice": 770, "currency": "CAD" }, { "isValid": false, "position": 3, "articleNumberVendor": "384 UW5", "description": "RECEIVER (19053)", "quantity": 2, "unitPrice": 385, "netPrice": 770, "currency": "CAD" }, { "isValid": false, "position": 4, "articleNumberVendor": "365UW8", "description": "RECEIVER (85583)", "quantity": 2, "unitPrice": 385, "netPrice": 770, "currency": "CAD" }, { "isValid": false, "position": 5, "articleNumberVendor": "354UW7", "description": "RECEIVER (15003)", "quantity": 2, "unitPrice": 385, "netPrice": 770, "currency": "CAD" }, { "isValid": false, "position": 6, "articleNumberVendor": "564UW7", "description": "RECEIVER (85513)", "quantity": 2, "unitPrice": 385, "netPrice": 770, "currency": "CAD" } ] } } ``` -------------------------------- ### Set Up Python Virtual Environment and Project File Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/quickstart.md Provides commands to create and activate a Python virtual environment, and then create a placeholder file for the application code. This is a common first step for Python projects to manage dependencies and isolate project-specific packages. ```bash # Create a virtual environment python3 -m venv venv # On macOS or Linux: source venv/bin/activate # On Windows: venv\Scripts\activate # Create a file touch docai.py ``` -------------------------------- ### Example JSON Response for Document Submission Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/quickstart.md Illustrates the JSON structure returned by the Document AI API after successfully submitting an invoice for processing. This response provides essential metadata, including the unique document ID, its name, creation timestamp, current processing status, and page count. ```json [ { "id": "r23qpmmjsc7f93o3", "name": "Invoice%20CA_1.pdf", "createdAt": "2025-04-01 20:41:26.510152", "status": "Pending", "pageCount": 1 } ] ``` -------------------------------- ### Manage SDK Resources with Context Managers Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/python.md Illustrates how to use the DocumentAi SDK as a context manager for proper resource management, ensuring HTTPX clients are closed. Includes examples for both synchronous (`with`) and asynchronous (`async with`) operations. ```Python from abbyy_document_ai import DocumentAi import os def main(): with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: # Rest of application here... # Or when using async: async def amain(): async with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: # Rest of application here... ``` -------------------------------- ### Use ABBYY Document AI SDK in Python shell with uvx Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/python.md Illustrates how to quickly use the ABBYY Document AI SDK within a Python shell environment. This method leverages `uvx` for direct execution without a full project setup. ```Python uvx --from abbyy-document-ai python ``` -------------------------------- ### Synchronous Document Listing with Authentication and Pagination Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/python.md Illustrates how to initialize the `DocumentAi` SDK client using an API key for authentication, typically sourced from an environment variable. This example also shows synchronous document listing and basic pagination by repeatedly calling `res.next()` to fetch subsequent pages. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.documents.list(cursor="") while res is not None: # Handle items res = res.next() ``` -------------------------------- ### Start Purchase Order Field Extraction (Python) Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python snippet initiates the AI-driven field extraction process for a purchase order document. It takes a document URL as input and uses the ABBYY Document AI SDK to begin processing. The response `documents` object indicates the start of the extraction. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.purchase_order.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/invoice.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Start Remittance Advice Field Extraction (Python) Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python snippet initiates the AI-driven field extraction process for a remittance advice document. It takes a document URL as input and uses the ABBYY Document AI SDK to begin processing. The response `documents` object indicates the start of the extraction. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.remittance_advice.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/invoice.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Python SDK: List Documents and Handle API Errors Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/python.md This example demonstrates how to initialize the ABBYY Document AI Python SDK, list documents with pagination, and implement comprehensive error handling for various API exceptions such as BadRequestError, UnauthorizedError, TooManyRequestsError, InternalServerError, and generic APIError. ```python from abbyy_document_ai import DocumentAi, models import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = None try: res = document_ai.documents.list(cursor="") while res is not None: # Handle items res = res.next() except models.BadRequestError as e: # handle e.data: models.BadRequestErrorData raise(e) except models.UnauthorizedError as e: # handle e.data: models.UnauthorizedErrorData raise(e) except models.TooManyRequestsError as e: # handle e.data: models.TooManyRequestsErrorData raise(e) except models.InternalServerError as e: # handle e.data: models.InternalServerErrorData raise(e) except models.APIError as e: # handle exception raise(e) ``` -------------------------------- ### Start Delivery Note Field Extraction (Python) Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python snippet initiates the AI-driven field extraction process for a delivery note document. It takes a document URL as input and uses the ABBYY Document AI SDK to begin processing. The response `documents` object indicates the start of the extraction. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.delivery_note.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/delivery_note.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Start Hotel Invoice Field Extraction (Python) Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python snippet initiates the AI-driven field extraction process for a hotel invoice document. It takes a document URL as input and uses the ABBYY Document AI SDK to begin processing. The response `documents` object indicates the start of the extraction. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.hotel_invoice.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/hotel_invoice.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Submit Invoice for Data Extraction using Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/quickstart.md Demonstrates how to initialize the DocumentAi client with an API key and submit an invoice document (via URL) for data extraction. The code shows how to capture the document ID from the API response, which is crucial for subsequent retrieval operations. ```python from document_ai_sdk import DocumentAi API_KEY="your-api-key-here" with DocumentAi(api_key_auth=API_KEY) as document_ai: res = document_ai.invoice.extract_invoice_data(input_source={ "url": "https://raw.githubusercontent.com/dotNetkow/test-cods/6c25fa2e54fb96ecf534903aef0d3cbecd71e987/Invoice%20CA_1.pdf", }) docId = res.documents[0].id print(res) ``` -------------------------------- ### Start Taxi Receipt Field Extraction (Python) Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python snippet initiates the AI-driven field extraction process for a taxi receipt document. It takes a document URL as input and uses the ABBYY Document AI SDK to begin processing. The response `documents` object indicates the start of the extraction. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.taxi_receipt.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/taxi_receipt.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Begin Packing List Field Extraction with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python example shows how to initiate the field extraction process for a packing list. It uses the 'begin_field_extraction' method, providing a URL to the document as the input source. The response contains information about the initiated extraction. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.packing_list.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/packing_list.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Extract Form 1040 Fields using Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/model/Know Your Customer/Form 1040, U.S. Individual Income Tax Return, 2022.md This Python example demonstrates how to use the `abbyy_document_ai` SDK to initiate field extraction from a Form 1040 document. It initializes the DocumentAi client with an API key, sends a document URL for processing, and then polls the service until the extraction is complete, finally printing the extracted fields. Replace `YOUR_API_KEY` and the example URL with your actual values. ```python from abbyy_document_ai import DocumentAi with DocumentAi(api_key_auth=YOUR_API_KEY) as document_ai: res = document_ai.models.us_form1040.begin_field_extraction(input_source={ "url": "https://example.com/document.pdf", }) assert res.documents is not None doc_id = res.documents[0].id processed = False while not processed: time.sleep(3) # Wait 3 seconds between checks res = document_ai.models.us_form1040.get_extracted_fields( document_id=doc_id ) processed = res.us_form1040.meta.status == "Processed" print(res.us_form1040.fields) ``` -------------------------------- ### Initiate Field Extraction for Basic Contract (Python) Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python example shows how to begin the field extraction process for a Basic Contract using the ABBYY Document AI SDK. It configures the SDK client with an API key and then invokes the `begin_field_extraction` method, providing a URL to the document as the input source. The method returns processing information, which is then asserted and printed. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.basic_contract.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/basic_contract.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Begin Sea Waybill Field Extraction with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python example shows how to initiate the field extraction process for a sea waybill. It uses the 'begin_field_extraction' method, providing a URL to the document as the input source. The response contains information about the initiated extraction. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.sea_waybill.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/sea_waybill.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Begin Personal Earnings Statement Field Extraction using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md Shows how to start the field extraction process for a Personal Earnings Statement from a given URL. It invokes the `begin_field_extraction` method on the `personal_earnings_statement` model, providing the document's URL. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.personal_earnings_statement.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/earnings_statement.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Initiate Field Extraction for Brokerage Statement (Python) Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python example shows how to begin the field extraction process for a Brokerage Statement using the ABBYY Document AI SDK. It sets up the SDK client with an API key and then calls the `begin_field_extraction` method, providing a URL to the brokerage statement image as the input source. The method returns document processing details, which are then checked and printed. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.brokerage_statement.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/brokerage_statement.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Begin Customs Declaration Field Extraction with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python example shows how to initiate the field extraction process for a customs declaration. It uses the 'begin_field_extraction' method, providing a URL to the document as the input source. The response contains information about the initiated extraction. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.customs_declaration.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/customs_declaration.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Begin Image To Text Extraction with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This snippet demonstrates how to start an image-to-text extraction process using the ABBYY Document AI Python SDK. It specifies the input image URL, desired languages for extraction, and an option for handwriting recognition, asserting that documents are returned. ```python import abbyy_document_ai from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.image_to_text.begin_text_extraction(request={ "input_source": { "url": "https://example.com/documents/invoice.png", }, "options": { "languages": abbyy_document_ai.BeginImageToTextTextExtractionRequestBodyLanguages.EN, "handwriting": True, }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Extract Invoice Data using Python Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/quickstart.md This Python snippet demonstrates how to initialize the Document AI SDK with an API key, extract invoice data from a publicly accessible URL, and then poll for the processing status until the invoice fields are available. It showcases how to access and print specific extracted fields like the invoice number. ```python import time from document_ai_sdk import DocumentAi API_KEY="your-api-key-here" with DocumentAi(api_key_auth=API_KEY) as document_ai: res = document_ai.invoice.extract_invoice_data(input_source={ "url": "https://raw.githubusercontent.com/dotNetkow/test-cods/6c25fa2e54fb96ecf534903aef0d3cbecd71e987/Invoice%20CA_1.pdf", }) docId = res.documents[0].id print(res) processed = False while not processed: time.sleep(3) # Wait 3 seconds between checks res = document_ai.models.invoice.get_extracted_fields( document_id=docId ) processed = res.invoice.meta.status == "Processed" print("Invoice number: ", res.invoice.fields.invoice_number) ``` -------------------------------- ### Begin US Form 1040 Field Extraction using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md Demonstrates how to start the field extraction for a US Form 1040 document from a specified URL. It utilizes the `begin_field_extraction` method on the `us_form_1040` model, passing the document's URL as input. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.us_form_1040.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/form_1040.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Begin International Consignment Note Field Extraction with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python example shows how to initiate the field extraction process for an international consignment note. It uses the 'begin_field_extraction' method, providing a URL to the document as the input source. The response contains information about the initiated extraction. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.international_consignment_note.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/international_consignment_note.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Get Arrival Notice Fields (Python) Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This snippet demonstrates how to retrieve previously extracted fields for an arrival notice using its document ID with the `abbyy_document_ai` Python library. It requires an initialized `DocumentAi` client and a valid `document_id`. The output is the extracted arrival notice fields object. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.arrival_notice.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.arrival_notice is not None # Handle response print(res.arrival_notice) ``` -------------------------------- ### Begin Dangerous Goods Declaration Field Extraction with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python example shows how to initiate the field extraction process for a dangerous goods declaration. It uses the 'begin_field_extraction' method, providing a URL to the document as the input source. The response contains information about the initiated extraction. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.dangerous_goods_declaration.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/dangerous_goods_declaration.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Extract Receipt Fields using Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/model/Expense Management/Receipt.md This Python example demonstrates how to use the ABBYY Document AI SDK to initiate field extraction from a receipt via a URL and then poll for the processing status until completion. It requires an API key and an input document URL, finally printing the extracted fields. ```python from abbyy_document_ai import DocumentAi import time with DocumentAi(api_key_auth=YOUR_API_KEY) as document_ai: res = document_ai.models.receipt.begin_field_extraction(input_source={ "url": "https://example.com/document.pdf", }) assert res.documents is not None doc_id = res.documents[0].id processed = False while not processed: time.sleep(3) # Wait 3 seconds between checks res = document_ai.models.receipt.get_extracted_fields( document_id=doc_id ) processed = res.receipt.meta.status == "Processed" print(res.receipt.fields) ``` -------------------------------- ### Retrieve Extracted Fields for Basic Contract (Python) Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python example demonstrates how to retrieve previously extracted fields for a Basic Contract using the ABBYY Document AI SDK. After initializing the SDK client, it calls the `get_extracted_fields` method, passing a `document_id` for a document that has already undergone processing. The extracted basic contract data is then validated and displayed. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.basic_contract.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.basic_contract is not None # Handle response print(res.basic_contract) ``` -------------------------------- ### Extract W-2 Form Fields using Python with ABBYY Document AI Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/model/Know Your Customer/W-2 Form.md This Python example demonstrates how to use the ABBYY Document AI SDK to extract fields from an IRS W-2 form. It shows the process of initiating field extraction from a URL, then polling the API until the document processing is complete, and finally printing the extracted fields. This snippet requires the 'abbyy_document_ai' Python package and a valid API key. ```python from abbyy_document_ai import DocumentAi import time with DocumentAi(api_key_auth=YOUR_API_KEY) as document_ai: res = document_ai.models.us_form_w2.begin_field_extraction(input_source={ "url": "https://example.com/document.pdf", }) assert res.documents is not None doc_id = res.documents[0].id processed = False while not processed: time.sleep(3) # Wait 3 seconds between checks res = document_ai.models.us_form_w2.get_extracted_fields( document_id=doc_id ) processed = res.us_form_w2.meta.status == "Processed" print(res.us_form_w2.fields) ``` -------------------------------- ### Initialize DocumentAi with Custom Async Client Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/python.md Shows how to initialize the DocumentAi SDK instance by providing a custom asynchronous HTTPX client for underlying operations. ```Python s = DocumentAi(async_client=CustomClient(httpx.AsyncClient())) ``` -------------------------------- ### Extract Sea Waybill Fields with ABBYY Document AI Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/model/Customs Clearance/Custom Clearance.md This Python example illustrates the process of extracting fields from a sea waybill using the ABBYY Document AI SDK. It involves initializing the SDK with an API key, starting the field extraction from a specified URL, and polling the API for the processing status every 3 seconds until the document is processed, finally displaying the extracted fields. ```python from abbyy_document_ai import DocumentAi with DocumentAi(api_key_auth=YOUR_API_KEY) as document_ai: res = document_ai.models.sea_waybill.begin_field_extraction(input_source={ "url": "https://example.com/document.pdf", }) assert res.documents is not None doc_id = res.documents[0].id processed = False while not processed: time.sleep(3) # Wait 3 seconds between checks res = document_ai.models.sea_waybill.get_extracted_fields( document_id=doc_id ) processed = res.sea_waybill.meta.status == "Processed" print(res.sea_waybill.fields) ``` -------------------------------- ### Perform Asynchronous Document Listing with ABBYY Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/python.md Demonstrates how to use the `abbyy_document_ai` SDK to asynchronously list documents, handling pagination. It initializes the client with an API key for authentication from an environment variable and iterates through results using `res.next()`. ```python from abbyy_document_ai import DocumentAi import asyncio import os async def main(): async with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = await document_ai.documents.list_async(cursor="") while res is not None: # Handle items res = res.next() asyncio.run(main()) ``` -------------------------------- ### Begin Document Conversion with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This snippet illustrates how to initiate a document conversion process using the ABBYY Document AI Python SDK. It takes an input source URL and specifies the desired output format (e.g., PDF) for the conversion, asserting that documents are returned. ```python import abbyy_document_ai from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.document_conversion.begin_conversion(request={ "input_source": { "url": "https://example.com/documents/invoice.png", }, "options": { "format_": abbyy_document_ai.DocumentConversionOutputFormat.PDF, }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Create standalone Python script with uv for ABBYY Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/python.md Demonstrates how to create and run a self-contained Python script utilizing the ABBYY Document AI SDK. The script includes dependency declarations and uses `uv` for execution, making it suitable for quick prototyping. ```Python #!/usr/bin/env -S uv run --script # /// script # requires-python = ">=3.9" # dependencies = [ # "abbyy-document-ai", # ] # /// from abbyy_document_ai import DocumentAi sdk = DocumentAi( # SDK arguments ) # Rest of script here... ``` -------------------------------- ### Get Extracted Text with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This snippet shows how to retrieve the text extracted from an image after the extraction process has completed. It uses the document ID to fetch the extracted text content, asserting that extracted text is available. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.image_to_text.get_extracted_text(document_id="wh23anb5xjf0ntw5taase5qz") assert res.extracted_text is not None # Handle response print(res.extracted_text) ``` -------------------------------- ### Begin Arrival Notice Field Extraction (Python) Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This snippet shows how to initiate the field extraction process for an arrival notice by providing its URL using the `abbyy_document_ai` Python library. It uses the `DocumentAi` client and expects a `request` object containing the `input_source` URL. The output is a response object containing information about the initiated document processing. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.arrival_notice.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/arrival_notice.png", }, }) assert res.documents is not None # Handle response print(res.documents) ``` -------------------------------- ### Get Personal Earnings Statement Fields using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md Illustrates how to retrieve the extracted fields for a Personal Earnings Statement using its document ID. It calls the `get_extracted_fields` method on the `personal_earnings_statement` model to obtain the processed data. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.personal_earnings_statement.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.personal_earnings_statement is not None # Handle response print(res.personal_earnings_statement) ``` -------------------------------- ### Build HTTP Requests with Custom Client Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/python.md Demonstrates how to build an HTTP request using a custom client, passing various parameters like method, URL, content, data, files, JSON, parameters, headers, cookies, timeout, and extensions. ```Python return self.client.build_request( method, url, content=content, data=data, files=files, json=json, params=params, headers=headers, cookies=cookies, timeout=timeout, extensions=extensions, ) ``` -------------------------------- ### Get Receipt Fields with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This snippet demonstrates how to retrieve the structured fields extracted from a receipt after the extraction process is complete. It uses the document ID to fetch the parsed receipt data, asserting that receipt data is available. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.receipt.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.receipt is not None # Handle response print(res.receipt) ``` -------------------------------- ### Get US Form W2 Fields using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md Demonstrates how to fetch the extracted fields for a US Form W2 document using its document ID. It uses the `get_extracted_fields` method on the `us_form_w2` model to retrieve the structured data. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.us_form_w2.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.us_form_w2 is not None # Handle response print(res.us_form_w2) ``` -------------------------------- ### Get US Form 1040 Fields using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md Shows how to retrieve the extracted fields for a US Form 1040 document using its document ID. It invokes the `get_extracted_fields` method on the `us_form_1040` model to obtain the processed data. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.us_form_1040.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.us_form_1040 is not None # Handle response print(res.us_form_1040) ``` -------------------------------- ### List Documents with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This snippet demonstrates how to list documents using the ABBYY Document AI Python SDK. It initializes the DocumentAi client with an API key and then iteratively fetches documents using a cursor until no more results are available. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.documents.list(cursor="xyz") while res is not None: # Handle items res = res.next() ``` -------------------------------- ### Get Utility Bill Fields using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md Illustrates how to fetch the extracted fields for a utility bill using its document ID after the extraction process is complete. It calls the `get_extracted_fields` method on the `utility_bill` model to retrieve the structured data. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.utility_bill.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.utility_bill is not None # Handle response print(res.utility_bill) ``` -------------------------------- ### Configure SDK Debugging with Custom Logger Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/python.md Explains how to enable debug logging for the SDK by passing a custom Python `logging` instance. This allows detailed insight into SDK requests and responses. ```Python from abbyy_document_ai import DocumentAi import logging logging.basicConfig(level=logging.DEBUG) s = DocumentAi(debug_logger=logging.getLogger("abbyy_document_ai")) ``` -------------------------------- ### Get Sea Waybill Fields using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md This Python snippet demonstrates how to retrieve extracted fields for a sea waybill using its document ID. It initializes the DocumentAi client, calls the 'get_extracted_fields' method on the 'sea_waybill' model, and prints the result. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.sea_waybill.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.sea_waybill is not None # Handle response print(res.sea_waybill) ``` -------------------------------- ### Begin Utility Bill Field Extraction using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-doc/blob/main/api documentation.md Shows how to initiate the field extraction process for a utility bill from a given URL. It uses the `begin_field_extraction` method on the `utility_bill` model, providing an `input_source` URL for the document. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( api_key_auth=os.getenv("DOCUMENTAI_API_KEY_AUTH", ""), ) as document_ai: res = document_ai.models.utility_bill.begin_field_extraction(request={ "input_source": { "url": "https://example.com/documents/utility_bill.png", }, }) assert res.documents is not None # Handle response print(res.documents) ```