structocr 1.6.0__tar.gz → 1.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: structocr
3
- Version: 1.6.0
3
+ Version: 1.7.0
4
4
  Summary: Official Python SDK for StructOCR Base64 document APIs, including images, PDFs, and account balance.
5
5
  Home-page: https://structocr.com
6
6
  Author: StructOCR Team
@@ -82,6 +82,7 @@ result = client.scan_passport(content)
82
82
  scan_passport(file)
83
83
  scan_national_id(file)
84
84
  scan_driver_license(file)
85
+ scan_driver_license_pdf417(file)
85
86
  scan_invoice(file)
86
87
  scan_receipt(file)
87
88
  scan_vin(file)
@@ -94,18 +95,27 @@ scan_weighbridge_ticket(file)
94
95
  get_account_balance()
95
96
  ```
96
97
 
97
- All document methods accept a local path or bytes. Supported decoded formats are JPG, PNG, WebP, and PDF, up to 4.5MB.
98
+ All document methods accept a local path or bytes, up to 4.5MB. Most methods support JPG, PNG, WebP, and PDF. `scan_driver_license_pdf417` accepts JPG, PNG, and WebP only.
98
99
 
99
- Receipt v2 provides a richer response. Enhanced accuracy requires v2 and costs 2 credits instead of the standard 1 credit:
100
+ The Receipt endpoint returns v2 by default. Enhanced accuracy costs 2 credits instead of the standard 1 credit and is enabled with the `accuracy` parameter:
100
101
 
101
102
  ```python
102
103
  receipt = client.scan_receipt(
103
104
  "./receipt.jpg",
104
- response_version=2,
105
105
  accuracy="enhanced",
106
106
  )
107
107
  ```
108
108
 
109
+ `response_version=2` remains accepted for compatibility but is not required. Receipt v1 is retired.
110
+
111
+ US driver license PDF417 example:
112
+
113
+ ```python
114
+ result = client.scan_driver_license_pdf417("./license-back.jpg")
115
+ if result.get("success"):
116
+ print(result["data"]["document_number"])
117
+ ```
118
+
109
119
  Weighbridge ticket example:
110
120
 
111
121
  ```python
@@ -49,6 +49,7 @@ result = client.scan_passport(content)
49
49
  scan_passport(file)
50
50
  scan_national_id(file)
51
51
  scan_driver_license(file)
52
+ scan_driver_license_pdf417(file)
52
53
  scan_invoice(file)
53
54
  scan_receipt(file)
54
55
  scan_vin(file)
@@ -61,18 +62,27 @@ scan_weighbridge_ticket(file)
61
62
  get_account_balance()
62
63
  ```
63
64
 
64
- All document methods accept a local path or bytes. Supported decoded formats are JPG, PNG, WebP, and PDF, up to 4.5MB.
65
+ All document methods accept a local path or bytes, up to 4.5MB. Most methods support JPG, PNG, WebP, and PDF. `scan_driver_license_pdf417` accepts JPG, PNG, and WebP only.
65
66
 
66
- Receipt v2 provides a richer response. Enhanced accuracy requires v2 and costs 2 credits instead of the standard 1 credit:
67
+ The Receipt endpoint returns v2 by default. Enhanced accuracy costs 2 credits instead of the standard 1 credit and is enabled with the `accuracy` parameter:
67
68
 
68
69
  ```python
69
70
  receipt = client.scan_receipt(
70
71
  "./receipt.jpg",
71
- response_version=2,
72
72
  accuracy="enhanced",
73
73
  )
74
74
  ```
75
75
 
76
+ `response_version=2` remains accepted for compatibility but is not required. Receipt v1 is retired.
77
+
78
+ US driver license PDF417 example:
79
+
80
+ ```python
81
+ result = client.scan_driver_license_pdf417("./license-back.jpg")
82
+ if result.get("success"):
83
+ print(result["data"]["document_number"])
84
+ ```
85
+
76
86
  Weighbridge ticket example:
77
87
 
78
88
  ```python
@@ -11,6 +11,7 @@ from .version import __version__
11
11
  FileInput = Union[str, os.PathLike, bytes, bytearray, memoryview]
12
12
  MAX_FILE_SIZE = int(4.5 * 1024 * 1024)
13
13
  SUPPORTED_FORMATS = "JPG, PNG, WebP, and PDF"
14
+ IMAGE_ONLY_FORMATS = "JPG, PNG, and WebP"
14
15
  RETRYABLE_STATUS_CODES = {429, 502, 503, 504}
15
16
 
16
17
 
@@ -56,7 +57,7 @@ class StructOCR:
56
57
  })
57
58
 
58
59
  @staticmethod
59
- def _read_file(file: FileInput) -> bytes:
60
+ def _read_file(file: FileInput, *, allow_pdf: bool = True) -> bytes:
60
61
  if isinstance(file, (bytes, bytearray, memoryview)):
61
62
  content = bytes(file)
62
63
  else:
@@ -69,8 +70,11 @@ class StructOCR:
69
70
  raise ValueError("File is empty")
70
71
  if len(content) > MAX_FILE_SIZE:
71
72
  raise ValueError("File exceeds the maximum allowed size of 4.5MB")
72
- if StructOCR._detect_mime(content) is None:
73
+ mime_type = StructOCR._detect_mime(content)
74
+ if mime_type is None:
73
75
  raise ValueError(f"Unsupported file format. Supported formats: {SUPPORTED_FORMATS}")
