structocr 1.4.0__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.
- structocr-1.5.0/LICENSE +21 -0
- structocr-1.5.0/MANIFEST.in +2 -0
- structocr-1.5.0/PKG-INFO +112 -0
- structocr-1.5.0/README.md +79 -0
- structocr-1.5.0/pyproject.toml +3 -0
- {structocr-1.4.0 → structocr-1.5.0}/setup.py +13 -7
- structocr-1.5.0/structocr/__init__.py +5 -0
- structocr-1.5.0/structocr/client.py +125 -0
- structocr-1.5.0/structocr.egg-info/PKG-INFO +112 -0
- {structocr-1.4.0 → structocr-1.5.0}/structocr.egg-info/SOURCES.txt +3 -0
- structocr-1.4.0/PKG-INFO +0 -137
- structocr-1.4.0/README.md +0 -108
- structocr-1.4.0/structocr/__init__.py +0 -5
- structocr-1.4.0/structocr/client.py +0 -138
- structocr-1.4.0/structocr.egg-info/PKG-INFO +0 -137
- {structocr-1.4.0 → structocr-1.5.0}/setup.cfg +0 -0
- {structocr-1.4.0 → structocr-1.5.0}/structocr.egg-info/dependency_links.txt +0 -0
- {structocr-1.4.0 → structocr-1.5.0}/structocr.egg-info/requires.txt +0 -0
- {structocr-1.4.0 → structocr-1.5.0}/structocr.egg-info/top_level.txt +0 -0
structocr-1.5.0/LICENSE
ADDED
|
@@ -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.
|
structocr-1.5.0/PKG-INFO
ADDED
|
@@ -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
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
from setuptools import setup, find_packages
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
ROOT = Path(__file__).parent
|
|
2
6
|
|
|
3
7
|
setup(
|
|
4
8
|
name="structocr",
|
|
5
|
-
version="1.
|
|
6
|
-
description="
|
|
7
|
-
long_description=
|
|
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"),
|
|
8
12
|
long_description_content_type="text/markdown",
|
|
13
|
+
license="MIT",
|
|
14
|
+
license_files=("LICENSE",),
|
|
9
15
|
|
|
10
16
|
author="StructOCR Team",
|
|
11
17
|
author_email="support@structocr.com",
|
|
@@ -15,8 +21,8 @@ setup(
|
|
|
15
21
|
project_urls={
|
|
16
22
|
"Homepage": "https://structocr.com",
|
|
17
23
|
"Documentation": "https://structocr.com/developers",
|
|
18
|
-
"Source": "https://github.com/
|
|
19
|
-
"Tracker": "https://github.com/
|
|
24
|
+
"Source": "https://github.com/dracula911/structocr-python",
|
|
25
|
+
"Tracker": "https://github.com/dracula911/structocr-python/issues",
|
|
20
26
|
},
|
|
21
27
|
|
|
22
28
|
packages=find_packages(),
|
|
@@ -29,5 +35,5 @@ setup(
|
|
|
29
35
|
"Operating System :: OS Independent",
|
|
30
36
|
"Topic :: Scientific/Engineering :: Image Recognition",
|
|
31
37
|
],
|
|
32
|
-
python_requires='>=3.
|
|
33
|
-
)
|
|
38
|
+
python_requires='>=3.7',
|
|
39
|
+
)
|
|
@@ -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
|
structocr-1.4.0/PKG-INFO
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: structocr
|
|
3
|
-
Version: 1.4.0
|
|
4
|
-
Summary: The official Python SDK for StructOCR API - Passport, ID card, Driver License OCR, Invoice, Receipts, VIN, HIN, License plate, 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
|
-
[](https://badge.fury.io/py/structocr)
|
|
33
|
-
[](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**, **Container OCR**, and **License Plate 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.4.0
|
|
44
|
-
|
|
45
|
-
* **License Plate OCR**: We've launched a specialized ALPR engine optimized for SEA plates. It accurately extracts native scripts (Thai, Khmer, etc.), plate numbers, colors, and vehicle types without forcing foreign formatting rules.
|
|
46
|
-
* *Previous updates (Hybrid VIZ + MRZ AI for National IDs, marine & expense additions) remain fully supported.*
|
|
47
|
-
|
|
48
|
-
Check out the [Quick Start](#quick-start) below to see how easy it is to use them!
|
|
49
|
-
|
|
50
|
-
-----
|
|
51
|
-
|
|
52
|
-
## Features
|
|
53
|
-
|
|
54
|
-
- **Passport OCR API**: Instantly extract MRZ, name, DOB, and expiry date from passports of 200+ countries.
|
|
55
|
-
- **National ID OCR**: Extract regional specific fields (CNP, CPF, NIN) and raw ICAO 9303 MRZ lines with hybrid validation.
|
|
56
|
-
- **Driver License OCR**: Extract vehicle class, license number, and personal details.
|
|
57
|
-
- **License Plate OCR**: Extract SEA-optimized plate numbers, regional texts, plate colors, and vehicle types.
|
|
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
|
-
|
|
74
|
-
## Quick Start
|
|
75
|
-
|
|
76
|
-
### 1. Initialize the Client
|
|
77
|
-
|
|
78
|
-
```python
|
|
79
|
-
from structocr import StructOCR
|
|
80
|
-
|
|
81
|
-
# Initialize with your API Key
|
|
82
|
-
client = StructOCR(api_key="sk_live_xxxxxxxx")
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### 2. Scan a Passport (Passport OCR)
|
|
87
|
-
|
|
88
|
-
```python
|
|
89
|
-
# Pass the path to the passport image file
|
|
90
|
-
result = client.scan_passport('./docs/passport_sample.jpg')
|
|
91
|
-
|
|
92
|
-
print(f"Name: {result['data']['name']}")
|
|
93
|
-
print(f"Passport Number: {result['data']['document_number']}")
|
|
94
|
-
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### 3. Scan Other Documents and Assets
|
|
98
|
-
|
|
99
|
-
```python
|
|
100
|
-
# License Plate OCR (New in 1.4.0)
|
|
101
|
-
plate_data = client.scan_license_plate('./docs/license_plate.jpg')
|
|
102
|
-
|
|
103
|
-
# National ID OCR
|
|
104
|
-
id_data = client.scan_national_id('./docs/id_card.png')
|
|
105
|
-
|
|
106
|
-
# Driver License OCR
|
|
107
|
-
license_data = client.scan_driver_license('./docs/license.jpg')
|
|
108
|
-
|
|
109
|
-
# Invoice OCR
|
|
110
|
-
invoice_data = client.scan_invoice('./docs/invoice.jpg')
|
|
111
|
-
|
|
112
|
-
# Receipt OCR
|
|
113
|
-
receipt_data = client.scan_receipt('./docs/receipt.jpg')
|
|
114
|
-
|
|
115
|
-
# VIN OCR
|
|
116
|
-
vin_data = client.scan_vin('./docs/vin.jpg')
|
|
117
|
-
|
|
118
|
-
# HIN OCR
|
|
119
|
-
hin_data = client.scan_hin('./docs/boat_hin.jpg')
|
|
120
|
-
|
|
121
|
-
# Container OCR
|
|
122
|
-
container_data = client.scan_container('./docs/container.jpg')
|
|
123
|
-
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Documentation
|
|
127
|
-
|
|
128
|
-
For full API documentation, response examples, and error codes, please visit the [StructOCR Developer Docs](https://www.structocr.com/developers?ref=github).
|
|
129
|
-
|
|
130
|
-
## Requirements
|
|
131
|
-
|
|
132
|
-
* Python 3.7+
|
|
133
|
-
* `requests` library
|
|
134
|
-
|
|
135
|
-
## License
|
|
136
|
-
|
|
137
|
-
MIT License. See [LICENSE](https://opensource.org/licenses/MIT) for details.
|
structocr-1.4.0/README.md
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# StructOCR Python SDK
|
|
2
|
-
|
|
3
|
-
[](https://badge.fury.io/py/structocr)
|
|
4
|
-
[](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**, **Container OCR**, and **License Plate 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.4.0
|
|
15
|
-
|
|
16
|
-
* **License Plate OCR**: We've launched a specialized ALPR engine optimized for SEA plates. It accurately extracts native scripts (Thai, Khmer, etc.), plate numbers, colors, and vehicle types without forcing foreign formatting rules.
|
|
17
|
-
* *Previous updates (Hybrid VIZ + MRZ AI for National IDs, marine & expense additions) remain fully supported.*
|
|
18
|
-
|
|
19
|
-
Check out the [Quick Start](#quick-start) below to see how easy it is to use them!
|
|
20
|
-
|
|
21
|
-
-----
|
|
22
|
-
|
|
23
|
-
## Features
|
|
24
|
-
|
|
25
|
-
- **Passport OCR API**: Instantly extract MRZ, name, DOB, and expiry date from passports of 200+ countries.
|
|
26
|
-
- **National ID OCR**: Extract regional specific fields (CNP, CPF, NIN) and raw ICAO 9303 MRZ lines with hybrid validation.
|
|
27
|
-
- **Driver License OCR**: Extract vehicle class, license number, and personal details.
|
|
28
|
-
- **License Plate OCR**: Extract SEA-optimized plate numbers, regional texts, plate colors, and vehicle types.
|
|
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
|
-
|
|
45
|
-
## Quick Start
|
|
46
|
-
|
|
47
|
-
### 1. Initialize the Client
|
|
48
|
-
|
|
49
|
-
```python
|
|
50
|
-
from structocr import StructOCR
|
|
51
|
-
|
|
52
|
-
# Initialize with your API Key
|
|
53
|
-
client = StructOCR(api_key="sk_live_xxxxxxxx")
|
|
54
|
-
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### 2. Scan a Passport (Passport OCR)
|
|
58
|
-
|
|
59
|
-
```python
|
|
60
|
-
# Pass the path to the passport image file
|
|
61
|
-
result = client.scan_passport('./docs/passport_sample.jpg')
|
|
62
|
-
|
|
63
|
-
print(f"Name: {result['data']['name']}")
|
|
64
|
-
print(f"Passport Number: {result['data']['document_number']}")
|
|
65
|
-
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### 3. Scan Other Documents and Assets
|
|
69
|
-
|
|
70
|
-
```python
|
|
71
|
-
# License Plate OCR (New in 1.4.0)
|
|
72
|
-
plate_data = client.scan_license_plate('./docs/license_plate.jpg')
|
|
73
|
-
|
|
74
|
-
# National ID OCR
|
|
75
|
-
id_data = client.scan_national_id('./docs/id_card.png')
|
|
76
|
-
|
|
77
|
-
# Driver License OCR
|
|
78
|
-
license_data = client.scan_driver_license('./docs/license.jpg')
|
|
79
|
-
|
|
80
|
-
# Invoice OCR
|
|
81
|
-
invoice_data = client.scan_invoice('./docs/invoice.jpg')
|
|
82
|
-
|
|
83
|
-
# Receipt OCR
|
|
84
|
-
receipt_data = client.scan_receipt('./docs/receipt.jpg')
|
|
85
|
-
|
|
86
|
-
# VIN OCR
|
|
87
|
-
vin_data = client.scan_vin('./docs/vin.jpg')
|
|
88
|
-
|
|
89
|
-
# HIN OCR
|
|
90
|
-
hin_data = client.scan_hin('./docs/boat_hin.jpg')
|
|
91
|
-
|
|
92
|
-
# Container OCR
|
|
93
|
-
container_data = client.scan_container('./docs/container.jpg')
|
|
94
|
-
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
## Documentation
|
|
98
|
-
|
|
99
|
-
For full API documentation, response examples, and error codes, please visit the [StructOCR Developer Docs](https://www.structocr.com/developers?ref=github).
|
|
100
|
-
|
|
101
|
-
## Requirements
|
|
102
|
-
|
|
103
|
-
* Python 3.7+
|
|
104
|
-
* `requests` library
|
|
105
|
-
|
|
106
|
-
## License
|
|
107
|
-
|
|
108
|
-
MIT License. See [LICENSE](https://opensource.org/licenses/MIT) for details.
|
|
@@ -1,138 +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.4.0"
|
|
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
|
|
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)
|
|
130
|
-
|
|
131
|
-
def scan_license_plate(self, file_path):
|
|
132
|
-
"""
|
|
133
|
-
Scan a Vehicle License Plate (Optimized for Southeast Asia).
|
|
134
|
-
path: Path to the license plate image file.
|
|
135
|
-
Returns: Structured JSON data including plate_number, region_text, plate_color, etc.
|
|
136
|
-
"""
|
|
137
|
-
# Endpoint: /v1/license-plate
|
|
138
|
-
return self._post_image('license-plate', file_path)
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: structocr
|
|
3
|
-
Version: 1.4.0
|
|
4
|
-
Summary: The official Python SDK for StructOCR API - Passport, ID card, Driver License OCR, Invoice, Receipts, VIN, HIN, License plate, 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
|
-
[](https://badge.fury.io/py/structocr)
|
|
33
|
-
[](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**, **Container OCR**, and **License Plate 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.4.0
|
|
44
|
-
|
|
45
|
-
* **License Plate OCR**: We've launched a specialized ALPR engine optimized for SEA plates. It accurately extracts native scripts (Thai, Khmer, etc.), plate numbers, colors, and vehicle types without forcing foreign formatting rules.
|
|
46
|
-
* *Previous updates (Hybrid VIZ + MRZ AI for National IDs, marine & expense additions) remain fully supported.*
|
|
47
|
-
|
|
48
|
-
Check out the [Quick Start](#quick-start) below to see how easy it is to use them!
|
|
49
|
-
|
|
50
|
-
-----
|
|
51
|
-
|
|
52
|
-
## Features
|
|
53
|
-
|
|
54
|
-
- **Passport OCR API**: Instantly extract MRZ, name, DOB, and expiry date from passports of 200+ countries.
|
|
55
|
-
- **National ID OCR**: Extract regional specific fields (CNP, CPF, NIN) and raw ICAO 9303 MRZ lines with hybrid validation.
|
|
56
|
-
- **Driver License OCR**: Extract vehicle class, license number, and personal details.
|
|
57
|
-
- **License Plate OCR**: Extract SEA-optimized plate numbers, regional texts, plate colors, and vehicle types.
|
|
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
|
-
|
|
74
|
-
## Quick Start
|
|
75
|
-
|
|
76
|
-
### 1. Initialize the Client
|
|
77
|
-
|
|
78
|
-
```python
|
|
79
|
-
from structocr import StructOCR
|
|
80
|
-
|
|
81
|
-
# Initialize with your API Key
|
|
82
|
-
client = StructOCR(api_key="sk_live_xxxxxxxx")
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### 2. Scan a Passport (Passport OCR)
|
|
87
|
-
|
|
88
|
-
```python
|
|
89
|
-
# Pass the path to the passport image file
|
|
90
|
-
result = client.scan_passport('./docs/passport_sample.jpg')
|
|
91
|
-
|
|
92
|
-
print(f"Name: {result['data']['name']}")
|
|
93
|
-
print(f"Passport Number: {result['data']['document_number']}")
|
|
94
|
-
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### 3. Scan Other Documents and Assets
|
|
98
|
-
|
|
99
|
-
```python
|
|
100
|
-
# License Plate OCR (New in 1.4.0)
|
|
101
|
-
plate_data = client.scan_license_plate('./docs/license_plate.jpg')
|
|
102
|
-
|
|
103
|
-
# National ID OCR
|
|
104
|
-
id_data = client.scan_national_id('./docs/id_card.png')
|
|
105
|
-
|
|
106
|
-
# Driver License OCR
|
|
107
|
-
license_data = client.scan_driver_license('./docs/license.jpg')
|
|
108
|
-
|
|
109
|
-
# Invoice OCR
|
|
110
|
-
invoice_data = client.scan_invoice('./docs/invoice.jpg')
|
|
111
|
-
|
|
112
|
-
# Receipt OCR
|
|
113
|
-
receipt_data = client.scan_receipt('./docs/receipt.jpg')
|
|
114
|
-
|
|
115
|
-
# VIN OCR
|
|
116
|
-
vin_data = client.scan_vin('./docs/vin.jpg')
|
|
117
|
-
|
|
118
|
-
# HIN OCR
|
|
119
|
-
hin_data = client.scan_hin('./docs/boat_hin.jpg')
|
|
120
|
-
|
|
121
|
-
# Container OCR
|
|
122
|
-
container_data = client.scan_container('./docs/container.jpg')
|
|
123
|
-
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Documentation
|
|
127
|
-
|
|
128
|
-
For full API documentation, response examples, and error codes, please visit the [StructOCR Developer Docs](https://www.structocr.com/developers?ref=github).
|
|
129
|
-
|
|
130
|
-
## Requirements
|
|
131
|
-
|
|
132
|
-
* Python 3.7+
|
|
133
|
-
* `requests` library
|
|
134
|
-
|
|
135
|
-
## License
|
|
136
|
-
|
|
137
|
-
MIT License. See [LICENSE](https://opensource.org/licenses/MIT) for details.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|