structocr 1.6.0__tar.gz → 1.7.1__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.
@@ -0,0 +1,214 @@
1
+ Metadata-Version: 2.4
2
+ Name: structocr
3
+ Version: 1.7.1
4
+ Summary: Passport, ID card, driver license, VIN, invoice and receipt OCR: turn images and PDFs into structured JSON. Official StructOCR SDK for Python.
5
+ Home-page: https://structocr.com
6
+ Author: StructOCR Team
7
+ Author-email: support@structocr.com
8
+ License: MIT
9
+ Project-URL: Homepage, https://structocr.com
10
+ Project-URL: Documentation, https://structocr.com/developers
11
+ Project-URL: Get a free API key, https://structocr.com/register?utm_source=pypi&utm_medium=project_urls&utm_campaign=sdk
12
+ Project-URL: Source, https://github.com/dracula911/structocr-python
13
+ Project-URL: Tracker, https://github.com/dracula911/structocr-python/issues
14
+ Keywords: ocr,passport ocr,mrz,id card ocr,driver license ocr,pdf417,vin ocr,invoice ocr,receipt ocr,kyc,document ai,structocr
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
19
+ Requires-Python: >=3.7
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: requests>=2.25.0
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: classifier
26
+ Dynamic: description
27
+ Dynamic: description-content-type
28
+ Dynamic: home-page
29
+ Dynamic: keywords
30
+ Dynamic: license
31
+ Dynamic: license-file
32
+ Dynamic: project-url
33
+ Dynamic: requires-dist
34
+ Dynamic: requires-python
35
+ Dynamic: summary
36
+
37
+ # StructOCR Python SDK
38
+
39
+ Official Python client for the [StructOCR API](https://structocr.com/developers?utm_source=pypi&utm_medium=readme&utm_campaign=sdk).
40
+
41
+ Send a photo or PDF of a passport, ID card, driver license, VIN, invoice, receipt or shipping container and get structured JSON back: one method call per document, no templates to train.
42
+
43
+ The SDK accepts a local JPG, PNG, WebP, or PDF path, plus in-memory `bytes`. It validates the decoded file locally, converts it to Base64, and sends JSON as `{"img": "..."}`. The REST API also supports multipart uploads; this SDK release keeps Base64 JSON as its default transport for backward compatibility.
44
+
45
+ ## Get a free API key
46
+
47
+ 1. [Create an account](https://structocr.com/register?utm_source=pypi&utm_medium=readme&utm_campaign=sdk). New accounts get **200 free credits**, enough for 100 passport or driver license scans, and no credit card is needed.
48
+ 2. Copy your key from **API Keys** in the dashboard.
49
+ 3. Optionally try any document type on a sample image in the [Playground](https://structocr.com/dashboard/playground?utm_source=pypi&utm_medium=readme&utm_campaign=sdk) before you write code.
50
+
51
+ Not ready to sign up? Try any document in your browser on a sample image or your own file, no account needed: use the **Try it** links in the table below.
52
+
53
+ After the free credits, packs start at $5 for 500 credits. There is no subscription and credits do not expire. See [pricing](https://structocr.com/pricing?utm_source=pypi&utm_medium=readme&utm_campaign=sdk).
54
+
55
+ ## Supported documents
56
+
57
+ | Document | Method | Credits per scan | Try it |
58
+ | --- | --- | --- | --- |
59
+ | Passport | `scan_passport` | 2 | [Try it](https://structocr.com/products/passport-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
60
+ | National ID card | `scan_national_id` | 2 | [Try it](https://structocr.com/products/national-id-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
61
+ | Driver license (front) | `scan_driver_license` | 2 | [Try it](https://structocr.com/products/driver-license-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
62
+ | US/Canada driver license PDF417 barcode | `scan_driver_license_pdf417` | 2 | [Try it](https://structocr.com/tools/driver-license-pdf417-scanner?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try) |
63
+ | Vehicle registration | `scan_vehicle_registration` | 2 | [Try it](https://structocr.com/products/vehicle-registration-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
64
+ | VIN | `scan_vin` | 1 | [Try it](https://structocr.com/products/vin-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
65
+ | License plate | `scan_license_plate` | 1 | [Try it](https://structocr.com/products/license-plate-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
66
+ | Invoice | `scan_invoice` | 3 | [Try it](https://structocr.com/products/invoice-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
67
+ | Receipt | `scan_receipt` | 1 | [Try it](https://structocr.com/products/receipt-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
68
+ | Shipping container (ISO 6346) | `scan_container` | 1 | [Try it](https://structocr.com/products/container-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
69
+ | Weighbridge ticket | `scan_weighbridge_ticket` | 2 | [Try it](https://structocr.com/products/weighbridge-ticket-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
70
+ | ATM cassette | `scan_atm_cassette` | 1 | |
71
+ | HIN (boat hull number) | `scan_hin` | 1 | [Try it](https://structocr.com/products/hin-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
72
+
73
+ The receipt endpoint's optional enhanced mode costs 2 credits. Only successful requests are charged.
74
+
75
+ ## Install
76
+
77
+ ```bash
78
+ pip install --upgrade structocr
79
+ ```
80
+
81
+ Python 3.7+ is required.
82
+
83
+ ## Quick start
84
+
85
+ ```bash
86
+ export STRUCTOCR_API_KEY="YOUR_API_KEY"
87
+ ```
88
+
89
+ ```python
90
+ from structocr import StructOCR
91
+
92
+ client = StructOCR()
93
+ result = client.scan_passport("./passport.jpg")
94
+
95
+ if result.get("success"):
96
+ data = result["data"]
97
+ print(data.get("passport_number"))
98
+ print(data.get("given_names"), data.get("surname"))
99
+ ```
100
+
101
+ A passport scan returns JSON like this (fictional sample document):
102
+
103
+ ```json
104
+ {
105
+ "success": true,
106
+ "data": {
107
+ "type": "passport",
108
+ "country_code": "UTO",
109
+ "nationality": "UTOPIAN",
110
+ "passport_number": "X4R7T2K9P",
111
+ "surname": "MORGAN",
112
+ "given_names": "OLIVIA ROSE",
113
+ "sex": "F",
114
+ "date_of_birth": "1990-03-14",
115
+ "place_of_birth": "ZENITH CITY",
116
+ "date_of_issue": "2024-07-16",
117
+ "date_of_expiry": "2034-07-15",
118
+ "place_of_issue": null
119
+ }
120
+ }
121
+ ```
122
+
123
+ PDF paths work the same way:
124
+
125
+ ```python
126
+ result = client.scan_invoice("./invoice.pdf")
127
+ ```
128
+
129
+ FastAPI and other server frameworks can pass uploaded bytes without a temporary file:
130
+
131
+ ```python
132
+ content = await upload.read()
133
+ result = client.scan_passport(content)
134
+ ```
135
+
136
+ ## Methods
137
+
138
+ ```text
139
+ scan_passport(file)
140
+ scan_national_id(file)
141
+ scan_driver_license(file)
142
+ scan_driver_license_pdf417(file)
143
+ scan_invoice(file)
144
+ scan_receipt(file)
145
+ scan_vin(file)
146
+ scan_hin(file)
147
+ scan_container(file)
148
+ scan_license_plate(file)
149
+ scan_vehicle_registration(file)
150
+ scan_atm_cassette(file)
151
+ scan_weighbridge_ticket(file)
152
+ get_account_balance()
153
+ ```
154
+
155
+ 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.
156
+
157
+ 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:
158
+
159
+ ```python
160
+ receipt = client.scan_receipt(
161
+ "./receipt.jpg",
162
+ accuracy="enhanced",
163
+ )
164
+ ```
165
+
166
+ `response_version=2` remains accepted for compatibility but is not required. Receipt v1 is retired.
167
+
168
+ US driver license PDF417 example:
169
+
170
+ ```python
171
+ result = client.scan_driver_license_pdf417("./license-back.jpg")
172
+ if result.get("success"):
173
+ print(result["data"]["document_number"])
174
+ ```
175
+
176
+ Weighbridge ticket example:
177
+
178
+ ```python
179
+ result = client.scan_weighbridge_ticket("./weighbridge-ticket.jpg")
180
+ if result.get("success"):
181
+ print(result["data"]["weights"])
182
+ print(result["data"]["validation"])
183
+ ```
184
+
185
+ ## Configuration
186
+
187
+ ```python
188
+ client = StructOCR(
189
+ api_key="YOUR_API_KEY",
190
+ base_url="https://api.structocr.com/v1",
191
+ timeout=60,
192
+ )
193
+ ```
194
+
195
+ See the [API documentation](https://structocr.com/developers?utm_source=pypi&utm_medium=readme&utm_campaign=sdk) for endpoint-specific response schemas and error codes.
196
+
197
+ ## Errors
198
+
199
+ API and network failures raise `StructOCRError`. Existing `except RuntimeError` code continues to work because `StructOCRError` extends `RuntimeError`.
200
+
201
+ ```python
202
+ from structocr import StructOCRError
203
+
204
+ try:
205
+ client.scan_passport("./passport.jpg")
206
+ except StructOCRError as error:
207
+ print(error.status_code, error.code, error.retryable)
208
+ ```
209
+
210
+ `retryable` is advisory only. The SDK does not automatically retry OCR requests because doing so without an idempotency key could charge a request twice.
211
+
212
+ ## License
213
+
214
+ MIT
@@ -0,0 +1,178 @@
1
+ # StructOCR Python SDK
2
+
3
+ Official Python client for the [StructOCR API](https://structocr.com/developers?utm_source=pypi&utm_medium=readme&utm_campaign=sdk).
4
+
5
+ Send a photo or PDF of a passport, ID card, driver license, VIN, invoice, receipt or shipping container and get structured JSON back: one method call per document, no templates to train.
6
+
7
+ The SDK accepts a local JPG, PNG, WebP, or PDF path, plus in-memory `bytes`. It validates the decoded file locally, converts it to Base64, and sends JSON as `{"img": "..."}`. The REST API also supports multipart uploads; this SDK release keeps Base64 JSON as its default transport for backward compatibility.
8
+
9
+ ## Get a free API key
10
+
11
+ 1. [Create an account](https://structocr.com/register?utm_source=pypi&utm_medium=readme&utm_campaign=sdk). New accounts get **200 free credits**, enough for 100 passport or driver license scans, and no credit card is needed.
12
+ 2. Copy your key from **API Keys** in the dashboard.
13
+ 3. Optionally try any document type on a sample image in the [Playground](https://structocr.com/dashboard/playground?utm_source=pypi&utm_medium=readme&utm_campaign=sdk) before you write code.
14
+
15
+ Not ready to sign up? Try any document in your browser on a sample image or your own file, no account needed: use the **Try it** links in the table below.
16
+
17
+ After the free credits, packs start at $5 for 500 credits. There is no subscription and credits do not expire. See [pricing](https://structocr.com/pricing?utm_source=pypi&utm_medium=readme&utm_campaign=sdk).
18
+
19
+ ## Supported documents
20
+
21
+ | Document | Method | Credits per scan | Try it |
22
+ | --- | --- | --- | --- |
23
+ | Passport | `scan_passport` | 2 | [Try it](https://structocr.com/products/passport-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
24
+ | National ID card | `scan_national_id` | 2 | [Try it](https://structocr.com/products/national-id-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
25
+ | Driver license (front) | `scan_driver_license` | 2 | [Try it](https://structocr.com/products/driver-license-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
26
+ | US/Canada driver license PDF417 barcode | `scan_driver_license_pdf417` | 2 | [Try it](https://structocr.com/tools/driver-license-pdf417-scanner?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try) |
27
+ | Vehicle registration | `scan_vehicle_registration` | 2 | [Try it](https://structocr.com/products/vehicle-registration-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
28
+ | VIN | `scan_vin` | 1 | [Try it](https://structocr.com/products/vin-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
29
+ | License plate | `scan_license_plate` | 1 | [Try it](https://structocr.com/products/license-plate-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
30
+ | Invoice | `scan_invoice` | 3 | [Try it](https://structocr.com/products/invoice-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
31
+ | Receipt | `scan_receipt` | 1 | [Try it](https://structocr.com/products/receipt-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
32
+ | Shipping container (ISO 6346) | `scan_container` | 1 | [Try it](https://structocr.com/products/container-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
33
+ | Weighbridge ticket | `scan_weighbridge_ticket` | 2 | [Try it](https://structocr.com/products/weighbridge-ticket-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
34
+ | ATM cassette | `scan_atm_cassette` | 1 | |
35
+ | HIN (boat hull number) | `scan_hin` | 1 | [Try it](https://structocr.com/products/hin-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
36
+
37
+ The receipt endpoint's optional enhanced mode costs 2 credits. Only successful requests are charged.
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ pip install --upgrade structocr
43
+ ```
44
+
45
+ Python 3.7+ is required.
46
+
47
+ ## Quick start
48
+
49
+ ```bash
50
+ export STRUCTOCR_API_KEY="YOUR_API_KEY"
51
+ ```
52
+
53
+ ```python
54
+ from structocr import StructOCR
55
+
56
+ client = StructOCR()
57
+ result = client.scan_passport("./passport.jpg")
58
+
59
+ if result.get("success"):
60
+ data = result["data"]
61
+ print(data.get("passport_number"))
62
+ print(data.get("given_names"), data.get("surname"))
63
+ ```
64
+
65
+ A passport scan returns JSON like this (fictional sample document):
66
+
67
+ ```json
68
+ {
69
+ "success": true,
70
+ "data": {
71
+ "type": "passport",
72
+ "country_code": "UTO",
73
+ "nationality": "UTOPIAN",
74
+ "passport_number": "X4R7T2K9P",
75
+ "surname": "MORGAN",
76
+ "given_names": "OLIVIA ROSE",
77
+ "sex": "F",
78
+ "date_of_birth": "1990-03-14",
79
+ "place_of_birth": "ZENITH CITY",
80
+ "date_of_issue": "2024-07-16",
81
+ "date_of_expiry": "2034-07-15",
82
+ "place_of_issue": null
83
+ }
84
+ }
85
+ ```
86
+
87
+ PDF paths work the same way:
88
+
89
+ ```python
90
+ result = client.scan_invoice("./invoice.pdf")
91
+ ```
92
+
93
+ FastAPI and other server frameworks can pass uploaded bytes without a temporary file:
94
+
95
+ ```python
96
+ content = await upload.read()
97
+ result = client.scan_passport(content)
98
+ ```
99
+
100
+ ## Methods
101
+
102
+ ```text
103
+ scan_passport(file)
104
+ scan_national_id(file)
105
+ scan_driver_license(file)
106
+ scan_driver_license_pdf417(file)
107
+ scan_invoice(file)
108
+ scan_receipt(file)
109
+ scan_vin(file)
110
+ scan_hin(file)
111
+ scan_container(file)
112
+ scan_license_plate(file)
113
+ scan_vehicle_registration(file)
114
+ scan_atm_cassette(file)
115
+ scan_weighbridge_ticket(file)
116
+ get_account_balance()
117
+ ```
118
+
119
+ 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.
120
+
121
+ 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:
122
+
123
+ ```python
124
+ receipt = client.scan_receipt(
125
+ "./receipt.jpg",
126
+ accuracy="enhanced",
127
+ )
128
+ ```
129
+
130
+ `response_version=2` remains accepted for compatibility but is not required. Receipt v1 is retired.
131
+
132
+ US driver license PDF417 example:
133
+
134
+ ```python
135
+ result = client.scan_driver_license_pdf417("./license-back.jpg")
136
+ if result.get("success"):
137
+ print(result["data"]["document_number"])
138
+ ```
139
+
140
+ Weighbridge ticket example:
141
+
142
+ ```python
143
+ result = client.scan_weighbridge_ticket("./weighbridge-ticket.jpg")
144
+ if result.get("success"):
145
+ print(result["data"]["weights"])
146
+ print(result["data"]["validation"])
147
+ ```
148
+
149
+ ## Configuration
150
+
151
+ ```python
152
+ client = StructOCR(
153
+ api_key="YOUR_API_KEY",
154
+ base_url="https://api.structocr.com/v1",
155
+ timeout=60,
156
+ )
157
+ ```
158
+
159
+ See the [API documentation](https://structocr.com/developers?utm_source=pypi&utm_medium=readme&utm_campaign=sdk) for endpoint-specific response schemas and error codes.
160
+
161
+ ## Errors
162
+
163
+ API and network failures raise `StructOCRError`. Existing `except RuntimeError` code continues to work because `StructOCRError` extends `RuntimeError`.
164
+
165
+ ```python
166
+ from structocr import StructOCRError
167
+
168
+ try:
169
+ client.scan_passport("./passport.jpg")
170
+ except StructOCRError as error:
171
+ print(error.status_code, error.code, error.retryable)
172
+ ```
173
+
174
+ `retryable` is advisory only. The SDK does not automatically retry OCR requests because doing so without an idempotency key could charge a request twice.
175
+
176
+ ## License
177
+
178
+ MIT
@@ -9,7 +9,8 @@ exec((ROOT / "structocr" / "version.py").read_text(encoding="utf-8"), VERSION)
9
9
  setup(
10
10
  name="structocr",
11
11
  version=VERSION["__version__"],
12
- description="Official Python SDK for StructOCR Base64 document APIs, including images, PDFs, and account balance.",
12
+ description="Passport, ID card, driver license, VIN, invoice and receipt OCR: turn images and PDFs into structured JSON. Official StructOCR SDK for Python.",
13
+ keywords=["ocr", "passport ocr", "mrz", "id card ocr", "driver license ocr", "pdf417", "vin ocr", "invoice ocr", "receipt ocr", "kyc", "document ai", "structocr"],
13
14
  long_description=(ROOT / "README.md").read_text(encoding="utf-8"),
14
15
  long_description_content_type="text/markdown",
15
16
  license="MIT",
@@ -22,7 +23,8 @@ setup(
22
23
 
23
24
  project_urls={
24
25
  "Homepage": "https://structocr.com",
25
- "Documentation": "https://structocr.com/developers",
26
+ "Documentation": "https://structocr.com/developers",
27
+ "Get a free API key": "https://structocr.com/register?utm_source=pypi&utm_medium=project_urls&utm_campaign=sdk",
26
28
  "Source": "https://github.com/dracula911/structocr-python",
27
29
  "Tracker": "https://github.com/dracula911/structocr-python/issues",
28
30
  },
@@ -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.1"
@@ -0,0 +1,214 @@
1
+ Metadata-Version: 2.4
2
+ Name: structocr
3
+ Version: 1.7.1
4
+ Summary: Passport, ID card, driver license, VIN, invoice and receipt OCR: turn images and PDFs into structured JSON. Official StructOCR SDK for Python.
5
+ Home-page: https://structocr.com
6
+ Author: StructOCR Team
7
+ Author-email: support@structocr.com
8
+ License: MIT
9
+ Project-URL: Homepage, https://structocr.com
10
+ Project-URL: Documentation, https://structocr.com/developers
11
+ Project-URL: Get a free API key, https://structocr.com/register?utm_source=pypi&utm_medium=project_urls&utm_campaign=sdk
12
+ Project-URL: Source, https://github.com/dracula911/structocr-python
13
+ Project-URL: Tracker, https://github.com/dracula911/structocr-python/issues
14
+ Keywords: ocr,passport ocr,mrz,id card ocr,driver license ocr,pdf417,vin ocr,invoice ocr,receipt ocr,kyc,document ai,structocr
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
19
+ Requires-Python: >=3.7
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: requests>=2.25.0
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: classifier
26
+ Dynamic: description
27
+ Dynamic: description-content-type
28
+ Dynamic: home-page
29
+ Dynamic: keywords
30
+ Dynamic: license
31
+ Dynamic: license-file
32
+ Dynamic: project-url
33
+ Dynamic: requires-dist
34
+ Dynamic: requires-python
35
+ Dynamic: summary
36
+
37
+ # StructOCR Python SDK
38
+
39
+ Official Python client for the [StructOCR API](https://structocr.com/developers?utm_source=pypi&utm_medium=readme&utm_campaign=sdk).
40
+
41
+ Send a photo or PDF of a passport, ID card, driver license, VIN, invoice, receipt or shipping container and get structured JSON back: one method call per document, no templates to train.
42
+
43
+ The SDK accepts a local JPG, PNG, WebP, or PDF path, plus in-memory `bytes`. It validates the decoded file locally, converts it to Base64, and sends JSON as `{"img": "..."}`. The REST API also supports multipart uploads; this SDK release keeps Base64 JSON as its default transport for backward compatibility.
44
+
45
+ ## Get a free API key
46
+
47
+ 1. [Create an account](https://structocr.com/register?utm_source=pypi&utm_medium=readme&utm_campaign=sdk). New accounts get **200 free credits**, enough for 100 passport or driver license scans, and no credit card is needed.
48
+ 2. Copy your key from **API Keys** in the dashboard.
49
+ 3. Optionally try any document type on a sample image in the [Playground](https://structocr.com/dashboard/playground?utm_source=pypi&utm_medium=readme&utm_campaign=sdk) before you write code.
50
+
51
+ Not ready to sign up? Try any document in your browser on a sample image or your own file, no account needed: use the **Try it** links in the table below.
52
+
53
+ After the free credits, packs start at $5 for 500 credits. There is no subscription and credits do not expire. See [pricing](https://structocr.com/pricing?utm_source=pypi&utm_medium=readme&utm_campaign=sdk).
54
+
55
+ ## Supported documents
56
+
57
+ | Document | Method | Credits per scan | Try it |
58
+ | --- | --- | --- | --- |
59
+ | Passport | `scan_passport` | 2 | [Try it](https://structocr.com/products/passport-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
60
+ | National ID card | `scan_national_id` | 2 | [Try it](https://structocr.com/products/national-id-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
61
+ | Driver license (front) | `scan_driver_license` | 2 | [Try it](https://structocr.com/products/driver-license-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
62
+ | US/Canada driver license PDF417 barcode | `scan_driver_license_pdf417` | 2 | [Try it](https://structocr.com/tools/driver-license-pdf417-scanner?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try) |
63
+ | Vehicle registration | `scan_vehicle_registration` | 2 | [Try it](https://structocr.com/products/vehicle-registration-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
64
+ | VIN | `scan_vin` | 1 | [Try it](https://structocr.com/products/vin-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
65
+ | License plate | `scan_license_plate` | 1 | [Try it](https://structocr.com/products/license-plate-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
66
+ | Invoice | `scan_invoice` | 3 | [Try it](https://structocr.com/products/invoice-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
67
+ | Receipt | `scan_receipt` | 1 | [Try it](https://structocr.com/products/receipt-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
68
+ | Shipping container (ISO 6346) | `scan_container` | 1 | [Try it](https://structocr.com/products/container-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
69
+ | Weighbridge ticket | `scan_weighbridge_ticket` | 2 | [Try it](https://structocr.com/products/weighbridge-ticket-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
70
+ | ATM cassette | `scan_atm_cassette` | 1 | |
71
+ | HIN (boat hull number) | `scan_hin` | 1 | [Try it](https://structocr.com/products/hin-ocr?utm_source=pypi&utm_medium=readme&utm_campaign=sdk_try#live-demo) |
72
+
73
+ The receipt endpoint's optional enhanced mode costs 2 credits. Only successful requests are charged.
74
+
75
+ ## Install
76
+
77
+ ```bash
78
+ pip install --upgrade structocr
79
+ ```
80
+
81
+ Python 3.7+ is required.
82
+
83
+ ## Quick start
84
+
85
+ ```bash
86
+ export STRUCTOCR_API_KEY="YOUR_API_KEY"
87
+ ```
88
+
89
+ ```python
90
+ from structocr import StructOCR
91
+
92
+ client = StructOCR()
93
+ result = client.scan_passport("./passport.jpg")
94
+
95
+ if result.get("success"):
96
+ data = result["data"]
97
+ print(data.get("passport_number"))
98
+ print(data.get("given_names"), data.get("surname"))
99
+ ```
100
+
101
+ A passport scan returns JSON like this (fictional sample document):
102
+
103
+ ```json
104
+ {
105
+ "success": true,
106
+ "data": {
107
+ "type": "passport",
108
+ "country_code": "UTO",
109
+ "nationality": "UTOPIAN",
110
+ "passport_number": "X4R7T2K9P",
111
+ "surname": "MORGAN",
112
+ "given_names": "OLIVIA ROSE",
113
+ "sex": "F",
114
+ "date_of_birth": "1990-03-14",
115
+ "place_of_birth": "ZENITH CITY",
116
+ "date_of_issue": "2024-07-16",
117
+ "date_of_expiry": "2034-07-15",
118
+ "place_of_issue": null
119
+ }
120
+ }
121
+ ```
122
+
123
+ PDF paths work the same way:
124
+
125
+ ```python
126
+ result = client.scan_invoice("./invoice.pdf")
127
+ ```
128
+
129
+ FastAPI and other server frameworks can pass uploaded bytes without a temporary file:
130
+
131
+ ```python
132
+ content = await upload.read()
133
+ result = client.scan_passport(content)
134
+ ```
135
+
136
+ ## Methods
137
+
138
+ ```text
139
+ scan_passport(file)
140
+ scan_national_id(file)
141
+ scan_driver_license(file)
142
+ scan_driver_license_pdf417(file)
143
+ scan_invoice(file)
144
+ scan_receipt(file)
145
+ scan_vin(file)
146
+ scan_hin(file)
147
+ scan_container(file)
148
+ scan_license_plate(file)
149
+ scan_vehicle_registration(file)
150
+ scan_atm_cassette(file)
151
+ scan_weighbridge_ticket(file)
152
+ get_account_balance()
153
+ ```
154
+
155
+ 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.
156
+
157
+ 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:
158
+
159
+ ```python
160
+ receipt = client.scan_receipt(
161
+ "./receipt.jpg",
162
+ accuracy="enhanced",
163
+ )
164
+ ```
165
+
166
+ `response_version=2` remains accepted for compatibility but is not required. Receipt v1 is retired.
167
+
168
+ US driver license PDF417 example:
169
+
170
+ ```python
171
+ result = client.scan_driver_license_pdf417("./license-back.jpg")
172
+ if result.get("success"):
173
+ print(result["data"]["document_number"])
174
+ ```
175
+
176
+ Weighbridge ticket example:
177
+
178
+ ```python
179
+ result = client.scan_weighbridge_ticket("./weighbridge-ticket.jpg")
180
+ if result.get("success"):
181
+ print(result["data"]["weights"])
182
+ print(result["data"]["validation"])
183
+ ```
184
+
185
+ ## Configuration
186
+
187
+ ```python
188
+ client = StructOCR(
189
+ api_key="YOUR_API_KEY",
190
+ base_url="https://api.structocr.com/v1",
191
+ timeout=60,
192
+ )
193
+ ```
194
+
195
+ See the [API documentation](https://structocr.com/developers?utm_source=pypi&utm_medium=readme&utm_campaign=sdk) for endpoint-specific response schemas and error codes.
196
+
197
+ ## Errors
198
+
199
+ API and network failures raise `StructOCRError`. Existing `except RuntimeError` code continues to work because `StructOCRError` extends `RuntimeError`.
200
+
201
+ ```python
202
+ from structocr import StructOCRError
203
+
204
+ try:
205
+ client.scan_passport("./passport.jpg")
206
+ except StructOCRError as error:
207
+ print(error.status_code, error.code, error.retryable)
208
+ ```
209
+
210
+ `retryable` is advisory only. The SDK does not automatically retry OCR requests because doing so without an idempotency key could charge a request twice.
211
+
212
+ ## License
213
+
214
+ MIT
structocr-1.6.0/PKG-INFO DELETED
@@ -1,147 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: structocr
3
- Version: 1.6.0
4
- Summary: Official Python SDK for StructOCR Base64 document APIs, including images, PDFs, and account balance.
5
- Home-page: https://structocr.com
6
- Author: StructOCR Team
7
- Author-email: support@structocr.com
8
- License: MIT
9
- Project-URL: Homepage, https://structocr.com
10
- Project-URL: Documentation, https://structocr.com/developers
11
- Project-URL: Source, https://github.com/dracula911/structocr-python
12
- Project-URL: Tracker, https://github.com/dracula911/structocr-python/issues
13
- Classifier: Programming Language :: Python :: 3
14
- Classifier: License :: OSI Approved :: MIT License
15
- Classifier: Operating System :: OS Independent
16
- Classifier: Topic :: Scientific/Engineering :: Image Recognition
17
- Requires-Python: >=3.7
18
- Description-Content-Type: text/markdown
19
- License-File: LICENSE
20
- Requires-Dist: requests>=2.25.0
21
- Dynamic: author
22
- Dynamic: author-email
23
- Dynamic: classifier
24
- Dynamic: description
25
- Dynamic: description-content-type
26
- Dynamic: home-page
27
- Dynamic: license
28
- Dynamic: license-file
29
- Dynamic: project-url
30
- Dynamic: requires-dist
31
- Dynamic: requires-python
32
- Dynamic: summary
33
-
34
- # StructOCR Python SDK
35
-
36
- Official Python client for the [StructOCR API](https://structocr.com/developers).
37
-
38
- The SDK accepts a local JPG, PNG, WebP, or PDF path, plus in-memory `bytes`. It validates the decoded file locally, converts it to Base64, and sends JSON as `{"img": "..."}`. The REST API also supports multipart uploads; this SDK release keeps Base64 JSON as its default transport for backward compatibility.
39
-
40
- ## Install
41
-
42
- ```bash
43
- pip install --upgrade structocr
44
- ```
45
-
46
- Python 3.7+ is required.
47
-
48
- ## Quick start
49
-
50
- ```bash
51
- export STRUCTOCR_API_KEY="YOUR_API_KEY"
52
- ```
53
-
54
- ```python
55
- from structocr import StructOCR
56
-
57
- client = StructOCR()
58
- result = client.scan_passport("./passport.jpg")
59
-
60
- if result.get("success"):
61
- data = result["data"]
62
- print(data.get("passport_number"))
63
- print(data.get("given_names"), data.get("surname"))
64
- ```
65
-
66
- PDF paths work the same way:
67
-
68
- ```python
69
- result = client.scan_invoice("./invoice.pdf")
70
- ```
71
-
72
- FastAPI and other server frameworks can pass uploaded bytes without a temporary file:
73
-
74
- ```python
75
- content = await upload.read()
76
- result = client.scan_passport(content)
77
- ```
78
-
79
- ## Methods
80
-
81
- ```text
82
- scan_passport(file)
83
- scan_national_id(file)
84
- scan_driver_license(file)
85
- scan_invoice(file)
86
- scan_receipt(file)
87
- scan_vin(file)
88
- scan_hin(file)
89
- scan_container(file)
90
- scan_license_plate(file)
91
- scan_vehicle_registration(file)
92
- scan_atm_cassette(file)
93
- scan_weighbridge_ticket(file)
94
- get_account_balance()
95
- ```
96
-
97
- All document methods accept a local path or bytes. Supported decoded formats are JPG, PNG, WebP, and PDF, up to 4.5MB.
98
-
99
- Receipt v2 provides a richer response. Enhanced accuracy requires v2 and costs 2 credits instead of the standard 1 credit:
100
-
101
- ```python
102
- receipt = client.scan_receipt(
103
- "./receipt.jpg",
104
- response_version=2,
105
- accuracy="enhanced",
106
- )
107
- ```
108
-
109
- Weighbridge ticket example:
110
-
111
- ```python
112
- result = client.scan_weighbridge_ticket("./weighbridge-ticket.jpg")
113
- if result.get("success"):
114
- print(result["data"]["weights"])
115
- print(result["data"]["validation"])
116
- ```
117
-
118
- ## Configuration
119
-
120
- ```python
121
- client = StructOCR(
122
- api_key="YOUR_API_KEY",
123
- base_url="https://api.structocr.com/v1",
124
- timeout=60,
125
- )
126
- ```
127
-
128
- See the [API documentation](https://structocr.com/developers) for endpoint-specific response schemas and error codes.
129
-
130
- ## Errors
131
-
132
- API and network failures raise `StructOCRError`. Existing `except RuntimeError` code continues to work because `StructOCRError` extends `RuntimeError`.
133
-
134
- ```python
135
- from structocr import StructOCRError
136
-
137
- try:
138
- client.scan_passport("./passport.jpg")
139
- except StructOCRError as error:
140
- print(error.status_code, error.code, error.retryable)
141
- ```
142
-
143
- `retryable` is advisory only. The SDK does not automatically retry OCR requests because doing so without an idempotency key could charge a request twice.
144
-
145
- ## License
146
-
147
- MIT
structocr-1.6.0/README.md DELETED
@@ -1,114 +0,0 @@
1
- # StructOCR Python SDK
2
-
3
- Official Python client for the [StructOCR API](https://structocr.com/developers).
4
-
5
- The SDK accepts a local JPG, PNG, WebP, or PDF path, plus in-memory `bytes`. It validates the decoded file locally, converts it to Base64, and sends JSON as `{"img": "..."}`. The REST API also supports multipart uploads; this SDK release keeps Base64 JSON as its default transport for backward compatibility.
6
-
7
- ## Install
8
-
9
- ```bash
10
- pip install --upgrade structocr
11
- ```
12
-
13
- Python 3.7+ is required.
14
-
15
- ## Quick start
16
-
17
- ```bash
18
- export STRUCTOCR_API_KEY="YOUR_API_KEY"
19
- ```
20
-
21
- ```python
22
- from structocr import StructOCR
23
-
24
- client = StructOCR()
25
- result = client.scan_passport("./passport.jpg")
26
-
27
- if result.get("success"):
28
- data = result["data"]
29
- print(data.get("passport_number"))
30
- print(data.get("given_names"), data.get("surname"))
31
- ```
32
-
33
- PDF paths work the same way:
34
-
35
- ```python
36
- result = client.scan_invoice("./invoice.pdf")
37
- ```
38
-
39
- FastAPI and other server frameworks can pass uploaded bytes without a temporary file:
40
-
41
- ```python
42
- content = await upload.read()
43
- result = client.scan_passport(content)
44
- ```
45
-
46
- ## Methods
47
-
48
- ```text
49
- scan_passport(file)
50
- scan_national_id(file)
51
- scan_driver_license(file)
52
- scan_invoice(file)
53
- scan_receipt(file)
54
- scan_vin(file)
55
- scan_hin(file)
56
- scan_container(file)
57
- scan_license_plate(file)
58
- scan_vehicle_registration(file)
59
- scan_atm_cassette(file)
60
- scan_weighbridge_ticket(file)
61
- get_account_balance()
62
- ```
63
-
64
- All document methods accept a local path or bytes. Supported decoded formats are JPG, PNG, WebP, and PDF, up to 4.5MB.
65
-
66
- Receipt v2 provides a richer response. Enhanced accuracy requires v2 and costs 2 credits instead of the standard 1 credit:
67
-
68
- ```python
69
- receipt = client.scan_receipt(
70
- "./receipt.jpg",
71
- response_version=2,
72
- accuracy="enhanced",
73
- )
74
- ```
75
-
76
- Weighbridge ticket example:
77
-
78
- ```python
79
- result = client.scan_weighbridge_ticket("./weighbridge-ticket.jpg")
80
- if result.get("success"):
81
- print(result["data"]["weights"])
82
- print(result["data"]["validation"])
83
- ```
84
-
85
- ## Configuration
86
-
87
- ```python
88
- client = StructOCR(
89
- api_key="YOUR_API_KEY",
90
- base_url="https://api.structocr.com/v1",
91
- timeout=60,
92
- )
93
- ```
94
-
95
- See the [API documentation](https://structocr.com/developers) for endpoint-specific response schemas and error codes.
96
-
97
- ## Errors
98
-
99
- API and network failures raise `StructOCRError`. Existing `except RuntimeError` code continues to work because `StructOCRError` extends `RuntimeError`.
100
-
101
- ```python
102
- from structocr import StructOCRError
103
-
104
- try:
105
- client.scan_passport("./passport.jpg")
106
- except StructOCRError as error:
107
- print(error.status_code, error.code, error.retryable)
108
- ```
109
-
110
- `retryable` is advisory only. The SDK does not automatically retry OCR requests because doing so without an idempotency key could charge a request twice.
111
-
112
- ## License
113
-
114
- MIT
@@ -1 +0,0 @@
1
- __version__ = "1.6.0"
@@ -1,147 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: structocr
3
- Version: 1.6.0
4
- Summary: Official Python SDK for StructOCR Base64 document APIs, including images, PDFs, and account balance.
5
- Home-page: https://structocr.com
6
- Author: StructOCR Team
7
- Author-email: support@structocr.com
8
- License: MIT
9
- Project-URL: Homepage, https://structocr.com
10
- Project-URL: Documentation, https://structocr.com/developers
11
- Project-URL: Source, https://github.com/dracula911/structocr-python
12
- Project-URL: Tracker, https://github.com/dracula911/structocr-python/issues
13
- Classifier: Programming Language :: Python :: 3
14
- Classifier: License :: OSI Approved :: MIT License
15
- Classifier: Operating System :: OS Independent
16
- Classifier: Topic :: Scientific/Engineering :: Image Recognition
17
- Requires-Python: >=3.7
18
- Description-Content-Type: text/markdown
19
- License-File: LICENSE
20
- Requires-Dist: requests>=2.25.0
21
- Dynamic: author
22
- Dynamic: author-email
23
- Dynamic: classifier
24
- Dynamic: description
25
- Dynamic: description-content-type
26
- Dynamic: home-page
27
- Dynamic: license
28
- Dynamic: license-file
29
- Dynamic: project-url
30
- Dynamic: requires-dist
31
- Dynamic: requires-python
32
- Dynamic: summary
33
-
34
- # StructOCR Python SDK
35
-
36
- Official Python client for the [StructOCR API](https://structocr.com/developers).
37
-
38
- The SDK accepts a local JPG, PNG, WebP, or PDF path, plus in-memory `bytes`. It validates the decoded file locally, converts it to Base64, and sends JSON as `{"img": "..."}`. The REST API also supports multipart uploads; this SDK release keeps Base64 JSON as its default transport for backward compatibility.
39
-
40
- ## Install
41
-
42
- ```bash
43
- pip install --upgrade structocr
44
- ```
45
-
46
- Python 3.7+ is required.
47
-
48
- ## Quick start
49
-
50
- ```bash
51
- export STRUCTOCR_API_KEY="YOUR_API_KEY"
52
- ```
53
-
54
- ```python
55
- from structocr import StructOCR
56
-
57
- client = StructOCR()
58
- result = client.scan_passport("./passport.jpg")
59
-
60
- if result.get("success"):
61
- data = result["data"]
62
- print(data.get("passport_number"))
63
- print(data.get("given_names"), data.get("surname"))
64
- ```
65
-
66
- PDF paths work the same way:
67
-
68
- ```python
69
- result = client.scan_invoice("./invoice.pdf")
70
- ```
71
-
72
- FastAPI and other server frameworks can pass uploaded bytes without a temporary file:
73
-
74
- ```python
75
- content = await upload.read()
76
- result = client.scan_passport(content)
77
- ```
78
-
79
- ## Methods
80
-
81
- ```text
82
- scan_passport(file)
83
- scan_national_id(file)
84
- scan_driver_license(file)
85
- scan_invoice(file)
86
- scan_receipt(file)
87
- scan_vin(file)
88
- scan_hin(file)
89
- scan_container(file)
90
- scan_license_plate(file)
91
- scan_vehicle_registration(file)
92
- scan_atm_cassette(file)
93
- scan_weighbridge_ticket(file)
94
- get_account_balance()
95
- ```
96
-
97
- All document methods accept a local path or bytes. Supported decoded formats are JPG, PNG, WebP, and PDF, up to 4.5MB.
98
-
99
- Receipt v2 provides a richer response. Enhanced accuracy requires v2 and costs 2 credits instead of the standard 1 credit:
100
-
101
- ```python
102
- receipt = client.scan_receipt(
103
- "./receipt.jpg",
104
- response_version=2,
105
- accuracy="enhanced",
106
- )
107
- ```
108
-
109
- Weighbridge ticket example:
110
-
111
- ```python
112
- result = client.scan_weighbridge_ticket("./weighbridge-ticket.jpg")
113
- if result.get("success"):
114
- print(result["data"]["weights"])
115
- print(result["data"]["validation"])
116
- ```
117
-
118
- ## Configuration
119
-
120
- ```python
121
- client = StructOCR(
122
- api_key="YOUR_API_KEY",
123
- base_url="https://api.structocr.com/v1",
124
- timeout=60,
125
- )
126
- ```
127
-
128
- See the [API documentation](https://structocr.com/developers) for endpoint-specific response schemas and error codes.
129
-
130
- ## Errors
131
-
132
- API and network failures raise `StructOCRError`. Existing `except RuntimeError` code continues to work because `StructOCRError` extends `RuntimeError`.
133
-
134
- ```python
135
- from structocr import StructOCRError
136
-
137
- try:
138
- client.scan_passport("./passport.jpg")
139
- except StructOCRError as error:
140
- print(error.status_code, error.code, error.retryable)
141
- ```
142
-
143
- `retryable` is advisory only. The SDK does not automatically retry OCR requests because doing so without an idempotency key could charge a request twice.
144
-
145
- ## License
146
-
147
- MIT
File without changes
File without changes
File without changes
File without changes