structocr 1.1.1__py3-none-any.whl

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/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .client import StructOCR
2
+
3
+ __all__ = ['StructOCR']
structocr/client.py ADDED
@@ -0,0 +1,92 @@
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
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
83
+ return self._post_image('driver-license', file_path)
84
+
85
+ def scan_driver_license(self, file_path):
86
+ """
87
+ Scan a Invoice.
88
+ path: Path to the invoice image file.
89
+ Returns: Structured JSON data.
90
+ """
91
+ # Endpoint: /v1/invoice
92
+ return self._post_image('invoice', file_path)
@@ -0,0 +1,92 @@
1
+ Metadata-Version: 2.1
2
+ Name: structocr
3
+ Version: 1.1.1
4
+ Summary: The official Python SDK for StructOCR API - Passport, ID card, Driver License OCR, and Invoice.
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://www.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
+
20
+ # StructOCR Python SDK
21
+
22
+ [![PyPI version](https://badge.fury.io/py/structocr.svg)](https://badge.fury.io/py/structocr)
23
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
24
+
25
+ **The official Python client for [StructOCR](https://structocr.com).**
26
+
27
+ 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.
28
+
29
+ 👉 **[Get your Free API Key here](https://structocr.com)**
30
+
31
+ ## Features
32
+
33
+ - **Passport OCR API**: Instantly extract MRZ, name, DOB, and expiry date from passports of 200+ countries.
34
+ - **National ID OCR**: Support for ID cards with automatic field mapping.
35
+ - **Driver License OCR**: Extract vehicle class, license number, and personal details.
36
+ - **Secure & Fast**: Enterprise-grade encryption and sub-second response times.
37
+
38
+ ## Installation
39
+
40
+ Install the package via pip:
41
+
42
+ ```bash
43
+ pip install structocr
44
+
45
+ ```
46
+
47
+ ## Quick Start
48
+
49
+ ### 1. Initialize the Client
50
+
51
+ ```python
52
+ from structocr import StructOCR
53
+
54
+ # Initialize with your API Key
55
+ client = StructOCR(api_key="sk_live_xxxxxxxx")
56
+
57
+ ```
58
+
59
+ ### 2. Scan a Passport (Passport OCR)
60
+
61
+ ```python
62
+ # Pass the path to the passport image file
63
+ result = client.scan_passport('./docs/passport_sample.jpg')
64
+
65
+ print(f"Name: {result['data']['name']}")
66
+ print(f"Passport Number: {result['data']['document_number']}")
67
+
68
+ ```
69
+
70
+ ### 3. Scan a National ID or Driver License
71
+
72
+ ```python
73
+ # National ID OCR
74
+ id_data = client.scan_national_id('./docs/id_card.png')
75
+
76
+ # Driver License OCR
77
+ license_data = client.scan_driver_license('./docs/license.jpg')
78
+
79
+ ```
80
+
81
+ ## Documentation
82
+
83
+ For full API documentation, response examples, and error codes, please visit the [StructOCR Developer Docs](https://www.structocr.com/developers?ref=github).
84
+
85
+ ## Requirements
86
+
87
+ * Python 3.6+
88
+ * `requests` library
89
+
90
+ ## License
91
+
92
+ MIT License. See [LICENSE](https://www.google.com/search?q=LICENSE) for details.
@@ -0,0 +1,6 @@
1
+ structocr/__init__.py,sha256=q0dim8G5HQBYxPY6nSv9zkz1UMbAsvmmTseENFBNubc,54
2
+ structocr/client.py,sha256=vqXvJq-6_enyHEPvrmPsXpMRqBo0zhQ5tFLubmW6UN0,3012
3
+ structocr-1.1.1.dist-info/METADATA,sha256=f9CS0F9gDXENgD6szMch9sRR_znZkF06oLCjgAlL25I,2860
4
+ structocr-1.1.1.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
5
+ structocr-1.1.1.dist-info/top_level.txt,sha256=r71IAG7a0LhuKvYrrZDO-2QVLYuT-Dzyle4k4gHFJQw,10
6
+ structocr-1.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.38.4)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ structocr