### Install ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/quickstart.md Command to install the official ABBYY Document AI Python SDK using pip, making it available for use in your project. ```bash pip install abbyy-document-ai ``` -------------------------------- ### Set Up Python Virtual Environment and Project File Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/quickstart.md Commands to create and activate a Python virtual environment, and then create an empty Python file for the project. This ensures dependencies are isolated. ```bash # Create a virtual environment python3 -m venv venv # On macOS or Linux: source venv/bin/activate # On Windows: vvenv\Scripts\activate # Create a file touch docai.py ``` -------------------------------- ### Install ABBYY Document AI SDK with pip Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/python.md Installs the ABBYY Document AI Python SDK using the pip package manager, which is the default installer for Python packages from PyPI. ```Shell pip install abbyy-document-ai ``` -------------------------------- ### Install ABBYY Document AI SDK with Poetry Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/python.md Adds the ABBYY Document AI Python SDK as a dependency using Poetry, a modern tool for dependency management and package publishing, utilizing a pyproject.toml file. ```Shell poetry add abbyy-document-ai ``` -------------------------------- ### Begin Basic Contract Field Extraction Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This example illustrates how to initiate the field extraction process for a Basic Contract using the ABBYY Document AI SDK. It sends a request with an input source URL pointing to the document and asserts that the extraction process has started successfully. ```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 Brokerage Statement Field Extraction Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This code example demonstrates how to start the field extraction process for a Brokerage Statement using the ABBYY Document AI SDK. It sends the document's URL as an input source to the service and verifies that the extraction request was successfully initiated. ```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) ``` -------------------------------- ### Extract Invoice Data using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/quickstart.md Python code to initialize the Document AI SDK with an API key and send an invoice file for processing. It demonstrates how to use the 'documents/invoice' endpoint and capture the document ID from the initial response. ```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) ``` -------------------------------- ### ABBYY Document AI Invoice Processing API Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/quickstart.md Documentation for the ABBYY Document AI API endpoints related to invoice processing, including initial submission and retrieval of extracted fields. It details the request parameters, response structures, and status handling. ```APIDOC Endpoint: POST /documents/invoice Description: Submits an invoice document for data extraction. Parameters: input_source (object): Defines the source of the invoice document. url (string): URL to the invoice file. Headers: Authorization: Bearer Response (Initial Submission): Type: JSON Array of Document Objects Example: [ { "id": "r23qpmmjsc7f93o3", "name": "Invoice%20CA_1.pdf", "createdAt": "2025-04-01 20:41:26.510152", "status": "Pending", "pageCount": 1 } ] Properties: id (string): Unique identifier for the submitted document. name (string): Original name of the document. createdAt (string): Timestamp of document submission. status (string): Current processing status (e.g., 'Pending', 'Processed'). pageCount (integer): Number of pages in the document. Endpoint: GET /documents/invoice/[document-id] Description: Retrieves the extracted fields for a previously submitted invoice document. Parameters: document_id (string): The ID of the document obtained from the initial submission. Response (Processed Invoice Fields): Type: JSON Object Example: { "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" } ] } } ``` -------------------------------- ### Extract Invoice Data and Poll for Completion (Python) Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/quickstart.md This Python snippet demonstrates how to initialize the Document AI SDK, submit an invoice PDF for data extraction using a URL, and then poll the API until the document processing is complete. It showcases how to retrieve 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) ``` -------------------------------- ### Manage DocumentAi SDK Resources with Python Context Manager Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/python.md This example demonstrates how to use the DocumentAi class as a context manager in Python for both synchronous and asynchronous operations. Utilizing 'with' statements ensures proper resource cleanup, such as closing HTTP connections and freeing memory, which is crucial for long-lived applications to prevent resource leaks. ```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... ``` -------------------------------- ### Begin Field Extraction for Purchase Orders using ABBYY Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python example illustrates how to initiate the field extraction process for a purchase order document using the ABBYY Document AI SDK. It sets up the DocumentAi client and then calls the `begin_field_extraction` method on the purchase order model, providing a URL to the input document. 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.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 Packing List Field Extraction with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This code initiates the field extraction process for a packing list document from a specified URL. It sets up the Document AI client using an API key and then invokes the `begin_field_extraction` method, providing the document's URL as input. The response, containing document processing details, is then 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.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) ``` -------------------------------- ### Begin Field Extraction for Remittance Advice using ABBYY Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python example illustrates how to initiate the field extraction process for a remittance advice document using the ABBYY Document AI SDK. It sets up the DocumentAi client and then calls the `begin_field_extraction` method on the remittance advice model, providing a URL to the input document. 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.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) ``` -------------------------------- ### Override ABBYY Document AI SDK Server URL in Python Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/python.md This example shows how to configure the ABBYY Document AI SDK to use a custom server URL instead of the default one. It initializes the SDK with a specified `server_url` parameter, allowing for connection to different API endpoints. ```python from abbyy_document_ai import DocumentAi import os with DocumentAi( server_url="https://api.abbyy.com/document-ai", 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() ``` -------------------------------- ### Wrap Custom HTTP Client for ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/python.md This advanced example demonstrates how to create a custom HTTP client class that wraps an existing `AsyncHttpClient` to inject custom logic, such as modifying request headers before sending. It shows how to implement the `send` method to intercept and modify requests, providing fine-grained control over network operations. ```python from abbyy_document_ai import DocumentAi from abbyy_document_ai.httpclient import AsyncHttpClient import httpx class CustomClient(AsyncHttpClient): client: AsyncHttpClient def __init__(self, client: AsyncHttpClient): self.client = client async def send( self, request: httpx.Request, *, stream: bool = False, auth: Union[ httpx._types.AuthTypes, httpx._client.UseClientDefault, None ] = httpx.USE_CLIENT_DEFAULT, follow_redirects: Union[ bool, httpx._client.UseClientDefault ] = httpx.USE_CLIENT_DEFAULT, ) -> httpx.Response: request.headers["Client-Level-Header"] = "added by client" return await self.client.send( request, stream=stream, auth=auth, follow_redirects=follow_redirects ) def build_request( self, method: str, url: httpx._types.URLTypes, *, content: Optional[httpx._types.RequestContent] = None, data: Optional[httpx._types.RequestData] = None, files: Optional[httpx._types.RequestFiles] = None, json: Optional[Any] = None, params: Optional[httpx._types.QueryParamTypes] = None, headers: Optional[httpx._types.HeaderTypes] = None, cookies: Optional[httpx._types.CookieTypes] = None, timeout: Union[ httpx._types.TimeoutTypes, httpx._client.UseClientDefault ] = httpx.USE_CLIENT_DEFAULT, extensions: Optional[httpx._types.RequestExtensions] = None, ) -> httpx.Request: ``` -------------------------------- ### Begin Field Extraction for Delivery Notes using ABBYY Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python example illustrates how to initiate the field extraction process for a delivery note document using the ABBYY Document AI SDK. It sets up the DocumentAi client and then calls the `begin_field_extraction` method on the delivery note model, providing a URL to the input document. 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.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) ``` -------------------------------- ### Retrieve Document Conversion Status with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This example demonstrates how to retrieve the status and results of a previously initiated document conversion using its document ID. It queries the `get_conversion` method to check the progress and obtain the conversion results, which can then be processed or downloaded. ```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.document_conversion.get_conversion(document_id="wh23anb5xjf0ntw5taase5qz") assert res.conversion_results is not None # Handle response print(res.conversion_results) ``` -------------------------------- ### Begin Field Extraction for Hotel Invoices using ABBYY Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python example illustrates how to initiate the field extraction process for a hotel invoice document using the ABBYY Document AI SDK. It sets up the DocumentAi client and then calls the `begin_field_extraction` method on the hotel invoice model, providing a URL to the input document. 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.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) ``` -------------------------------- ### Start Sea Waybill Field Extraction with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This code initiates the field extraction process for a sea waybill document from a specified URL. It sets up the Document AI client using an API key and then invokes the `begin_field_extraction` method, providing the document's URL as input. The response, containing document processing details, is then 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.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) ``` -------------------------------- ### Extract Personal Earnings Statement Fields with Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/model/Know Your Customer/Personal Earning Statement.md This Python example demonstrates how to use the ABBYY Document AI SDK to initiate field extraction from a document URL and then poll for the processing status until the fields are successfully extracted. It requires an API key for authentication and handles the asynchronous nature of document processing. ```python from abbyy_document_ai import DocumentAi import time with DocumentAi(api_key_auth=YOUR_API_KEY) as document_ai: res = document_ai.models.personal_earnings_statement.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.personal_earnings_statement.get_extracted_fields( document_id=doc_id ) processed = res.personal_earnings_statement.meta.status == "Processed" print(res.personal_earnings_statement.fields) ``` -------------------------------- ### Get Arrival Notice Extracted Fields using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python snippet retrieves the extracted fields for a specific arrival notice document using the ABBYY Document AI SDK. It initializes the client with an API key and calls the `get_extracted_fields` method on the `arrival_notice` model, asserting the response and printing the extracted 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.arrival_notice.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.arrival_notice is not None # Handle response print(res.arrival_notice) ``` -------------------------------- ### Begin Field Extraction for Taxi Receipts using ABBYY Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python example illustrates how to initiate the field extraction process for a taxi receipt document using the ABBYY Document AI SDK. It sets up the DocumentAi client and then calls the `begin_field_extraction` method on the taxi receipt model, providing a URL to the input document. 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.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) ``` -------------------------------- ### Start Customs Declaration Field Extraction with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This code initiates the field extraction process for a customs declaration document from a specified URL. It sets up the Document AI client using an API key and then invokes the `begin_field_extraction` method, providing the document's URL as input. The response, containing document processing details, is then 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.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) ``` -------------------------------- ### Extract Form 1040 Fields with Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/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 for a Form 1040 document from a specified URL. It includes polling logic to wait for the document processing to complete and then prints the extracted fields. An API key is required for authentication. ```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) ``` -------------------------------- ### Extract W-2 Form Data using Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/model/Know Your Customer/W-2 Form.md This Python code demonstrates how to use the ABBYY Document AI SDK to initiate W-2 form data extraction from a specified URL. It includes a polling mechanism to wait for the document processing to complete and then prints the extracted fields. This example highlights the asynchronous nature of document processing. ```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) ``` -------------------------------- ### Start International Consignment Note Field Extraction with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This code initiates the field extraction process for an international consignment note document from a specified URL. It sets up the Document AI client using an API key and then invokes the `begin_field_extraction` method, providing the document's URL as input. The response, containing document processing details, is then 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.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) ``` -------------------------------- ### Extract Fields from Packing List using Python Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/model/Customs Clearance/Custom Clearance.md This Python example illustrates how to leverage the ABBYY Document AI SDK to extract structured data from a Packing List. It sets up the DocumentAi client, begins the field extraction process for a document from a URL, and continuously checks the processing status until completion, then outputs 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.packing_list.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.packing_list.get_extracted_fields( document_id=doc_id ) processed = res.packing_list.meta.status == "Processed" print(res.packing_list.fields) ``` -------------------------------- ### Get Extracted Fields for Remittance Advice using ABBYY Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python snippet demonstrates how to retrieve previously extracted fields for a specific remittance advice document using the ABBYY Document AI SDK. It initializes the DocumentAi client with an API key and then calls the `get_extracted_fields` method on the remittance advice model, asserting that the remittance advice data is not None. ```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.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.remittance_advice is not None # Handle response print(res.remittance_advice) ``` -------------------------------- ### Start Dangerous Goods Declaration Field Extraction with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This code initiates the field extraction process for a dangerous goods declaration document from a specified URL. It sets up the Document AI client using an API key and then invokes the `begin_field_extraction` method, providing the document's URL as input. The response, containing document processing details, is then 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.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) ``` -------------------------------- ### Run Python shell with ABBYY Document AI SDK using uvx Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/python.md Launches a Python shell with the ABBYY Document AI SDK available, utilizing the uvx command for quick execution without needing to set up a full project environment. ```Shell uvx --from abbyy-document-ai python ``` -------------------------------- ### Perform Asynchronous Document Listing with ABBYY Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/python.md Demonstrates how to use the `DocumentAi` SDK asynchronously to list documents, including handling pagination. It initializes the client with an API key from an environment variable and iterates through results using `list_async`. ```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()) ``` -------------------------------- ### Get Brokerage Statement Fields Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This snippet illustrates how to retrieve the extracted fields for a Brokerage Statement after its processing has been completed. It uses the document ID to query the ABBYY Document AI service and then prints the extracted data for the brokerage statement. ```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.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.brokerage_statement is not None # Handle response print(res.brokerage_statement) ``` -------------------------------- ### Synchronous usage of ABBYY Document AI SDK to list documents Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/python.md Illustrates how to initialize the ABBYY Document AI SDK client with an API key and perform a synchronous API call to list documents, including handling pagination through the `res.next()` method. ```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() ``` -------------------------------- ### List Documents with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This snippet demonstrates how to list documents using the ABBYY Document AI Python SDK. It initializes the client with an API key and then iteratively fetches documents, handling pagination with the `cursor` and `next()` method to retrieve all available items. ```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() ``` -------------------------------- ### Retrieve Extracted Text with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This example demonstrates how to retrieve the text extracted from an image after an image-to-text extraction process has completed. It uses the document ID to fetch the results, providing access to the recognized text content. ```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) ``` -------------------------------- ### Create and run standalone Python script with ABBYY Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/python.md Demonstrates how to write a self-contained Python script that uses the ABBYY Document AI SDK, including dependency declaration within the script for execution with `uv run`. ```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 Basic Contract Fields Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python snippet shows how to retrieve the results of a previously initiated field extraction for a Basic Contract. It uses the document ID to fetch the processed data from the ABBYY Document AI service and prints the extracted contract information. ```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) ``` -------------------------------- ### Begin Document Conversion with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This snippet initiates a document conversion process using the ABBYY Document AI Python SDK. It specifies an input document via a URL and defines the desired output format, such as PDF. The response contains information about the newly created converted document. ```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) ``` -------------------------------- ### Get International Consignment Note Fields Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python snippet demonstrates how to retrieve the extracted fields for an International Consignment Note using the ABBYY Document AI SDK. It requires a document ID for a previously processed document and asserts that the response contains the expected 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.international_consignment_note.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.international_consignment_note is not None # Handle response print(res.international_consignment_note) ``` -------------------------------- ### Poll ABBYY Document AI API for Processed Invoice Results Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/quickstart.md Python code demonstrating how to poll the Document AI API to check the processing status of an invoice. It repeatedly calls the API until the document's status changes to 'Processed', then accesses and prints an extracted field. ```python # import time module at the top of the file for waiting between field checks import time 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) ``` -------------------------------- ### Authenticate and List Documents Synchronously with ABBYY Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/python.md Illustrates synchronous authentication and document listing using the `DocumentAi` SDK. The API key is loaded from an environment variable, and the `documents.list` method is called to retrieve and paginate through document results. ```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() ``` -------------------------------- ### Extract Receipt Fields with ABBYY Document AI (Python) Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/model/Expense Management/Receipt.md This Python example demonstrates how to use the `abbyy_document_ai` library to initiate and poll for structured data extraction from a receipt. It shows the workflow from beginning field extraction with a URL input to retrieving and printing the processed receipt 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) ``` -------------------------------- ### Begin Arrival Notice Field Extraction using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python snippet initiates the field extraction process for an arrival notice using the ABBYY Document AI SDK. It configures the client with an API key and sends a request with the URL of the arrival notice image to the `begin_field_extraction` method, asserting the response and printing the document details. ```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) ``` -------------------------------- ### Extract Brokerage Statement Fields with Python Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/model/Contract and Brokeage Statement/Contract and Brokerage.md This Python snippet uses the ABBYY Document AI SDK to extract data from a brokerage statement. It starts the extraction process for a document provided via URL, then repeatedly checks the processing status until completion, and outputs 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.brokerage_statement.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.brokerage_statement.get_extracted_fields( document_id=doc_id ) processed = res.brokerage_statement.meta.status == "Processed" print(res.brokerage_statement.fields) ``` -------------------------------- ### Delete Document with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This example shows how to delete a specific document by its ID using the ABBYY Document AI Python SDK. It initializes the client with the necessary API key and then calls the `delete` method on the `documents` service, asserting a successful response upon completion. ```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.delete(document_id="wh23anb5xjf0ntw5taase5qz") assert res is not None # Handle response print(res) ``` -------------------------------- ### List Documents with ABBYY Document AI Python SDK and Error Handling Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/python.md This snippet demonstrates how to initialize the ABBYY Document AI SDK, list documents using pagination, and implement robust error handling for various API exceptions such as BadRequestError, UnauthorizedError, TooManyRequestsError, InternalServerError, and a 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) ``` -------------------------------- ### Retrieve Extracted Receipt Fields with ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This example demonstrates how to retrieve the structured data fields extracted from a receipt after the field extraction process has completed. It uses the document ID to fetch the results, providing access to parsed information like total amount, vendor, and line items. ```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 Extracted Fields for Invoices using ABBYY Document AI SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python snippet demonstrates how to retrieve previously extracted fields for a specific invoice document using the ABBYY Document AI SDK. It initializes the DocumentAi client with an API key and then calls the `get_extracted_fields` method on the invoice model, asserting that the invoice data is not None. ```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.invoice.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.invoice is not None # Handle response print(res.invoice) ``` -------------------------------- ### Get Certificate Of Origin Extracted Fields using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python snippet retrieves the extracted fields for a specific certificate of origin document using the ABBYY Document AI SDK. It initializes the client with an API key and calls the `get_extracted_fields` method on the `certificate_of_origin` model, asserting the response and printing the extracted 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.certificate_of_origin.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.certificate_of_origin is not None # Handle response print(res.certificate_of_origin) ``` -------------------------------- ### Get Bill Of Lading Extracted Fields using ABBYY Document AI Python SDK Source: https://github.com/sarvottam-bhagat/abbyy-documentation/blob/main/api documentation.md This Python snippet retrieves the extracted fields for a specific bill of lading document using the ABBYY Document AI SDK. It initializes the client with an API key and calls the `get_extracted_fields` method on the `bill_of_lading` model, asserting the response and printing the extracted 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.bill_of_lading.get_extracted_fields(document_id="wh23anb5xjf0ntw5taase5qz") assert res.bill_of_lading is not None # Handle response print(res.bill_of_lading) ```