76
+ if not allow_pdf and mime_type == "application/pdf":
77
+ raise ValueError(f"Unsupported file format. Supported formats: {IMAGE_ONLY_FORMATS}")
74
78
  return content
75
79
 
76
80
  @staticmethod
@@ -132,9 +136,11 @@ class StructOCR:
132
136
  endpoint: str,
133
137
  file: FileInput,
134
138
  params: Optional[Dict[str, Any]] = None,
139
+ *,
140
+ allow_pdf: bool = True,
135
141
  ) -> Dict[str, Any]:
136
142
  """Read a local file or bytes and send it as Base64 JSON in ``img``."""
137
- content = self._read_file(file)
143
+ content = self._read_file(file, allow_pdf=allow_pdf)
138
144
  payload = {"img": base64.b64encode(content).decode("ascii")}
139
145
 
140
146
  try:
@@ -182,6 +188,9 @@ class StructOCR:
182
188
  def scan_driver_license(self, file: FileInput) -> Dict[str, Any]:
183
189
  return self._post_image("driver-license", file)
184
190
 
191
+ def scan_driver_license_pdf417(self, file: FileInput) -> Dict[str, Any]:
192
+ return self._post_image("driver-license-pdf417", file, allow_pdf=False)
193
+
185
194
  def scan_invoice(self, file: FileInput) -> Dict[str, Any]:
186
195
  return self._post_image("invoice", file)
187
196
 
@@ -197,27 +206,30 @@ class StructOCR:
197
206
  def scan_receipt(
198
207
  self,
199
208
  file: FileInput,
200
- response_version: int = 1,
209
+ response_version: Optional[int] = None,
201
210
  accuracy: str = "standard",
202
211
  ) -> Dict[str, Any]:
203
- if response_version not in (1, 2):
204
- raise StructOCRError("response_version must be 1 or 2", code="INVALID_OPTIONS")
205
- if accuracy not in ("standard", "enhanced"):
212
+ if response_version not in (None, 2):
206
213
  raise StructOCRError(
207
- 'accuracy must be "standard" or "enhanced"',
214
+ "response_version must be 2 when provided; Receipt v1 is retired",
208
215
  code="INVALID_OPTIONS",
209
216
  )
210
- if accuracy == "enhanced" and response_version != 2:
217
+ if accuracy not in ("standard", "enhanced"):
211
218
  raise StructOCRError(
212
- "Enhanced accuracy requires response_version=2",
219
+ 'accuracy must be "standard" or "enhanced"',
213
220
  code="INVALID_OPTIONS",
214
221
  )
215
- if response_version == 1 and accuracy == "standard":
222
+ if accuracy == "standard" and response_version is None:
216
223
  return self._post_image("receipt", file)
224
+ params: Dict[str, Any] = {}
225
+ if response_version == 2:
226
+ params["response_version"] = 2
227
+ if accuracy == "enhanced":
228
+ params["accuracy"] = "enhanced"
217
229
  return self._post_image(
218
230
  "receipt",
219
231
  file,
220
- params={"response_version": response_version, "accuracy": accuracy},
232
+ params=params,
221
233
  )
222
234
 
223
235
  def scan_license_plate(self, file: FileInput) -> Dict[str, Any]:
@@ -0,0 +1 @@
1
+ __version__ = "1.7.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: structocr
3
- Version: 1.6.0
3
+ Version: 1.7.0
4
4
  Summary: Official Python SDK for StructOCR Base64 document APIs, including images, PDFs, and account balance.
5
5
  Home-page: https://structocr.com
6
6
  Author: StructOCR Team
@@ -82,6 +82,7 @@ result = client.scan_passport(content)
82
82
  scan_passport(file)
83
83
  scan_national_id(file)
84
84
  scan_driver_license(file)
85
+ scan_driver_license_pdf417(file)
85
86
  scan_invoice(file)
86
87
  scan_receipt(file)
87
88
  scan_vin(file)
@@ -94,18 +95,27 @@ scan_weighbridge_ticket(file)
94
95
  get_account_balance()
95
96
  ```
96
97
 
97
- All document methods accept a local path or bytes. Supported decoded formats are JPG, PNG, WebP, and PDF, up to 4.5MB.
98
+ All document methods accept a local path or bytes, up to 4.5MB. Most methods support JPG, PNG, WebP, and PDF. `scan_driver_license_pdf417` accepts JPG, PNG, and WebP only.
98
99
 
99
- Receipt v2 provides a richer response. Enhanced accuracy requires v2 and costs 2 credits instead of the standard 1 credit:
100
+ The Receipt endpoint returns v2 by default. Enhanced accuracy costs 2 credits instead of the standard 1 credit and is enabled with the `accuracy` parameter:
100
101
 
101
102
  ```python
102
103
  receipt = client.scan_receipt(
103
104
  "./receipt.jpg",
104
- response_version=2,
105
105
  accuracy="enhanced",
106
106
  )
107
107
  ```
108
108
 
109
+ `response_version=2` remains accepted for compatibility but is not required. Receipt v1 is retired.
110
+
111
+ US driver license PDF417 example:
112
+
113
+ ```python
114
+ result = client.scan_driver_license_pdf417("./license-back.jpg")
115
+ if result.get("success"):
116
+ print(result["data"]["document_number"])
117
+ ```
118
+
109
119
  Weighbridge ticket example:
110
120
 
111
121
  ```python
@@ -1 +0,0 @@
1
- __version__ = "1.6.0"
File without changes
File without changes
File without changes
File without changes
File without changes