structocr 1.3.1__tar.gz → 1.5.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 StructOCR
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ include LICENSE
2
+ include README.md
@@ -0,0 +1,112 @@
1
+ Metadata-Version: 2.4
2
+ Name: structocr
3
+ Version: 1.5.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 the API's required JSON payload: `{"img": "..."}`. The REST API itself does not accept file paths, bytes, URLs, or multipart uploads.
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
+ get_account_balance()
94
+ ```
95
+
96
+ All document methods accept a local path or bytes. Supported decoded formats are JPG, PNG, WebP, and PDF, up to 4.5MB.
97
+
98
+ ## Configuration
99
+
100
+ ```python
101
+ client = StructOCR(
102
+ api_key="YOUR_API_KEY",
103
+ base_url="https://api.structocr.com/v1",
104
+ timeout=60,
105
+ )
106
+ ```
107
+
108
+ See the [API documentation](https://structocr.com/developers) for endpoint-specific response schemas and error codes.
109
+
110
+ ## License
111
+
112
+ MIT
@@ -0,0 +1,79 @@
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 the API's required JSON payload: `{"img": "..."}`. The REST API itself does not accept file paths, bytes, URLs, or multipart uploads.
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
+ get_account_balance()
61
+ ```
62
+
63
+ All document methods accept a local path or bytes. Supported decoded formats are JPG, PNG, WebP, and PDF, up to 4.5MB.
64
+
65
+ ## Configuration
66
+
67
+ ```python
68
+ client = StructOCR(
69
+ api_key="YOUR_API_KEY",
70
+ base_url="https://api.structocr.com/v1",
71
+ timeout=60,
72
+ )
73
+ ```
74
+
75
+ See the [API documentation](https://structocr.com/developers) for endpoint-specific response schemas and error codes.
76
+
77
+ ## License
78
+
79
+ MIT
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61", "wheel"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,39 @@
1
+ from setuptools import setup, find_packages
2
+ from pathlib import Path
3
+
4
+
5
+ ROOT = Path(__file__).parent
6
+
7
+ setup(
8
+ name="structocr",
9
+ version="1.5.0",
10
+ description="Official Python SDK for StructOCR Base64 document APIs, including images, PDFs, and account balance.",
11
+ long_description=(ROOT / "README.md").read_text(encoding="utf-8"),
12
+ long_description_content_type="text/markdown",
13
+ license="MIT",
14
+ license_files=("LICENSE",),
15
+
16
+ author="StructOCR Team",
17
+ author_email="support@structocr.com",
18
+
19
+ url="https://structocr.com",
20
+
21
+ project_urls={
22
+ "Homepage": "https://structocr.com",
23
+ "Documentation": "https://structocr.com/developers",
24
+ "Source": "https://github.com/dracula911/structocr-python",
25
+ "Tracker": "https://github.com/dracula911/structocr-python/issues",
26
+ },
27
+
28
+ packages=find_packages(),
29
+ install_requires=[
30
+ "requests>=2.25.0",
31
+ ],
32
+ classifiers=[
33
+ "Programming Language :: Python :: 3",
34
+ "License :: OSI Approved :: MIT License",
35
+ "Operating System :: OS Independent",
36
+ "Topic :: Scientific/Engineering :: Image Recognition",
37
+ ],
38
+ python_requires='>=3.7',
39
+ )
@@ -0,0 +1,5 @@
1
+ __version__ = "1.5.0"
2
+
3
+ from .client import StructOCR
4
+
5
+ __all__ = ['StructOCR']
@@ -0,0 +1,125 @@
1
+ import base64
2
+ import os
3
+ from pathlib import Path
4
+ from typing import Any, Dict, Optional, Union
5
+
6
+ import requests
7
+
8
+
9
+ FileInput = Union[str, os.PathLike, bytes, bytearray, memoryview]
10
+ MAX_FILE_SIZE = int(4.5 * 1024 * 1024)
11
+ SUPPORTED_FORMATS = "JPG, PNG, WebP, and PDF"
12
+
13
+
14
+ class StructOCR:
15
+ """Official Python client for the StructOCR Base64 JSON API."""
16
+
17
+ def __init__(
18
+ self,
19
+ api_key: Optional[str] = None,
20
+ base_url: str = "https://api.structocr.com/v1",
21
+ timeout: float = 30.0,
22
+ ) -> None:
23
+ self.api_key = api_key or os.environ.get("STRUCTOCR_API_KEY")
24
+ if not self.api_key:
25
+ raise ValueError("API Key is required. Get one at https://structocr.com")
26
+
27
+ self.base_url = base_url.rstrip("/")
28
+ self.timeout = timeout
29
+ self.session = requests.Session()
30
+ self.session.headers.update({
31
+ "x-api-key": self.api_key,
32
+ "Content-Type": "application/json",
33
+ "User-Agent": "StructOCR-Python/1.5.0",
34
+ })
35
+
36
+ @staticmethod
37
+ def _read_file(file: FileInput) -> bytes:
38
+ if isinstance(file, (bytes, bytearray, memoryview)):
39
+ content = bytes(file)
40
+ else:
41
+ path = Path(file)
42
+ if not path.is_file():
43
+ raise FileNotFoundError(f"File not found: {path}")
44
+ content = path.read_bytes()
45
+
46
+ if not content:
47
+ raise ValueError("File is empty")
48
+ if len(content) > MAX_FILE_SIZE:
49
+ raise ValueError("File exceeds the maximum allowed size of 4.5MB")
50
+ if StructOCR._detect_mime(content) is None:
51
+ raise ValueError(f"Unsupported file format. Supported formats: {SUPPORTED_FORMATS}")
52
+ return content
53
+
54
+ @staticmethod
55
+ def _detect_mime(content: bytes) -> Optional[str]:
56
+ if content.startswith(b"%PDF"):
57
+ return "application/pdf"
58
+ if content.startswith(b"\xff\xd8\xff"):
59
+ return "image/jpeg"
60
+ if content.startswith(b"\x89PNG\r\n\x1a\n"):
61
+ return "image/png"
62
+ if len(content) >= 12 and content[:4] == b"RIFF" and content[8:12] == b"WEBP":
63
+ return "image/webp"
64
+ return None
65
+
66
+ def _post_image(self, endpoint: str, file: FileInput) -> Dict[str, Any]:
67
+ """Read a local file or bytes and send it as Base64 JSON in ``img``."""
68
+ content = self._read_file(file)
69
+ payload = {"img": base64.b64encode(content).decode("ascii")}
70
+
71
+ try:
72
+ response = self.session.post(
73
+ f"{self.base_url}/{endpoint}",
74
+ json=payload,
75
+ timeout=self.timeout,
76
+ )
77
+ response.raise_for_status()
78
+ return response.json()
79
+ except requests.exceptions.RequestException as error:
80
+ raise RuntimeError(f"API request failed: {error}") from error
81
+
82
+ def get_account_balance(self) -> Dict[str, Any]:
83
+ """Return account-level and current-key usage from ``/account/balance``."""
84
+ try:
85
+ response = self.session.get(
86
+ f"{self.base_url}/account/balance",
87
+ timeout=self.timeout,
88
+ )
89
+ response.raise_for_status()
90
+ return response.json()
91
+ except requests.exceptions.RequestException as error:
92
+ raise RuntimeError(f"API request failed: {error}") from error
93
+
94
+ def scan_passport(self, file: FileInput) -> Dict[str, Any]:
95
+ return self._post_image("passport", file)
96
+
97
+ def scan_national_id(self, file: FileInput) -> Dict[str, Any]:
98
+ return self._post_image("national-id", file)
99
+
100
+ def scan_driver_license(self, file: FileInput) -> Dict[str, Any]:
101
+ return self._post_image("driver-license", file)
102
+
103
+ def scan_invoice(self, file: FileInput) -> Dict[str, Any]:
104
+ return self._post_image("invoice", file)
105
+
106
+ def scan_vin(self, file: FileInput) -> Dict[str, Any]:
107
+ return self._post_image("vin", file)
108
+
109
+ def scan_container(self, file: FileInput) -> Dict[str, Any]:
110
+ return self._post_image("container", file)
111
+
112
+ def scan_hin(self, file: FileInput) -> Dict[str, Any]:
113
+ return self._post_image("hin", file)
114
+
115
+ def scan_receipt(self, file: FileInput) -> Dict[str, Any]:
116
+ return self._post_image("receipt", file)
117
+
118
+ def scan_license_plate(self, file: FileInput) -> Dict[str, Any]:
119
+ return self._post_image("license-plate", file)
120
+
121
+ def scan_vehicle_registration(self, file: FileInput) -> Dict[str, Any]:
122
+ return self._post_image("vehicle-registration", file)
123
+
124
+ def scan_atm_cassette(self, file: FileInput) -> Dict[str, Any]:
125
+ return self._post_image("atm-cassette", file)
@@ -0,0 +1,112 @@
1
+ Metadata-Version: 2.4
2
+ Name: structocr
3
+ Version: 1.5.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 the API's required JSON payload: `{"img": "..."}`. The REST API itself does not accept file paths, bytes, URLs, or multipart uploads.
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
+ get_account_balance()
94
+ ```
95
+
96
+ All document methods accept a local path or bytes. Supported decoded formats are JPG, PNG, WebP, and PDF, up to 4.5MB.
97
+
98
+ ## Configuration
99
+
100
+ ```python
101
+ client = StructOCR(
102
+ api_key="YOUR_API_KEY",
103
+ base_url="https://api.structocr.com/v1",
104
+ timeout=60,
105
+ )
106
+ ```
107
+
108
+ See the [API documentation](https://structocr.com/developers) for endpoint-specific response schemas and error codes.
109
+
110
+ ## License
111
+
112
+ MIT
@@ -1,4 +1,7 @@
1
+ LICENSE
2
+ MANIFEST.in
1
3
  README.md
4
+ pyproject.toml
2
5
  setup.py
3
6
  structocr/__init__.py
4
7
  structocr/client.py
structocr-1.3.1/PKG-INFO DELETED
@@ -1,130 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: structocr
3
- Version: 1.3.1
4
- Summary: The official Python SDK for StructOCR API - Passport, ID card, Driver License OCR, Invoice, Receipts, VIN, HIN and Container OCR.
5
- Home-page: https://structocr.com
6
- Author: StructOCR Team
7
- Author-email: support@structocr.com
8
- Project-URL: Homepage, https://structocr.com
9
- Project-URL: Documentation, https://structocr.com/developers
10
- Project-URL: Source, https://github.com/structocr/structocr-python
11
- Project-URL: Tracker, https://github.com/structocr/structocr-python/issues
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Operating System :: OS Independent
15
- Classifier: Topic :: Scientific/Engineering :: Image Recognition
16
- Requires-Python: >=3.6
17
- Description-Content-Type: text/markdown
18
- Requires-Dist: requests>=2.25.0
19
- Dynamic: author
20
- Dynamic: author-email
21
- Dynamic: classifier
22
- Dynamic: description
23
- Dynamic: description-content-type
24
- Dynamic: home-page
25
- Dynamic: project-url
26
- Dynamic: requires-dist
27
- Dynamic: requires-python
28
- Dynamic: summary
29
-
30
- # StructOCR Python SDK
31
-
32
- [![PyPI version](https://badge.fury.io/py/structocr.svg)](https://badge.fury.io/py/structocr)
33
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
34
-
35
- **The official Python client for [StructOCR](https://structocr.com).**
36
-
37
- StructOCR is a powerful API tailored for developers to extract structured data from complex documents and physical assets with high accuracy. This SDK helps you integrate **Passport OCR**, **National ID OCR**, **Driver License OCR**, **Invoice OCR**, **Receipt OCR**, **VIN OCR**, **HIN OCR**, and **Container OCR** into your Python applications in minutes.
38
-
39
- 👉 **[Get your Free API Key here](https://structocr.com)**
40
-
41
- -----
42
-
43
- ## 🚀 What's New in 1.3.1
44
-
45
- We've massively upgraded our Identity Verification engine!
46
- * **Hybrid VIZ + MRZ AI for National IDs**: The SDK now automatically cross-validates unstructured Visual Zone (VIZ) data against cryptographic Machine Readable Zone (MRZ) checksums (TD1/TD2) for zero hallucination. Raw MRZ lines are now accessible via `additional_fields`.
47
- * *Previous marine & expense additions (Receipt OCR, HIN OCR, Container OCR) remain fully supported.*
48
-
49
- Check out the [Quick Start](#quick-start) below to see how easy it is to use them!
50
-
51
- -----
52
-
53
- ## Features
54
-
55
- - **Passport OCR API**: Instantly extract MRZ, name, DOB, and expiry date from passports of 200+ countries.
56
- - **National ID OCR**: Extract regional specific fields (CNP, CPF, NIN) and raw ICAO 9303 MRZ lines with hybrid validation.
57
- - **Driver License OCR**: Extract vehicle class, license number, and personal details.
58
- - **Invoice OCR**: Extract invoice number, currency, merchant, customer, and financial totals.
59
- - **Receipt OCR**: Extract merchants, dates, line items, taxes, and totals for expense management.
60
- - **VIN OCR**: Extract VIN (Vehicle Identification Number) from windshield or engine bay images.
61
- - **HIN OCR**: Validate and extract Hull Identification Numbers from marine vessels.
62
- - **Container OCR**: Extract shipping container numbers accurately from images.
63
- - **Secure & Fast**: Enterprise-grade encryption, SOC2 compliance, and sub-second response times with zero data retention.
64
-
65
- ## Installation
66
-
67
- Install the package via pip:
68
-
69
- ```bash
70
- pip install structocr
71
- ```
72
-
73
- ## Quick Start
74
-
75
- ### 1\. Initialize the Client
76
-
77
- ```python
78
- from structocr import StructOCR
79
-
80
- # Initialize with your API Key
81
- client = StructOCR(api_key="sk_live_xxxxxxxx")
82
- ```
83
-
84
- ### 2\. Scan a Passport (Passport OCR)
85
-
86
- ```python
87
- # Pass the path to the passport image file
88
- result = client.scan_passport('./docs/passport_sample.jpg')
89
-
90
- print(f"Name: {result['data']['name']}")
91
- print(f"Passport Number: {result['data']['document_number']}")
92
- ```
93
-
94
- ### 3\. Scan Other Documents and Assets
95
-
96
- ```python
97
- # National ID OCR
98
- id_data = client.scan_national_id('./docs/id_card.png')
99
-
100
- # Driver License OCR
101
- license_data = client.scan_driver_license('./docs/license.jpg')
102
-
103
- # Invoice OCR
104
- invoice_data = client.scan_invoice('./docs/invoice.jpg')
105
-
106
- # Receipt OCR (New in 1.2.0)
107
- receipt_data = client.scan_receipt('./docs/receipt.jpg')
108
-
109
- # VIN OCR
110
- vin_data = client.scan_vin('./docs/vin.jpg')
111
-
112
- # HIN OCR (New in 1.2.0)
113
- hin_data = client.scan_hin('./docs/boat_hin.jpg')
114
-
115
- # Container OCR
116
- container_data = client.scan_container('./docs/container.jpg')
117
- ```
118
-
119
- ## Documentation
120
-
121
- For full API documentation, response examples, and error codes, please visit the [StructOCR Developer Docs](https://www.structocr.com/developers?ref=github).
122
-
123
- ## Requirements
124
-
125
- * Python 3.7+
126
- * `requests` library
127
-
128
- ## License
129
-
130
- MIT License. See [LICENSE](https://opensource.org/licenses/MIT) for details.
structocr-1.3.1/README.md DELETED
@@ -1,101 +0,0 @@
1
- # StructOCR Python SDK
2
-
3
- [![PyPI version](https://badge.fury.io/py/structocr.svg)](https://badge.fury.io/py/structocr)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
-
6
- **The official Python client for [StructOCR](https://structocr.com).**
7
-
8
- StructOCR is a powerful API tailored for developers to extract structured data from complex documents and physical assets with high accuracy. This SDK helps you integrate **Passport OCR**, **National ID OCR**, **Driver License OCR**, **Invoice OCR**, **Receipt OCR**, **VIN OCR**, **HIN OCR**, and **Container OCR** into your Python applications in minutes.
9
-
10
- 👉 **[Get your Free API Key here](https://structocr.com)**
11
-
12
- -----
13
-
14
- ## 🚀 What's New in 1.3.1
15
-
16
- We've massively upgraded our Identity Verification engine!
17
- * **Hybrid VIZ + MRZ AI for National IDs**: The SDK now automatically cross-validates unstructured Visual Zone (VIZ) data against cryptographic Machine Readable Zone (MRZ) checksums (TD1/TD2) for zero hallucination. Raw MRZ lines are now accessible via `additional_fields`.
18
- * *Previous marine & expense additions (Receipt OCR, HIN OCR, Container OCR) remain fully supported.*
19
-
20
- Check out the [Quick Start](#quick-start) below to see how easy it is to use them!
21
-
22
- -----
23
-
24
- ## Features
25
-
26
- - **Passport OCR API**: Instantly extract MRZ, name, DOB, and expiry date from passports of 200+ countries.
27
- - **National ID OCR**: Extract regional specific fields (CNP, CPF, NIN) and raw ICAO 9303 MRZ lines with hybrid validation.
28
- - **Driver License OCR**: Extract vehicle class, license number, and personal details.
29
- - **Invoice OCR**: Extract invoice number, currency, merchant, customer, and financial totals.
30
- - **Receipt OCR**: Extract merchants, dates, line items, taxes, and totals for expense management.
31
- - **VIN OCR**: Extract VIN (Vehicle Identification Number) from windshield or engine bay images.
32
- - **HIN OCR**: Validate and extract Hull Identification Numbers from marine vessels.
33
- - **Container OCR**: Extract shipping container numbers accurately from images.
34
- - **Secure & Fast**: Enterprise-grade encryption, SOC2 compliance, and sub-second response times with zero data retention.
35
-
36
- ## Installation
37
-
38
- Install the package via pip:
39
-
40
- ```bash
41
- pip install structocr
42
- ```
43
-
44
- ## Quick Start
45
-
46
- ### 1\. Initialize the Client
47
-
48
- ```python
49
- from structocr import StructOCR
50
-
51
- # Initialize with your API Key
52
- client = StructOCR(api_key="sk_live_xxxxxxxx")
53
- ```
54
-
55
- ### 2\. Scan a Passport (Passport OCR)
56
-
57
- ```python
58
- # Pass the path to the passport image file
59
- result = client.scan_passport('./docs/passport_sample.jpg')
60
-
61
- print(f"Name: {result['data']['name']}")
62
- print(f"Passport Number: {result['data']['document_number']}")
63
- ```
64
-
65
- ### 3\. Scan Other Documents and Assets
66
-
67
- ```python
68
- # National ID OCR
69
- id_data = client.scan_national_id('./docs/id_card.png')
70
-
71
- # Driver License OCR
72
- license_data = client.scan_driver_license('./docs/license.jpg')
73
-
74
- # Invoice OCR
75
- invoice_data = client.scan_invoice('./docs/invoice.jpg')
76
-
77
- # Receipt OCR (New in 1.2.0)
78
- receipt_data = client.scan_receipt('./docs/receipt.jpg')
79
-
80
- # VIN OCR
81
- vin_data = client.scan_vin('./docs/vin.jpg')
82
-
83
- # HIN OCR (New in 1.2.0)
84
- hin_data = client.scan_hin('./docs/boat_hin.jpg')
85
-
86
- # Container OCR
87
- container_data = client.scan_container('./docs/container.jpg')
88
- ```
89
-
90
- ## Documentation
91
-
92
- For full API documentation, response examples, and error codes, please visit the [StructOCR Developer Docs](https://www.structocr.com/developers?ref=github).
93
-
94
- ## Requirements
95
-
96
- * Python 3.7+
97
- * `requests` library
98
-
99
- ## License
100
-
101
- MIT License. See [LICENSE](https://opensource.org/licenses/MIT) for details.
structocr-1.3.1/setup.py DELETED
@@ -1,35 +0,0 @@
1
- from setuptools import setup, find_packages
2
-
3
- setup(
4
- name="structocr",
5
- version="1.3.1",
6
- description="The official Python SDK for StructOCR API - Passport, ID card, Driver License OCR, Invoice, Receipts, VIN, HIN and Container OCR.",
7
- long_description=open("README.md").read(),
8
- long_description_content_type="text/markdown",
9
-
10
- author="StructOCR Team",
11
- author_email="support@structocr.com",
12
-
13
- # 1. 这里通常放主页或者 GitHub 地址 (PyPI 标题下的链接)
14
- url="https://structocr.com",
15
-
16
- # 2. 这里定义侧边栏的具体链接 (Homepage, Documentation, Source 等)
17
- project_urls={
18
- "Homepage": "https://structocr.com",
19
- "Documentation": "https://structocr.com/developers", # 假设你的文档在这里
20
- "Source": "https://github.com/structocr/structocr-python",
21
- "Tracker": "https://github.com/structocr/structocr-python/issues", # 问题追踪
22
- },
23
-
24
- packages=find_packages(),
25
- install_requires=[
26
- "requests>=2.25.0",
27
- ],
28
- classifiers=[
29
- "Programming Language :: Python :: 3",
30
- "License :: OSI Approved :: MIT License",
31
- "Operating System :: OS Independent",
32
- "Topic :: Scientific/Engineering :: Image Recognition",
33
- ],
34
- python_requires='>=3.6',
35
- )
@@ -1,5 +0,0 @@
1
- __version__ = "1.3.1"
2
-
3
- from .client import StructOCR
4
-
5
- __all__ = ['StructOCR']
@@ -1,129 +0,0 @@
1
- import requests
2
- import os
3
- import base64
4
- import json
5
-
6
- class StructOCR:
7
- """
8
- StructOCR Python Client
9
- Get your API Key at: https://structocr.com
10
- """
11
- def __init__(self, api_key=None, base_url="https://api.structocr.com/v1"):
12
- # Allow reading API Key from environment variables for better DX
13
- self.api_key = api_key or os.environ.get('STRUCTOCR_API_KEY')
14
- if not self.api_key:
15
- raise ValueError("API Key is required. Get one at https://structocr.com")
16
-
17
- self.base_url = base_url.rstrip('/')
18
- self.session = requests.Session()
19
-
20
- # Updated headers based on your API specification
21
- self.session.headers.update({
22
- "x-api-key": self.api_key,
23
- "Content-Type": "application/json",
24
- "User-Agent": "StructOCR-Python/1.3.1"
25
- })
26
-
27
- def _post_image(self, endpoint, file_path):
28
- """
29
- Internal method: Handle image encoding and API request.
30
- """
31
- url = f"{self.base_url}/{endpoint}"
32
-
33
- if not os.path.exists(file_path):
34
- raise FileNotFoundError(f"File not found: {file_path}")
35
-
36
- try:
37
- # 1. Encode image to Base64
38
- with open(file_path, "rb") as image_file:
39
- base64_image = base64.b64encode(image_file.read()).decode('utf-8')
40
-
41
- # 2. Prepare JSON payload
42
- payload = {
43
- "img": base64_image
44
- }
45
-
46
- # 3. Send Request
47
- response = self.session.post(url, json=payload)
48
- response.raise_for_status() # Raise error for 4xx/5xx responses
49
-
50
- return response.json()
51
-
52
- except requests.exceptions.RequestException as e:
53
- # Handle connection errors or API errors
54
- raise Exception(f"API Request failed: {str(e)}")
55
-
56
- # --- Public Methods for Developers ---
57
-
58
- def scan_passport(self, file_path):
59
- """
60
- Scan a Passport image.
61
- path: Path to the passport image file.
62
- Returns: Structured JSON data.
63
- """
64
- # Endpoint: /v1/passport
65
- return self._post_image('passport', file_path)
66
-
67
- def scan_national_id(self, file_path):
68
- """
69
- Scan a National ID card.
70
- path: Path to the ID card image file.
71
- Returns: Structured JSON data.
72
- Note: MRZ lines (if present) are located inside the 'additional_fields' object.
73
- """
74
- # Endpoint: /v1/national-id
75
- return self._post_image('national-id', file_path)
76
-
77
- def scan_driver_license(self, file_path):
78
- """
79
- Scan a Driver License.
80
- path: Path to the driver license image file.
81
- Returns: Structured JSON data.
82
- """
83
- # Endpoint: /v1/driver-license
84
- return self._post_image('driver-license', file_path)
85
-
86
- def scan_invoice(self, file_path):
87
- """
88
- Scan a Invoice.
89
- path: Path to the invoice image file.
90
- Returns: Structured JSON data.
91
- """
92
- # Endpoint: /v1/invoice
93
- return self._post_image('invoice', file_path)
94
-
95
- def scan_vin(self, file_path):
96
- """
97
- Scan a VIN (Vehicle Identification Number).
98
- path: Path to the VIN image file.
99
- Returns: Structured JSON data.
100
- """
101
- # Endpoint: /v1/vin
102
- return self._post_image('vin', file_path)
103
-
104
- def scan_container(self, file_path):
105
- """
106
- Scan a shipping container number (集装箱号).
107
- path: Path to the container image file.
108
- Returns: Structured JSON data.
109
- """
110
- # Endpoint: /v1/container (这里假设你的后端路由是 container,如果不同请替换)
111
- return self._post_image('container', file_path)
112
-
113
- def scan_hin(self, file_path):
114
- """
115
- Scan a Hull Identification Number (HIN) from a boat or watercraft.
116
- path: Path to the HIN image file.
117
- Returns: Structured JSON data.
118
- """
119
- # Endpoint: /v1/hin
120
- return self._post_image('hin', file_path)
121
-
122
- def scan_receipt(self, file_path):
123
- """
124
- Scan a Retail/Dining Receipt for expense extraction.
125
- path: Path to the receipt image file.
126
- Returns: Structured JSON data.
127
- """
128
- # Endpoint: /v1/receipt
129
- return self._post_image('receipt', file_path)
@@ -1,130 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: structocr
3
- Version: 1.3.1
4
- Summary: The official Python SDK for StructOCR API - Passport, ID card, Driver License OCR, Invoice, Receipts, VIN, HIN and Container OCR.
5
- Home-page: https://structocr.com
6
- Author: StructOCR Team
7
- Author-email: support@structocr.com
8
- Project-URL: Homepage, https://structocr.com
9
- Project-URL: Documentation, https://structocr.com/developers
10
- Project-URL: Source, https://github.com/structocr/structocr-python
11
- Project-URL: Tracker, https://github.com/structocr/structocr-python/issues
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Operating System :: OS Independent
15
- Classifier: Topic :: Scientific/Engineering :: Image Recognition
16
- Requires-Python: >=3.6
17
- Description-Content-Type: text/markdown
18
- Requires-Dist: requests>=2.25.0
19
- Dynamic: author
20
- Dynamic: author-email
21
- Dynamic: classifier
22
- Dynamic: description
23
- Dynamic: description-content-type
24
- Dynamic: home-page
25
- Dynamic: project-url
26
- Dynamic: requires-dist
27
- Dynamic: requires-python
28
- Dynamic: summary
29
-
30
- # StructOCR Python SDK
31
-
32
- [![PyPI version](https://badge.fury.io/py/structocr.svg)](https://badge.fury.io/py/structocr)
33
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
34
-
35
- **The official Python client for [StructOCR](https://structocr.com).**
36
-
37
- StructOCR is a powerful API tailored for developers to extract structured data from complex documents and physical assets with high accuracy. This SDK helps you integrate **Passport OCR**, **National ID OCR**, **Driver License OCR**, **Invoice OCR**, **Receipt OCR**, **VIN OCR**, **HIN OCR**, and **Container OCR** into your Python applications in minutes.
38
-
39
- 👉 **[Get your Free API Key here](https://structocr.com)**
40
-
41
- -----
42
-
43
- ## 🚀 What's New in 1.3.1
44
-
45
- We've massively upgraded our Identity Verification engine!
46
- * **Hybrid VIZ + MRZ AI for National IDs**: The SDK now automatically cross-validates unstructured Visual Zone (VIZ) data against cryptographic Machine Readable Zone (MRZ) checksums (TD1/TD2) for zero hallucination. Raw MRZ lines are now accessible via `additional_fields`.
47
- * *Previous marine & expense additions (Receipt OCR, HIN OCR, Container OCR) remain fully supported.*
48
-
49
- Check out the [Quick Start](#quick-start) below to see how easy it is to use them!
50
-
51
- -----
52
-
53
- ## Features
54
-
55
- - **Passport OCR API**: Instantly extract MRZ, name, DOB, and expiry date from passports of 200+ countries.
56
- - **National ID OCR**: Extract regional specific fields (CNP, CPF, NIN) and raw ICAO 9303 MRZ lines with hybrid validation.
57
- - **Driver License OCR**: Extract vehicle class, license number, and personal details.
58
- - **Invoice OCR**: Extract invoice number, currency, merchant, customer, and financial totals.
59
- - **Receipt OCR**: Extract merchants, dates, line items, taxes, and totals for expense management.
60
- - **VIN OCR**: Extract VIN (Vehicle Identification Number) from windshield or engine bay images.
61
- - **HIN OCR**: Validate and extract Hull Identification Numbers from marine vessels.
62
- - **Container OCR**: Extract shipping container numbers accurately from images.
63
- - **Secure & Fast**: Enterprise-grade encryption, SOC2 compliance, and sub-second response times with zero data retention.
64
-
65
- ## Installation
66
-
67
- Install the package via pip:
68
-
69
- ```bash
70
- pip install structocr
71
- ```
72
-
73
- ## Quick Start
74
-
75
- ### 1\. Initialize the Client
76
-
77
- ```python
78
- from structocr import StructOCR
79
-
80
- # Initialize with your API Key
81
- client = StructOCR(api_key="sk_live_xxxxxxxx")
82
- ```
83
-
84
- ### 2\. Scan a Passport (Passport OCR)
85
-
86
- ```python
87
- # Pass the path to the passport image file
88
- result = client.scan_passport('./docs/passport_sample.jpg')
89
-
90
- print(f"Name: {result['data']['name']}")
91
- print(f"Passport Number: {result['data']['document_number']}")
92
- ```
93
-
94
- ### 3\. Scan Other Documents and Assets
95
-
96
- ```python
97
- # National ID OCR
98
- id_data = client.scan_national_id('./docs/id_card.png')
99
-
100
- # Driver License OCR
101
- license_data = client.scan_driver_license('./docs/license.jpg')
102
-
103
- # Invoice OCR
104
- invoice_data = client.scan_invoice('./docs/invoice.jpg')
105
-
106
- # Receipt OCR (New in 1.2.0)
107
- receipt_data = client.scan_receipt('./docs/receipt.jpg')
108
-
109
- # VIN OCR
110
- vin_data = client.scan_vin('./docs/vin.jpg')
111
-
112
- # HIN OCR (New in 1.2.0)
113
- hin_data = client.scan_hin('./docs/boat_hin.jpg')
114
-
115
- # Container OCR
116
- container_data = client.scan_container('./docs/container.jpg')
117
- ```
118
-
119
- ## Documentation
120
-
121
- For full API documentation, response examples, and error codes, please visit the [StructOCR Developer Docs](https://www.structocr.com/developers?ref=github).
122
-
123
- ## Requirements
124
-
125
- * Python 3.7+
126
- * `requests` library
127
-
128
- ## License
129
-
130
- MIT License. See [LICENSE](https://opensource.org/licenses/MIT) for details.
File without changes