The Definitive Python SDK for Passport Data Extraction
Achieve 99.8%+ accuracy and sub-second latency, converting passport images directly into structured JSON.

Why Passport OCR is Difficult
Standard open-source OCR engines like Tesseract fail on real-world passport scans due to inherent complexities. Image defects such as camera glare, shadows, and non-uniform lighting degrade character recognition. Geometric distortions, including skew and rotation, misalign text regions, breaking parsing logic. The Machine Readable Zone (MRZ) itself, while standardized by ICAO 9303, requires precise parsing and checksum validation—a non-trivial task. Manually validating MRZ check digits or maintaining brittle RegEx patterns for dozens of international passport variations creates a significant engineering overhead that is both costly and error-prone.
Enterprise-Grade Extraction with StructOCR
StructOCR simplifies fragile, multi-step OCR pipelines into a single API call, ideal for processing identity documents. Our solution leverages pre-trained deep learning models optimized for specific document types, unlike generic OCR engines. The passport mrz ocr api automatically handles image pre-processing, including deskewing, denoising, and glare correction. Unlike Tesseract, which outputs unstructured text, StructOCR provides a standardized JSON with validated fields, eliminating manual parsing and format normalization. This robust solution is designed to support operations across international borders.
Production Use Cases
- Digital Onboarding (KYC): Reduce drop-off rates by pre-filling user data from Passports in < 2 seconds.
- Fraud Prevention: Detect tampered fonts or mismatched MRZ checksums automatically.
- Global Compliance: Handle Passports from 200+ jurisdictions without custom rules.
Live Demo: Passport scanner
No registration required. Upload a file to test the extraction.
Drop files here or click to browse
JPG · PNG · WebP · up to 500 files · max 4.5 MB each
Implementation: Python SDK
The official Python SDK supports both MRZ and Visual Inspection Zone (VIZ) extraction. It automatically handles file encoding and parses fields like 'Place of Birth' that aren't available in the MRZ.
Prerequisite: pip install structocr
from structocr import StructOCR
# 💰 Save 30%+ vs competitors. Get 200 free credits instantly:
# 👉 https://structocr.com/register
# Initialize with your API Key
client = StructOCR("YOUR_API_KEY_HERE")
def scan_passport():
# Note: Supports JPG, PNG, WebP (Max 4.5MB)
image_path = "passport.jpg"
try:
print(f"Scanning {image_path}...")
# The SDK handles file upload and API communication
result = client.scan_passport(image_path)
if result.get('success'):
data = result['data']
print("✅ Extraction Successful!")
# Identity Data
print(f"Passport #: {data.get('passport_number')}")
print(f"Name: {data.get('given_names')} {data.get('surname')}")
print(f"Nation: {data.get('nationality')} ({data.get('country_code')})")
# Visual Zone Specifics (Not in MRZ)
print(f"Birth Place:{data.get('place_of_birth')}")
print(f"Issued At: {data.get('place_of_issue')}")
# Dates
print(f"DOB: {data.get('date_of_birth')} ({data.get('sex')})")
print(f"Expiry: {data.get('date_of_expiry')}")
else:
print(f"❌ Extraction Failed: {result.get('error')}")
except Exception as e:
# Handle SDK or Network errors
print(f"An error occurred: {e}")
if __name__ == "__main__":
scan_passport()Technical Specs
- •Latency: < 4s (Average)
- •Uptime: 99.9% SLA
- •Security: AES-256 Encryption & SOC2 Compliant
- •Input: JPG, PNG, WebP (File Path)
- •Max File Size: 4.5MB
- •Output: JSON (Structured Data)
Key Features
- •Visual Extraction (VIZ): Parses non-MRZ data fields like Place of Birth and Issuing Authority.
- •Global Support: Optimized for 195+ countries, handling complex backgrounds and holograms.
- •Date Normalization: Returns all dates (Birth, Issue, Expiry) in a standardized YYYY-MM-DD format.
Sample JSON Output
StructOCR returns a normalized JSON object, regardless of the input image angle or quality.
{
"success": true,
"data": {
"type": "passport",
"country_code": "USA",
"nationality": "UNITED STATES",
"passport_number": "E12345678",
"surname": "DOE",
"given_names": "JOHN",
"sex": "M",
"date_of_birth": "1990-01-01",
"place_of_birth": "NEW YORK, USA",
"date_of_issue": "2020-01-01",
"date_of_expiry": "2030-01-01",
"place_of_issue": "PASSPORT AGENCY"
}
}Frequently Asked Questions
How does StructOCR compare to AWS Textract or Google Vision?
General-purpose OCR services like AWS Textract and Google Vision return raw, unstructured lines of text that require significant post-processing. StructOCR is a specialized API, pre-trained on identity documents. It directly returns a structured JSON object with validated fields like `surname` and `date_of_birth`, eliminating the need for any parsing on your end.
Do you store the uploaded images?
No. We do not store any customer data. Images are processed in-memory and are permanently deleted immediately after the OCR process is complete. Your data never touches persistent storage on our servers.
How to handle blurry images?
Our API includes a sophisticated image pre-processing engine that automatically enhances images before extraction. This includes deblurring, denoising, and contrast correction, allowing us to achieve high accuracy even on suboptimal images from mobile phone cameras.
You May Also Like
Related tutorials, platform guides, and comparisons
Morocco Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Morocco passports with a server-side integration.
Ukraine Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Ukraine passports with a server-side integration.
South Africa Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from South Africa passports with a server-side integration.
Serbia Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Serbia passports with a server-side integration.
Estonia Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Estonia passports with a server-side integration.
US Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from US passports with a server-side integration.
Kazakhstan Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Kazakhstan passports with a server-side integration.
Uganda Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Uganda passports with a server-side integration.
Ukraine Passport OCR with Node.js SDK
Use the official StructOCR Node.js SDK with TypeScript and Express to extract structured MRZ and VIZ data from Ukraine passports.
Uganda Passport OCR with Node.js SDK
Use the official StructOCR Node.js SDK with TypeScript and Express to extract structured MRZ and VIZ data from Uganda passports.
Technical Comparisons & Integrations
Explore platform integrations and competitive analysis
Add Passport OCR to Your v0 App in 5 Minutes
Step-by-step guide to integrating the StructOCR Passport scanner API into a v0 by Vercel app through a secure Next.js server route.
AWS Textract vs. StructOCR API for Indian Passport Back Page Extraction
Why generic OCR fails at parsing the back page of Indian passports, and how a dedicated KYC API instantly extracts structured addresses, PIN codes, and family details.
AWS Textract & Google Vision vs. StructOCR Passport API
Why generic cloud OCR APIs fail at structured KYC automation, and why developers choose specialized Passport APIs instead.
Add Passport OCR to Your Bolt.new App in 5 Minutes
Step-by-step guide to integrating the StructOCR Passport scanner API into a Bolt.new app. Build travel, hospitality, and global KYC flows right in your browser.
Add Passport OCR using Cursor in 5 Minutes
Step-by-step guide to integrating the StructOCR Passport scanner API using the Cursor AI code editor. Build travel, hospitality, and global KYC flows rapidly.
Extracting ECR Status & File Numbers: Generic OCR vs. StructOCR Indian Passport API
Learn why generic text extractors fail to capture critical Indian KYC fields like ECR status and File Numbers, and how a specialized API structures this data automatically.
From tutorial to production in 5 minutes.
You've seen the code. Now get your API key, grab your 200 free credits, and see it work with your own images. No credit card required.