Skip to content

Commit 1e97aab

Browse files
committed
♻️ simplify default endpoint creation
1 parent fd1172c commit 1e97aab

File tree

16 files changed

+44
-51
lines changed

16 files changed

+44
-51
lines changed

mindee/client.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ def __init__(self, api_key: str = "", raise_on_error: bool = True):
194194
def _init_default_endpoints(self) -> None:
195195
self._doc_configs = {
196196
(OTS_OWNER, InvoiceV3.__name__): DocumentConfig(
197-
document_type="invoice_v3",
198197
document_class=InvoiceV3,
199198
endpoints=[
200199
StandardEndpoint(
@@ -203,7 +202,6 @@ def _init_default_endpoints(self) -> None:
203202
],
204203
),
205204
(OTS_OWNER, InvoiceV4.__name__): DocumentConfig(
206-
document_type="invoice_v4",
207205
document_class=InvoiceV4,
208206
endpoints=[
209207
StandardEndpoint(
@@ -212,7 +210,6 @@ def _init_default_endpoints(self) -> None:
212210
],
213211
),
214212
(OTS_OWNER, ReceiptV3.__name__): DocumentConfig(
215-
document_type="receipt_v3",
216213
document_class=ReceiptV3,
217214
endpoints=[
218215
StandardEndpoint(
@@ -221,7 +218,6 @@ def _init_default_endpoints(self) -> None:
221218
],
222219
),
223220
(OTS_OWNER, ReceiptV4.__name__): DocumentConfig(
224-
document_type="receipt_v4",
225221
document_class=ReceiptV4,
226222
endpoints=[
227223
StandardEndpoint(
@@ -230,7 +226,6 @@ def _init_default_endpoints(self) -> None:
230226
],
231227
),
232228
(OTS_OWNER, FinancialV1.__name__): DocumentConfig(
233-
document_type="financial_doc",
234229
document_class=FinancialV1,
235230
endpoints=[
236231
StandardEndpoint(
@@ -242,7 +237,6 @@ def _init_default_endpoints(self) -> None:
242237
],
243238
),
244239
(OTS_OWNER, FinancialDocumentV1.__name__): DocumentConfig(
245-
document_type="financial_document",
246240
document_class=FinancialDocumentV1,
247241
endpoints=[
248242
StandardEndpoint(
@@ -251,7 +245,6 @@ def _init_default_endpoints(self) -> None:
251245
],
252246
),
253247
(OTS_OWNER, PassportV1.__name__): DocumentConfig(
254-
document_type="passport_v1",
255248
document_class=PassportV1,
256249
endpoints=[
257250
StandardEndpoint(
@@ -260,7 +253,6 @@ def _init_default_endpoints(self) -> None:
260253
],
261254
),
262255
(OTS_OWNER, us.BankCheckV1.__name__): DocumentConfig(
263-
document_type="bank_check_v1",
264256
document_class=us.BankCheckV1,
265257
endpoints=[
266258
StandardEndpoint(
@@ -269,7 +261,6 @@ def _init_default_endpoints(self) -> None:
269261
],
270262
),
271263
(OTS_OWNER, fr.CarteGriseV1.__name__): DocumentConfig(
272-
document_type="carte_grise_v1",
273264
document_class=fr.CarteGriseV1,
274265
endpoints=[
275266
StandardEndpoint(
@@ -278,7 +269,6 @@ def _init_default_endpoints(self) -> None:
278269
],
279270
),
280271
(OTS_OWNER, ProofOfAddressV1.__name__): DocumentConfig(
281-
document_type="proof_of_address_v1",
282272
document_class=ProofOfAddressV1,
283273
endpoints=[
284274
StandardEndpoint(
@@ -287,7 +277,6 @@ def _init_default_endpoints(self) -> None:
287277
],
288278
),
289279
(OTS_OWNER, CropperV1.__name__): DocumentConfig(
290-
document_type="cropper_v1",
291280
document_class=CropperV1,
292281
endpoints=[
293282
StandardEndpoint(

mindee/documents/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def clean_out_string(out_string: str) -> str:
2828

2929

3030
class Document:
31-
type: str
31+
type: Optional[str]
3232
"""Document type"""
3333
checklist: dict
3434
"""Validation checks for the document"""
@@ -47,7 +47,7 @@ class Document:
4747
def __init__(
4848
self,
4949
input_source: InputSource,
50-
document_type: str,
50+
document_type: Optional[str],
5151
api_prediction: TypeApiPrediction,
5252
page_n: Optional[int] = None,
5353
):

mindee/documents/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, List, Tuple, Type
1+
from typing import Dict, List, Optional, Tuple, Type
22

33
from mindee.documents.base import Document
44
from mindee.endpoints import API_KEY_ENV_NAME, Endpoint
@@ -7,15 +7,15 @@
77

88

99
class DocumentConfig:
10-
document_type: str
10+
document_type: Optional[str]
1111
endpoints: List[Endpoint]
1212
document_class: _docT
1313

1414
def __init__(
1515
self,
16-
document_type: str,
1716
document_class: _docT,
1817
endpoints: List[Endpoint],
18+
document_type: Optional[str] = None,
1919
):
2020
self.document_type = document_type
2121
self.document_class = document_class
@@ -27,7 +27,7 @@ def check_api_keys(self) -> None:
2727
if not endpoint.api_key:
2828
raise RuntimeError(
2929
(
30-
f"Missing API key for '{self.document_type}',"
30+
f"Missing API key for '{endpoint.url_name} v{endpoint.version}',"
3131
"check your Client configuration.\n"
3232
"You can set this using the "
3333
f"'{API_KEY_ENV_NAME}' environment variable."

mindee/documents/cropper/cropper_v1.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def __init__(
1313
api_prediction: TypeApiPrediction,
1414
input_source=None,
1515
page_n: Optional[int] = None,
16-
document_type="cropper",
1716
):
1817
"""
1918
Custom document object.
@@ -25,7 +24,7 @@ def __init__(
2524
"""
2625
super().__init__(
2726
input_source=input_source,
28-
document_type=document_type,
27+
document_type="cropper",
2928
api_prediction=api_prediction,
3029
page_n=page_n,
3130
)

mindee/documents/financial/financial_document_v1.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def __init__(
6262
api_prediction=None,
6363
input_source=None,
6464
page_n: Optional[int] = None,
65-
document_type="financial_doc",
6665
):
6766
"""
6867
Union of `Invoice` and `Receipt`.
@@ -76,7 +75,7 @@ def __init__(
7675

7776
super().__init__(
7877
input_source=input_source,
79-
document_type=document_type,
78+
document_type="financial_doc",
8079
api_prediction=api_prediction,
8180
page_n=page_n,
8281
)

mindee/documents/financial/financial_v1.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def __init__(
5353
api_prediction=None,
5454
input_source=None,
5555
page_n: Optional[int] = None,
56-
document_type="financial_doc",
5756
):
5857
"""
5958
Union of `Invoice` and `Receipt`.
@@ -69,7 +68,7 @@ def __init__(
6968

7069
super().__init__(
7170
input_source=input_source,
72-
document_type=document_type,
71+
document_type="financial_doc",
7372
api_prediction=api_prediction,
7473
page_n=page_n,
7574
)

mindee/documents/fr/carte_grise/carte_grise_v1.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def __init__(
9494
api_prediction=None,
9595
input_source=None,
9696
page_n: Optional[int] = None,
97-
document_type="carte_grise",
9897
):
9998
"""
10099
Bank check document.
@@ -105,7 +104,7 @@ def __init__(
105104
"""
106105
super().__init__(
107106
input_source=input_source,
108-
document_type=document_type,
107+
document_type="carte_grise",
109108
api_prediction=api_prediction,
110109
page_n=page_n,
111110
)

mindee/documents/fr/carte_vitale/carte_vitale_v1.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def __init__(
2222
api_prediction=None,
2323
input_source=None,
2424
page_n: Optional[int] = None,
25-
document_type="carte_vitale",
2625
):
2726
"""
2827
document.
@@ -33,7 +32,7 @@ def __init__(
3332
"""
3433
super().__init__(
3534
input_source=input_source,
36-
document_type=document_type,
35+
document_type="carte_vitale",
3736
api_prediction=api_prediction,
3837
page_n=page_n,
3938
)

mindee/documents/invoice/invoice_v3.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def __init__(
4848
api_prediction=None,
4949
input_source=None,
5050
page_n: Optional[int] = None,
51-
document_type="invoice",
5251
):
5352
"""
5453
Invoice document.
@@ -59,7 +58,7 @@ def __init__(
5958
"""
6059
super().__init__(
6160
input_source=input_source,
62-
document_type=document_type,
61+
document_type="invoice",
6362
api_prediction=api_prediction,
6463
page_n=page_n,
6564
)

mindee/documents/invoice/invoice_v4.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def __init__(
5353
api_prediction=None,
5454
input_source=None,
5555
page_n: Optional[int] = None,
56-
document_type="invoice",
5756
):
5857
"""
5958
Invoice document.
@@ -64,7 +63,7 @@ def __init__(
6463
"""
6564
super().__init__(
6665
input_source=input_source,
67-
document_type=document_type,
66+
document_type="invoice",
6867
api_prediction=api_prediction,
6968
page_n=page_n,
7069
)

0 commit comments

Comments
 (0)