From 13ced25bbdc4c4ef0d363116061ed23047c4ab7f Mon Sep 17 00:00:00 2001 From: sebastianMindee Date: Mon, 27 Jan 2025 18:16:01 +0100 Subject: [PATCH 1/6] :recycle: update regression test sample + add quick accessor for LocalResponse --- .github/workflows/_test-integrations.yml | 2 +- README.md | 51 ++++++++++++++++++- docs/extras/guide/driver_license_v1.md | 33 +----------- mindee/__init__.py | 7 ++- .../indian_passport_v1_document.py | 2 +- tests/data | 2 +- 6 files changed, 59 insertions(+), 38 deletions(-) diff --git a/.github/workflows/_test-integrations.yml b/.github/workflows/_test-integrations.yml index 8acca249..ddc93b11 100644 --- a/.github/workflows/_test-integrations.yml +++ b/.github/workflows/_test-integrations.yml @@ -56,6 +56,6 @@ jobs: with: status: ${{ job.status }} notify_when: "failure" - notification_title: "Integration test '{workflow}' is failing" + notification_title: "[Python] Integration test '{workflow}' is failing" env: SLACK_WEBHOOK_URL: ${{ secrets.PRODUCTION_ISSUES_SLACK_HOOK_URL }} \ No newline at end of file diff --git a/README.md b/README.md index ac4b2fea..ec0e3151 100644 --- a/README.md +++ b/README.md @@ -106,8 +106,57 @@ for field_name, field_values in result.document.fields.items(): print(field_name, "=", field_values) ``` +### Enqueue and Parse a Webhook Response +This is an optional way of handling asynchronous APIs. + +```python + +``` + ### Additional Options Options to pass when sending a file. +```python +from mindee import Client, product +from mindee.client import LocalResponse + +# Init a new client +mindee_client = Client() + +# Load a file from disk +input_source = mindee_client.source_from_path("/path/to/the/file.ext") + +# Parse the file + +enqueue_response = mindee_client.enqueue( + product.InternationalIdV2, + input_source, +) + +# You can keep track of the job's ID for traceability concerns. +job_id = enqueue_response.job.id + + +# Load the JSON string sent by the Mindee webhook POST callback. +# Reading the callback data will vary greatly depending on your HTTP server. +# This is therefore beyond the scope of this example. + +local_response = LocalResponse(request.body.string) + +# Optional: verify the HMAC signature +if not local_response.is_valid_hmac_signature(my_secret_key, "some signature"): + raise Error("Invalid HMAC signature!") + +# Deserialize the response + +result = mindee_client.load_prediction( + product.InternationalIdV2, + local_response +) + +# Print a full summary of the parsed data in RST format +print(result.document) +``` + #### Page Options Allows sending only certain pages in a PDF. @@ -115,7 +164,7 @@ Allows sending only certain pages in a PDF. In this example we only send the first, penultimate and last pages: ```python -from mindee import Client, product, PageOptions +from mindee import product, PageOptions result = mindee_client.parse( product.InvoiceV4, diff --git a/docs/extras/guide/driver_license_v1.md b/docs/extras/guide/driver_license_v1.md index 321e776b..6553f039 100644 --- a/docs/extras/guide/driver_license_v1.md +++ b/docs/extras/guide/driver_license_v1.md @@ -6,7 +6,7 @@ parentDoc: 609808f773b0b90051d839de --- The Python OCR SDK supports the [Driver License API](https://platform.mindee.com/mindee/driver_license). -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg) can be used for testing purposes. ![Driver License sample](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg?raw=true) # Quick-Start @@ -29,37 +29,6 @@ result: AsyncPredictResponse = mindee_client.enqueue_and_parse( print(result.document) ``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: fbdeae38-ada3-43ac-aa58-e01a3d47e474 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/driver_license v1.0 -:Rotation applied: Yes - -Prediction -========== -:Country Code: USA -:State: AZ -:ID: D12345678 -:Category: D -:Last Name: Sample -:First Name: Jelani -:Date of Birth: 1957-02-01 -:Place of Birth: -:Expiry Date: 2018-02-01 -:Issued Date: 2013-01-10 -:Issuing Authority: -:MRZ: -:DD Number: DD1234567890123456 -``` - # Field Types ## Standard Fields These fields are generic and used in several products. diff --git a/mindee/__init__.py b/mindee/__init__.py index 27647254..9066d36a 100644 --- a/mindee/__init__.py +++ b/mindee/__init__.py @@ -1,7 +1,10 @@ from mindee import product -from mindee.client import Client, PageOptions +from mindee.client import Client +from mindee.input.local_response import LocalResponse +from mindee.input.page_options import PageOptions from mindee.parsing.common.api_response import ApiResponse -from mindee.parsing.common.async_predict_response import AsyncPredictResponse, Job +from mindee.parsing.common.async_predict_response import AsyncPredictResponse from mindee.parsing.common.feedback_response import FeedbackResponse +from mindee.parsing.common.job import Job from mindee.parsing.common.predict_response import PredictResponse from mindee.parsing.common.workflow_response import WorkflowResponse diff --git a/mindee/product/ind/indian_passport/indian_passport_v1_document.py b/mindee/product/ind/indian_passport/indian_passport_v1_document.py index 9eaeedbd..2dccd7cc 100644 --- a/mindee/product/ind/indian_passport/indian_passport_v1_document.py +++ b/mindee/product/ind/indian_passport/indian_passport_v1_document.py @@ -9,7 +9,7 @@ class IndianPassportV1Document(Prediction): - """Passport - India API version 1.1 document data.""" + """Passport - India API version 1.2 document data.""" address1: StringField """The first line of the address of the passport holder.""" diff --git a/tests/data b/tests/data index 86f3c9de..64a81052 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 86f3c9de490a0f29e56cacee0cd63dbebfa86dc8 +Subproject commit 64a810523d8b06ffb1682934f53f7f2eca2429d7 From a3e0754665bbe910ddca088faa7d7c31f8d0eb9e Mon Sep 17 00:00:00 2001 From: sebastianMindee Date: Tue, 28 Jan 2025 10:02:33 +0100 Subject: [PATCH 2/6] fix readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ec0e3151..968f3a23 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,10 @@ job_id = enqueue_response.job.id # Reading the callback data will vary greatly depending on your HTTP server. # This is therefore beyond the scope of this example. -local_response = LocalResponse(request.body.string) +local_response = LocalResponse(request.body()) + +# You can also use a File object as the input. +# local_response = mindee_client.source_from_path("path/to/my/file.ext); # Optional: verify the HMAC signature if not local_response.is_valid_hmac_signature(my_secret_key, "some signature"): From afe66a73a2912f3e449e52e8f03336b3fc2bcb07 Mon Sep 17 00:00:00 2001 From: sebastianMindee Date: Tue, 28 Jan 2025 10:04:17 +0100 Subject: [PATCH 3/6] fix typos --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 968f3a23..928a2100 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ job_id = enqueue_response.job.id local_response = LocalResponse(request.body()) # You can also use a File object as the input. -# local_response = mindee_client.source_from_path("path/to/my/file.ext); +# local_response = LocalResponse("path/to/my/file.ext") # Optional: verify the HMAC signature if not local_response.is_valid_hmac_signature(my_secret_key, "some signature"): From fcd611cd5810eeb5eb5395b0803e354118f5eb91 Mon Sep 17 00:00:00 2001 From: sebastianMindee Date: Tue, 28 Jan 2025 10:45:52 +0100 Subject: [PATCH 4/6] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 928a2100..bb76c13a 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ job_id = enqueue_response.job.id local_response = LocalResponse(request.body()) -# You can also use a File object as the input. +# You can also load the json from a local path. # local_response = LocalResponse("path/to/my/file.ext") # Optional: verify the HMAC signature From 006fe3ef531d6afc1f422451271f7ba68b68b26f Mon Sep 17 00:00:00 2001 From: sebastianMindee Date: Tue, 28 Jan 2025 10:50:46 +0100 Subject: [PATCH 5/6] restore driver license example --- docs/extras/guide/driver_license_v1.md | 33 +++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/docs/extras/guide/driver_license_v1.md b/docs/extras/guide/driver_license_v1.md index 6553f039..321e776b 100644 --- a/docs/extras/guide/driver_license_v1.md +++ b/docs/extras/guide/driver_license_v1.md @@ -6,7 +6,7 @@ parentDoc: 609808f773b0b90051d839de --- The Python OCR SDK supports the [Driver License API](https://platform.mindee.com/mindee/driver_license). -The [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg) can be used for testing purposes. +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. ![Driver License sample](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg?raw=true) # Quick-Start @@ -29,6 +29,37 @@ result: AsyncPredictResponse = mindee_client.enqueue_and_parse( print(result.document) ``` + +**Output (RST):** +```rst +######## +Document +######## +:Mindee ID: fbdeae38-ada3-43ac-aa58-e01a3d47e474 +:Filename: default_sample.jpg + +Inference +######### +:Product: mindee/driver_license v1.0 +:Rotation applied: Yes + +Prediction +========== +:Country Code: USA +:State: AZ +:ID: D12345678 +:Category: D +:Last Name: Sample +:First Name: Jelani +:Date of Birth: 1957-02-01 +:Place of Birth: +:Expiry Date: 2018-02-01 +:Issued Date: 2013-01-10 +:Issuing Authority: +:MRZ: +:DD Number: DD1234567890123456 +``` + # Field Types ## Standard Fields These fields are generic and used in several products. From 6d457ace0d0287c3889a57b3b0785864fb894432 Mon Sep 17 00:00:00 2001 From: sebastianMindee Date: Tue, 28 Jan 2025 10:51:36 +0100 Subject: [PATCH 6/6] update test samples --- docs/extras/guide/financial_document_v1.md | 10 +++++----- docs/extras/guide/invoices_v4.md | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/extras/guide/financial_document_v1.md b/docs/extras/guide/financial_document_v1.md index 284ae04c..28f623d5 100644 --- a/docs/extras/guide/financial_document_v1.md +++ b/docs/extras/guide/financial_document_v1.md @@ -58,7 +58,7 @@ print(result.document) ######## Document ######## -:Mindee ID: b26161ce-35d0-4984-b1ff-886645e160e6 +:Mindee ID: f469a24d-3875-4a83-ad43-e0d5aa9da604 :Filename: default_sample.jpg Inference @@ -75,8 +75,8 @@ Prediction :Document Number: INT-001 :Reference Numbers: 2412/2019 :Purchase Date: 2019-11-02 -:Due Date: 2019-02-26 -:Payment Date: 2019-02-26 +:Due Date: 2019-11-17 +:Payment Date: 2019-11-17 :Total Net: 195.00 :Total Amount: 204.75 :Taxes: @@ -127,8 +127,8 @@ Page 0 :Document Number: INT-001 :Reference Numbers: 2412/2019 :Purchase Date: 2019-11-02 -:Due Date: 2019-02-26 -:Payment Date: 2019-02-26 +:Due Date: 2019-11-17 +:Payment Date: 2019-11-17 :Total Net: 195.00 :Total Amount: 204.75 :Taxes: diff --git a/docs/extras/guide/invoices_v4.md b/docs/extras/guide/invoices_v4.md index b54546a2..5760c433 100644 --- a/docs/extras/guide/invoices_v4.md +++ b/docs/extras/guide/invoices_v4.md @@ -58,7 +58,7 @@ print(result.document) ######## Document ######## -:Mindee ID: a67b70ea-4b1e-4eac-ae75-dda47a7064ae +:Mindee ID: 86b1833f-138b-4a01-8387-860204b0e631 :Filename: default_sample.jpg Inference @@ -73,8 +73,8 @@ Prediction :Purchase Order Number: AD29094 :Reference Numbers: AD29094 :Purchase Date: 2018-09-25 -:Due Date: 2011-12-01 -:Payment Date: 2011-12-01 +:Due Date: +:Payment Date: :Total Net: 2145.00 :Total Amount: 2608.20 :Total Tax: 193.20 @@ -119,8 +119,8 @@ Page 0 :Purchase Order Number: AD29094 :Reference Numbers: AD29094 :Purchase Date: 2018-09-25 -:Due Date: 2011-12-01 -:Payment Date: 2011-12-01 +:Due Date: +:Payment Date: :Total Net: 2145.00 :Total Amount: 2608.20 :Total Tax: 193.20