US Passport OCR with the StructOCR Python SDK

Install the official Python SDK, extract validated US passport fields, and add the same workflow to a FastAPI service.

AI extracting data from a US passport
StructOCR engine analyzing a United States document in real-time.

Challenges with US Passport Verification

Extracting accurate information from US passports presents unique challenges, including complex background patterns, holographic security features, and variations in lighting across different capture devices. These factors can significantly hinder manual data entry and traditional OCR methods, making a specialized passport extraction api essential for reliable processing.

Why StructOCR for US Passports

StructOCR offers unparalleled accuracy for US passport data extraction, thanks to our advanced machine learning models trained on a vast dataset. Our solution is specifically engineered to overcome the common obstacles found in these documents, including Next Generation Passports (NGP). Whether you need a powerful passport extraction api or a comprehensive fintech identity verification software, StructOCR delivers robust performance. For the fastest Python integration, install the official StructOCR SDK and see the Python SDK documentation.

Built for High-Compliance Industries

  • Travel & Aviation: Our technology serves as a critical verification solution for travel, enabling faster check-ins, TSA pre-check integrations, and border control processes for US citizens. This speeds up passenger throughput and enhances the overall travel experience.
  • Financial Services: By integrating our sophisticated fintech identity verification software, financial institutions can automate their KYC onboarding workflows with confidence, ensuring compliance with US regulations like the Patriot Act. This reduces manual review times and mitigates fraud risk.

Live Demo: Passport scanner

No registration required. Upload a file to test the extraction.

1
Upload
2
Results

Drop files here or click to browse

JPG · PNG · WebP  ·  up to 500 files · max 4.5 MB each

No files selected
Need more testing? Create a free account to get 200 free credits (equals 100 Passport scans).

US Passport OCR with the Python SDK

The official Python SDK handles file encoding, API communication, and structured passport results. Use the SDK directly or open the FastAPI tab for a server endpoint. Keep your API key in STRUCTOCR_API_KEY.

Prerequisite: `pip install structocr`; set the server-side `STRUCTOCR_API_KEY` environment variable.

Prefer another stack? Open the Node.js SDK + Express integration.

import os
from structocr import StructOCR

# Initialize StructOCR Client
client = StructOCR(os.environ["STRUCTOCR_API_KEY"])

def scan_us_passport():
    image_path = "us_passport_sample.jpg"

    try:
        print(f"Scanning {image_path}...")
        result = client.scan_passport(image_path)

        if result.get('success'):
            data = result['data']
            print("✅ Passport Extraction Successful!")
            print(f"Passport #:  {data.get('passport_number')}")
            print(f"Name:        {data.get('given_names')} {data.get('surname')}")
            print(f"Nationality: {data.get('nationality')}")
            print(f"DOB:         {data.get('date_of_birth')}")
        else:
            print(f"❌ Extraction Failed: {result.get('error')}")

    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    scan_us_passport()

Technical Specs

  • Latency: < 4s (Average)
  • Uptime: 99.9% SLA
  • Security: AES-256 Encryption & SOC2 Compliant
  • Input: JPG, PNG, WebP, PDF (Max 4.5MB)
  • Output: JSON (Structured Data)

Key Features

  • Document Localization: Auto-detects passport boundaries and cropping.
  • Visual Extraction (VIZ): Reliably extracts data directly from the visual inspection zone.
  • Glare Reduction: Automatically corrects lighting issues and reflections common with NGP polycarbonate pages.
  • MRZ Parsing: Validates and cross-references data with the Machine Readable Zone.

JSON Response Example

The Python SDK returns a dictionary matching this normalized JSON structure.

{
  "success": true,
  "data": {
    "type": "passport",
    "country_code": "USA",
    "nationality": "USA",
    "passport_number": "123456789",
    "surname": "DOE",
    "given_names": "JOHN",
    "sex": "M",
    "date_of_birth": "1985-05-15",
    "place_of_birth": "NEW YORK, U.S.A.",
    "date_of_issue": "2020-05-15",
    "date_of_expiry": "2030-05-14",
    "issuing_authority": "UNITED STATES DEPARTMENT OF STATE"
  }
}

Frequently Asked Questions

Is there an official SDK for Node.js?

Yes. StructOCR publishes official Python and Node.js SDKs. Installation links and source documentation are available in the Developer SDK section. Other languages can use the REST API.

Does it work with older passport formats?

Yes, our ocr passport sdk is trained to handle both legacy and modern passport layouts globally, including both traditional and Next Generation US Passports.

You May Also Like

Related tutorials, platform guides, and comparisons

Country Tutorial

South Korea Passport OCR with Python SDK

Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from South Korea passports with a server-side integration.

Python · Passport
Country Tutorial

Saudi Arabia Passport OCR with Python SDK

Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Saudi Arabia passports with a server-side integration.

Python · Passport
Country Tutorial

Tunisia Passport OCR with Python SDK

Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Tunisia passports with a server-side integration.

Python · Passport
Country Tutorial

Mexico Passport OCR with Python SDK

Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Mexico passports with a server-side integration.

Python · Passport
Country Tutorial

France Passport OCR with Python SDK

Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from France passports with a server-side integration.

Python · Passport
Country Tutorial

Spain Passport OCR with Python SDK

Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Spain passports with a server-side integration.

Python · Passport
Country Tutorial

Singapore Passport OCR with Python SDK

Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Singapore passports with a server-side integration.

Python · Passport
Country Tutorial

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.

Python · Passport
Country Tutorial

Singapore 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 Singapore passports.

Node.js · Passport
Country Tutorial

Slovakia 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 Slovakia passports.

Node.js · Passport

Technical Comparisons & Integrations

Explore platform integrations and competitive analysis

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.

Instant Access Cancel Anytime 99.9% Uptime