Skip to content

Commit f4bf2d5

Browse files
ianardeeMindee
andauthored
✨ add support for us mail v3 (#294)
Co-authored-by: Mindee <opensource@mindee.com>
1 parent 30d2b9e commit f4bf2d5

File tree

17 files changed

+478
-19
lines changed

17 files changed

+478
-19
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from mindee import Client, product, AsyncPredictResponse
2+
3+
# Init a new client
4+
mindee_client = Client(api_key="my-api-key")
5+
6+
# Load a file from disk
7+
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
8+
9+
# Load a file from disk and enqueue it.
10+
result: AsyncPredictResponse = mindee_client.enqueue_and_parse(
11+
product.us.UsMailV3,
12+
input_doc,
13+
)
14+
15+
# Print a brief summary of the parsed data
16+
print(result.document)

docs/extras/guide/us_mail_v2.md renamed to docs/extras/guide/us_mail_v3.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
2121

2222
# Load a file from disk and enqueue it.
2323
result: AsyncPredictResponse = mindee_client.enqueue_and_parse(
24-
product.us.UsMailV2,
24+
product.us.UsMailV3,
2525
input_doc,
2626
)
2727

@@ -32,7 +32,20 @@ print(result.document)
3232

3333
**Output (RST):**
3434
```rst
35-
:Sender Name: zed
35+
########
36+
Document
37+
########
38+
:Mindee ID: f9c36f59-977d-4ddc-9f2d-31c294c456ac
39+
:Filename: default_sample.jpg
40+
41+
Inference
42+
#########
43+
:Product: mindee/us_mail v3.0
44+
:Rotation applied: Yes
45+
46+
Prediction
47+
==========
48+
:Sender Name: company zed
3649
:Sender Address:
3750
:City: Dallas
3851
:Complete Address: 54321 Elm Street, Dallas, Texas 54321
@@ -41,11 +54,12 @@ print(result.document)
4154
:Street: 54321 Elm Street
4255
:Recipient Names: Jane Doe
4356
:Recipient Addresses:
44-
+-----------------+-------------------------------------+-------------------+-------------+------------------------+-------+---------------------------+
45-
| City | Complete Address | Is Address Change | Postal Code | Private Mailbox Number | State | Street |
46-
+=================+=====================================+===================+=============+========================+=======+===========================+
47-
| Detroit | 1234 Market Street PMB 4321, Det... | | 12345 | 4321 | MI | 1234 Market Street |
48-
+-----------------+-------------------------------------+-------------------+-------------+------------------------+-------+---------------------------+
57+
+-----------------+-------------------------------------+-------------------+-------------+------------------------+-------+---------------------------+-----------------+
58+
| City | Complete Address | Is Address Change | Postal Code | Private Mailbox Number | State | Street | Unit |
59+
+=================+=====================================+===================+=============+========================+=======+===========================+=================+
60+
| Detroit | 1234 Market Street PMB 4321, Det... | False | 12345 | 4321 | MI | 1234 Market Street | |
61+
+-----------------+-------------------------------------+-------------------+-------------+------------------------+-------+---------------------------+-----------------+
62+
:Return to Sender: False
4963
```
5064

5165
# Field Types
@@ -77,7 +91,7 @@ Fields which are specific to this product; they are not used in any other produc
7791
### Recipient Addresses Field
7892
The addresses of the recipients.
7993

80-
A `UsMailV2RecipientAddress` implements the following attributes:
94+
A `UsMailV3RecipientAddress` implements the following attributes:
8195

8296
* **city** (`str`): The city of the recipient's address.
8397
* **complete** (`str`): The complete address of the recipient.
@@ -86,12 +100,13 @@ A `UsMailV2RecipientAddress` implements the following attributes:
86100
* **private_mailbox_number** (`str`): The private mailbox number of the recipient's address.
87101
* **state** (`str`): Second part of the ISO 3166-2 code, consisting of two letters indicating the US State.
88102
* **street** (`str`): The street of the recipient's address.
103+
* **unit** (`str`): The unit number of the recipient's address.
89104
Fields which are specific to this product; they are not used in any other product.
90105

91106
### Sender Address Field
92107
The address of the sender.
93108

94-
A `UsMailV2SenderAddress` implements the following attributes:
109+
A `UsMailV3SenderAddress` implements the following attributes:
95110

96111
* **city** (`str`): The city of the sender's address.
97112
* **complete** (`str`): The complete address of the sender.
@@ -100,10 +115,17 @@ A `UsMailV2SenderAddress` implements the following attributes:
100115
* **street** (`str`): The street of the sender's address.
101116

102117
# Attributes
103-
The following fields are extracted for US Mail V2:
118+
The following fields are extracted for US Mail V3:
119+
120+
## Return to Sender
121+
**is_return_to_sender** ([BooleanField](#booleanfield)): Whether the mailing is marked as return to sender.
122+
123+
```py
124+
print(result.document.inference.prediction.is_return_to_sender.value)
125+
```
104126

105127
## Recipient Addresses
106-
**recipient_addresses** (List[[UsMailV2RecipientAddress](#recipient-addresses-field)]): The addresses of the recipients.
128+
**recipient_addresses** (List[[UsMailV3RecipientAddress](#recipient-addresses-field)]): The addresses of the recipients.
107129

108130
```py
109131
for recipient_addresses_elem in result.document.inference.prediction.recipient_addresses:
@@ -119,7 +141,7 @@ for recipient_names_elem in result.document.inference.prediction.recipient_names
119141
```
120142

121143
## Sender Address
122-
**sender_address** ([UsMailV2SenderAddress](#sender-address-field)): The address of the sender.
144+
**sender_address** ([UsMailV3SenderAddress](#sender-address-field)): The address of the sender.
123145

124146
```py
125147
print(result.document.inference.prediction.sender_address.value)

docs/product/bill_of_lading_v1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bill of Lading V1
33

44
**Sample Code:**
55

6-
.. literalinclude:: /extras/code_samples/bill_of_lading_v1.txt
6+
.. literalinclude:: /extras/code_samples/bill_of_lading_v1_async.txt
77
:language: Python
88

99
.. autoclass:: mindee.product.bill_of_lading.bill_of_lading_v1.BillOfLadingV1

docs/product/ind/indian_passport_v1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Passport - India V1
33

44
**Sample Code:**
55

6-
.. literalinclude:: /extras/code_samples/ind_passport_v1.txt
6+
.. literalinclude:: /extras/code_samples/ind_passport_v1_async.txt
77
:language: Python
88

99
.. autoclass:: mindee.product.ind.indian_passport.indian_passport_v1.IndianPassportV1

docs/product/international_id_v2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ International ID V2
33

44
**Sample Code:**
55

6-
.. literalinclude:: /extras/code_samples/international_id_v2.txt
6+
.. literalinclude:: /extras/code_samples/international_id_v2_async.txt
77
:language: Python
88

99
.. autoclass:: mindee.product.international_id.international_id_v2.InternationalIdV2

docs/product/nutrition_facts_label_v1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Nutrition Facts Label V1
33

44
**Sample Code:**
55

6-
.. literalinclude:: /extras/code_samples/nutrition_facts_v1.txt
6+
.. literalinclude:: /extras/code_samples/nutrition_facts_v1_async.txt
77
:language: Python
88

99
.. autoclass:: mindee.product.nutrition_facts_label.nutrition_facts_label_v1.NutritionFactsLabelV1

docs/product/us/us_mail_v2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ US Mail V2
33

44
**Sample Code:**
55

6-
.. literalinclude:: /extras/code_samples/us_mail_v2.txt
6+
.. literalinclude:: /extras/code_samples/us_mail_v2_async.txt
77
:language: Python
88

99
.. autoclass:: mindee.product.us.us_mail.us_mail_v2.UsMailV2

docs/product/us/us_mail_v3.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
US Mail V3
2+
----------
3+
4+
**Sample Code:**
5+
6+
.. literalinclude:: /extras/code_samples/us_mail_v3_async.txt
7+
:language: Python
8+
9+
.. autoclass:: mindee.product.us.us_mail.us_mail_v3.UsMailV3
10+
:members:
11+
:inherited-members:
12+
13+
.. autoclass:: mindee.product.us.us_mail.us_mail_v3_document.UsMailV3Document
14+
:members:
15+
:inherited-members:
16+
17+
.. autoclass:: mindee.product.us.us_mail.us_mail_v3_sender_address.UsMailV3SenderAddress
18+
:members:
19+
:inherited-members:
20+
21+
.. autoclass:: mindee.product.us.us_mail.us_mail_v3_recipient_address.UsMailV3RecipientAddress
22+
:members:
23+
:inherited-members:

mindee/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class CommandConfig(Generic[TypeInference]):
167167
),
168168
"us-mail": CommandConfig(
169169
help="US Mail",
170-
doc_class=product.us.UsMailV2,
170+
doc_class=product.us.UsMailV3,
171171
is_sync=False,
172172
is_async=True,
173173
),

mindee/product/us/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
UsMailV2RecipientAddress,
2020
)
2121
from mindee.product.us.us_mail.us_mail_v2_sender_address import UsMailV2SenderAddress
22+
from mindee.product.us.us_mail.us_mail_v3 import UsMailV3
23+
from mindee.product.us.us_mail.us_mail_v3_document import UsMailV3Document
24+
from mindee.product.us.us_mail.us_mail_v3_recipient_address import (
25+
UsMailV3RecipientAddress,
26+
)
27+
from mindee.product.us.us_mail.us_mail_v3_sender_address import UsMailV3SenderAddress
2228
from mindee.product.us.w9.w9_v1 import W9V1
2329
from mindee.product.us.w9.w9_v1_document import W9V1Document
2430
from mindee.product.us.w9.w9_v1_page import W9V1Page

0 commit comments

Comments
 (0)