structocr 1.0.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,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: structocr
3
+ Version: 1.0.0
4
+ Summary: The official Python SDK for StructOCR API - Passport, ID, and Driver License OCR.
5
+ Home-page: https://github.com/structocr/structocr-python
6
+ Author: StructOCR Team
7
+ Author-email: support@structocr.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: requests>=2.25.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: requires-dist
22
+ Dynamic: requires-python
23
+ Dynamic: summary
24
+
25
+ # StructOCR Python SDK
26
+
27
+ [![PyPI version](https://badge.fury.io/py/structocr.svg)](https://badge.fury.io/py/structocr)
28
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
29
+
30
+ **The official Python client for [StructOCR](https://structocr.com).**
31
+
32
+ StructOCR is a powerful API tailored for developers to extract structured data from identity documents with high accuracy. This SDK helps you integrate **Passport OCR**, **National ID OCR**, and **Driver License OCR** into your Python applications in minutes.
33
+
34
+ 👉 **[Get your Free API Key here](https://structocr.com)**
35
+
36
+ ## Features
37
+
38
+ - **Passport OCR API**: Instantly extract MRZ, name, DOB, and expiry date from passports of 200+ countries.
39
+ - **National ID OCR**: Support for ID cards with automatic field mapping.
40
+ - **Driver License OCR**: Extract vehicle class, license number, and personal details.
41
+ - **Secure & Fast**: Enterprise-grade encryption and sub-second response times.
42
+
43
+ ## Installation
44
+
45
+ Install the package via pip:
46
+
47
+ ```bash
48
+ pip install structocr
49
+
50
+ ```
51
+
52
+ ## Quick Start
53
+
54
+ ### 1. Initialize the Client
55
+
56
+ ```python
57
+ from structocr import StructOCR
58
+
59
+ # Initialize with your API Key
60
+ client = StructOCR(api_key="sk_live_xxxxxxxx")
61
+
62
+ ```
63
+
64
+ ### 2. Scan a Passport (Passport OCR)
65
+
66
+ ```python
67
+ # Pass the path to the passport image file
68
+ result = client.scan_passport('./docs/passport_sample.jpg')
69
+
70
+ print(f"Name: {result['data']['name']}")
71
+ print(f"Passport Number: {result['data']['document_number']}")
72
+
73
+ ```
74
+
75
+ ### 3. Scan a National ID or Driver License
76
+
77
+ ```python
78
+ # National ID OCR
79
+ id_data = client.scan_national_id('./docs/id_card.png')
80
+
81
+ # Driver License OCR
82
+ license_data = client.scan_driver_license('./docs/license.jpg')
83
+
84
+ ```
85
+
86
+ ## Documentation
87
+
88
+ For full API documentation, response examples, and error codes, please visit the [StructOCR Developer Docs](https://www.structocr.com/developers?ref=github).
89
+
90
+ ## Requirements
91
+
92
+ * Python 3.6+
93
+ * `requests` library
94
+
95
+ ## License
96
+
97
+ MIT License. See [LICENSE](https://www.google.com/search?q=LICENSE) for details.
98
+
99
+ ```
@@ -0,0 +1,75 @@
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 identity documents with high accuracy. This SDK helps you integrate **Passport OCR**, **National ID OCR**, and **Driver License OCR** into your Python applications in minutes.
9
+
10
+ 👉 **[Get your Free API Key here](https://structocr.com)**
11
+
12
+ ## Features
13
+
14
+ - **Passport OCR API**: Instantly extract MRZ, name, DOB, and expiry date from passports of 200+ countries.
15
+ - **National ID OCR**: Support for ID cards with automatic field mapping.
16
+ - **Driver License OCR**: Extract vehicle class, license number, and personal details.
17
+ - **Secure & Fast**: Enterprise-grade encryption and sub-second response times.
18
+
19
+ ## Installation
20
+
21
+ Install the package via pip:
22
+
23
+ ```bash
24
+ pip install structocr
25
+
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ### 1. Initialize the Client
31
+
32
+ ```python
33
+ from structocr import StructOCR
34
+
35
+ # Initialize with your API Key
36
+ client = StructOCR(api_key="sk_live_xxxxxxxx")
37
+
38
+ ```
39
+
40
+ ### 2. Scan a Passport (Passport OCR)
41
+
42
+ ```python
43
+ # Pass the path to the passport image file
44
+ result = client.scan_passport('./docs/passport_sample.jpg')
45
+
46
+ print(f"Name: {result['data']['name']}")
47
+ print(f"Passport Number: {result['data']['document_number']}")
48
+
49
+ ```
50
+
51
+ ### 3. Scan a National ID or Driver License
52
+
53
+ ```python
54
+ # National ID OCR
55
+ id_data = client.scan_national_id('./docs/id_card.png')
56
+
57
+ # Driver License OCR
58
+ license_data = client.scan_driver_license('./docs/license.jpg')
59
+
60
+ ```
61
+
62
+ ## Documentation
63
+
64
+ For full API documentation, response examples, and error codes, please visit the [StructOCR Developer Docs](https://www.structocr.com/developers?ref=github).
65
+
66
+ ## Requirements
67
+
68
+ * Python 3.6+
69
+ * `requests` library
70
+
71
+ ## License
72
+
73
+ MIT License. See [LICENSE](https://www.google.com/search?q=LICENSE) for details.
74
+
75
+ ```
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,23 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="structocr",
5
+ version="1.0.0",
6
+ description="The official Python SDK for StructOCR API - Passport, ID, and Driver License OCR.",
7
+ long_description=open("README.md").read(),
8
+ long_description_content_type="text/markdown",
9
+ author="StructOCR Team",
10
+ author_email="support@structocr.com",
11
+ url="https://github.com/structocr/structocr-python", # 记得换成你未来的 github 地址
12
+ packages=find_packages(),
13
+ install_requires=[
14
+ "requests>=2.25.0",
15
+ ],
16
+ classifiers=[
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Topic :: Scientific/Engineering :: Image Recognition", # 这是一个很好的分类标签
21
+ ],
22
+ python_requires='>=3.6',
23
+ )
@@ -0,0 +1,3 @@
1
+ from .client import StructOCR
2
+
3
+ __all__ = ['StructOCR']
@@ -0,0 +1,83 @@
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.0.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
+ """
73
+ # Endpoint: /v1/national-id (Assuming this is your endpoint naming)
74
+ return self._post_image('national-id', file_path)
75
+
76
+ def scan_driver_license(self, file_path):
77
+ """
78
+ Scan a Driver License.
79
+ path: Path to the driver license image file.
80
+ Returns: Structured JSON data.
81
+ """
82
+ # Endpoint: /v1/driver-license (Assuming this is your endpoint naming)
83
+ return self._post_image('driver-license', file_path)
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: structocr
3
+ Version: 1.0.0
4
+ Summary: The official Python SDK for StructOCR API - Passport, ID, and Driver License OCR.
5
+ Home-page: https://github.com/structocr/structocr-python
6
+ Author: StructOCR Team
7
+ Author-email: support@structocr.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: requests>=2.25.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: requires-dist
22
+ Dynamic: requires-python
23
+ Dynamic: summary
24
+
25
+ # StructOCR Python SDK
26
+
27
+ [![PyPI version](https://badge.fury.io/py/structocr.svg)](https://badge.fury.io/py/structocr)
28
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
29
+
30
+ **The official Python client for [StructOCR](https://structocr.com).**
31
+
32
+ StructOCR is a powerful API tailored for developers to extract structured data from identity documents with high accuracy. This SDK helps you integrate **Passport OCR**, **National ID OCR**, and **Driver License OCR** into your Python applications in minutes.
33
+
34
+ 👉 **[Get your Free API Key here](https://structocr.com)**
35
+
36
+ ## Features
37
+
38
+ - **Passport OCR API**: Instantly extract MRZ, name, DOB, and expiry date from passports of 200+ countries.
39
+ - **National ID OCR**: Support for ID cards with automatic field mapping.
40
+ - **Driver License OCR**: Extract vehicle class, license number, and personal details.
41
+ - **Secure & Fast**: Enterprise-grade encryption and sub-second response times.
42
+
43
+ ## Installation
44
+
45
+ Install the package via pip:
46
+
47
+ ```bash
48
+ pip install structocr
49
+
50
+ ```
51
+
52
+ ## Quick Start
53
+
54
+ ### 1. Initialize the Client
55
+
56
+ ```python
57
+ from structocr import StructOCR
58
+
59
+ # Initialize with your API Key
60
+ client = StructOCR(api_key="sk_live_xxxxxxxx")
61
+
62
+ ```
63
+
64
+ ### 2. Scan a Passport (Passport OCR)
65
+
66
+ ```python
67
+ # Pass the path to the passport image file
68
+ result = client.scan_passport('./docs/passport_sample.jpg')
69
+
70
+ print(f"Name: {result['data']['name']}")
71
+ print(f"Passport Number: {result['data']['document_number']}")
72
+
73
+ ```
74
+
75
+ ### 3. Scan a National ID or Driver License
76
+
77
+ ```python
78
+ # National ID OCR
79
+ id_data = client.scan_national_id('./docs/id_card.png')
80
+
81
+ # Driver License OCR
82
+ license_data = client.scan_driver_license('./docs/license.jpg')
83
+
84
+ ```
85
+
86
+ ## Documentation
87
+
88
+ For full API documentation, response examples, and error codes, please visit the [StructOCR Developer Docs](https://www.structocr.com/developers?ref=github).
89
+
90
+ ## Requirements
91
+
92
+ * Python 3.6+
93
+ * `requests` library
94
+
95
+ ## License
96
+
97
+ MIT License. See [LICENSE](https://www.google.com/search?q=LICENSE) for details.
98
+
99
+ ```
@@ -0,0 +1,9 @@
1
+ README.md
2
+ setup.py
3
+ structocr/__init__.py
4
+ structocr/client.py
5
+ structocr.egg-info/PKG-INFO
6
+ structocr.egg-info/SOURCES.txt
7
+ structocr.egg-info/dependency_links.txt
8
+ structocr.egg-info/requires.txt
9
+ structocr.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ requests>=2.25.0
@@ -0,0 +1 @@
1
+ structocr