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..bb76c13a 100644 --- a/README.md +++ b/README.md @@ -106,8 +106,60 @@ 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()) + +# You can also load the json from a local path. +# 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"): + 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 +167,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/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 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