Skip to content

Commit 841ee1c

Browse files
♻️ update regression test sample + add quick accessor for LocalResponse (#300)
1 parent 2e0fe16 commit 841ee1c

File tree

7 files changed

+71
-16
lines changed

7 files changed

+71
-16
lines changed

.github/workflows/_test-integrations.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ jobs:
5656
with:
5757
status: ${{ job.status }}
5858
notify_when: "failure"
59-
notification_title: "Integration test '{workflow}' is failing"
59+
notification_title: "[Python] Integration test '{workflow}' is failing"
6060
env:
6161
SLACK_WEBHOOK_URL: ${{ secrets.PRODUCTION_ISSUES_SLACK_HOOK_URL }}

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,68 @@ for field_name, field_values in result.document.fields.items():
106106
print(field_name, "=", field_values)
107107
```
108108

109+
### Enqueue and Parse a Webhook Response
110+
This is an optional way of handling asynchronous APIs.
111+
112+
```python
113+
114+
```
115+
109116
### Additional Options
110117
Options to pass when sending a file.
118+
```python
119+
from mindee import Client, product
120+
from mindee.client import LocalResponse
121+
122+
# Init a new client
123+
mindee_client = Client()
124+
125+
# Load a file from disk
126+
input_source = mindee_client.source_from_path("/path/to/the/file.ext")
127+
128+
# Parse the file
129+
130+
enqueue_response = mindee_client.enqueue(
131+
product.InternationalIdV2,
132+
input_source,
133+
)
134+
135+
# You can keep track of the job's ID for traceability concerns.
136+
job_id = enqueue_response.job.id
137+
138+
139+
# Load the JSON string sent by the Mindee webhook POST callback.
140+
# Reading the callback data will vary greatly depending on your HTTP server.
141+
# This is therefore beyond the scope of this example.
142+
143+
local_response = LocalResponse(request.body())
144+
145+
# You can also load the json from a local path.
146+
# local_response = LocalResponse("path/to/my/file.ext")
147+
148+
# Optional: verify the HMAC signature
149+
if not local_response.is_valid_hmac_signature(my_secret_key, "some signature"):
150+
raise Error("Invalid HMAC signature!")
151+
152+
# Deserialize the response
153+
154+
result = mindee_client.load_prediction(
155+
product.InternationalIdV2,
156+
local_response
157+
)
158+
159+
# Print a full summary of the parsed data in RST format
160+
print(result.document)
161+
```
162+
111163

112164
#### Page Options
113165
Allows sending only certain pages in a PDF.
114166

115167
In this example we only send the first, penultimate and last pages:
116168

117169
```python
118-
from mindee import Client, product, PageOptions
170+
from mindee import product, PageOptions
119171

120172
result = mindee_client.parse(
121173
product.InvoiceV4,

docs/extras/guide/financial_document_v1.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ print(result.document)
5858
########
5959
Document
6060
########
61-
:Mindee ID: b26161ce-35d0-4984-b1ff-886645e160e6
61+
:Mindee ID: f469a24d-3875-4a83-ad43-e0d5aa9da604
6262
:Filename: default_sample.jpg
6363
6464
Inference
@@ -75,8 +75,8 @@ Prediction
7575
:Document Number: INT-001
7676
:Reference Numbers: 2412/2019
7777
:Purchase Date: 2019-11-02
78-
:Due Date: 2019-02-26
79-
:Payment Date: 2019-02-26
78+
:Due Date: 2019-11-17
79+
:Payment Date: 2019-11-17
8080
:Total Net: 195.00
8181
:Total Amount: 204.75
8282
:Taxes:
@@ -127,8 +127,8 @@ Page 0
127127
:Document Number: INT-001
128128
:Reference Numbers: 2412/2019
129129
:Purchase Date: 2019-11-02
130-
:Due Date: 2019-02-26
131-
:Payment Date: 2019-02-26
130+
:Due Date: 2019-11-17
131+
:Payment Date: 2019-11-17
132132
:Total Net: 195.00
133133
:Total Amount: 204.75
134134
:Taxes:

docs/extras/guide/invoices_v4.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ print(result.document)
5858
########
5959
Document
6060
########
61-
:Mindee ID: a67b70ea-4b1e-4eac-ae75-dda47a7064ae
61+
:Mindee ID: 86b1833f-138b-4a01-8387-860204b0e631
6262
:Filename: default_sample.jpg
6363
6464
Inference
@@ -73,8 +73,8 @@ Prediction
7373
:Purchase Order Number: AD29094
7474
:Reference Numbers: AD29094
7575
:Purchase Date: 2018-09-25
76-
:Due Date: 2011-12-01
77-
:Payment Date: 2011-12-01
76+
:Due Date:
77+
:Payment Date:
7878
:Total Net: 2145.00
7979
:Total Amount: 2608.20
8080
:Total Tax: 193.20
@@ -119,8 +119,8 @@ Page 0
119119
:Purchase Order Number: AD29094
120120
:Reference Numbers: AD29094
121121
:Purchase Date: 2018-09-25
122-
:Due Date: 2011-12-01
123-
:Payment Date: 2011-12-01
122+
:Due Date:
123+
:Payment Date:
124124
:Total Net: 2145.00
125125
:Total Amount: 2608.20
126126
:Total Tax: 193.20

mindee/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from mindee import product
2-
from mindee.client import Client, PageOptions
2+
from mindee.client import Client
3+
from mindee.input.local_response import LocalResponse
4+
from mindee.input.page_options import PageOptions
35
from mindee.parsing.common.api_response import ApiResponse
4-
from mindee.parsing.common.async_predict_response import AsyncPredictResponse, Job
6+
from mindee.parsing.common.async_predict_response import AsyncPredictResponse
57
from mindee.parsing.common.feedback_response import FeedbackResponse
8+
from mindee.parsing.common.job import Job
69
from mindee.parsing.common.predict_response import PredictResponse
710
from mindee.parsing.common.workflow_response import WorkflowResponse

mindee/product/ind/indian_passport/indian_passport_v1_document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class IndianPassportV1Document(Prediction):
12-
"""Passport - India API version 1.1 document data."""
12+
"""Passport - India API version 1.2 document data."""
1313

1414
address1: StringField
1515
"""The first line of the address of the passport holder."""

0 commit comments

Comments
 (0)