Hong Kong SAR Passport OCR API with Python

Extract passport number, names, nationality, and validity dates from Hong Kong SAR passports with the StructOCR Python SDK, reading both MRZ and printed fields.

Extracting Data from Hong Kong SAR Passports

Passports issued by Hong Kong SAR follow the ICAO Doc 9303 data page layout with a two-line MRZ, and the issuing authority and place of birth appear only in the printed zone. Glare on the laminate and perspective make manual entry or plain-text OCR unreliable.

MRZ and Visual Zone in One Call

The Passport OCR API reads the MRZ and the printed visual zone and returns normalized fields, including place of birth and issuing authority where printed. Try it with the free passport scanner.

Common Integration Scenarios

  • Travel onboarding: Pre-fill passport details before the traveller confirms them.
  • Hotel and rental check-in: Capture guest passport data for local registration rules.
  • KYC intake: Feed extracted fields into your own verification steps.
Need more testing? Create a free account to get 200 free credits (equals 100 Passport scans).

Hong Kong SAR Passport OCR API with Python

The official Python SDK reads a local file and calls /v1/passport from your backend.

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

client = StructOCR(os.environ["STRUCTOCR_API_KEY"])
result = client.scan_passport("passport.jpg")

if result.get("success"):
    data = result["data"]
    print(data.get("document_number") or data.get("passport_number"))
    print(data.get("given_names"), data.get("surname"))
else:
    print(result.get("error"))

Technical Specs

  • •Endpoint: POST /v1/passport
  • •Input: Base64-encoded JPG, PNG, WebP, or PDF in JSON (Max 4.5MB)
  • •Authentication: Server-side x-api-key header handled by the SDK
  • •Cost: 2 credits per successful scan; failed requests are not billed
  • •Output: Structured JSON

Key Features

  • •MRZ plus visual zone: Returns fields the MRZ truncates or omits, such as place of birth.
  • •ICAO country codes: country_code uses the three-letter code printed on the passport.
  • •Validity dates: Issue and expiry dates as YYYY-MM-DD.
  • •Server-side SDK: Encodes the file and sends the request from your backend.

JSON Response Example

Fictional values showing the normalized fields for a readable Hong Kong SAR passport; unavailable fields are null.

{
  "success": true,
  "data": {
    "type": "passport",
    "country_code": "CHN",
    "nationality": "CHINESE",
    "passport_number": "P0000000",
    "surname": "DOE",
    "given_names": "ALEX",
    "sex": "X",
    "date_of_birth": "1990-01-01",
    "place_of_birth": "HONG KONG",
    "date_of_issue": "2024-05-10",
    "date_of_expiry": "2034-05-09",
    "issuing_authority": "IMMIGRATION DEPARTMENT, HKSAR"
  }
}

Frequently Asked Questions

Can I scan a PDF of a Hong Kong SAR passport?

Yes. The endpoint accepts a Base64-encoded JPG, PNG, WebP, or PDF up to 4.5MB.

Does OCR verify the passport?

No. OCR extracts readable fields; authenticity and eligibility decisions need separate controls.

Is there a version for the other SDK language?

Yes. A paired Node.js version of this tutorial covers the same document.

You May Also Like

Related tutorials, platform guides, and comparisons

Country Tutorial

China Passport OCR: Extract Fields with Python

Extract visible fields from China passport images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.

Python · Passport
Country Tutorial

Hong Kong SAR Passport OCR API with Node.js

Extract passport number, names, nationality, and validity dates from Hong Kong SAR passports with the StructOCR Node.js SDK, reading both MRZ and printed fields.

Node.js · Passport
Country Tutorial

Dominican Passport OCR API with Python

Extract passport number, names, nationality, and validity dates from Dominican passports with the StructOCR Python SDK, reading both MRZ and printed fields.

Python · Passport
Country Tutorial

Finland Passport OCR: Extract Fields with Python

Extract visible fields from Finland passport images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.

Python · Passport
Country Tutorial

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.

Python · Passport
Country Tutorial

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.

Python · Passport
Country Tutorial

UK Passport OCR with Python SDK

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

Python · Passport
Country Tutorial

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

Node.js · Passport
Country Tutorial

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

Node.js · Passport
Country Tutorial

Hungary Személyazonosító OCR Python SDK

Python Tutorial: Automate KYC in Hungary. Extract data from Személyazonosító and validate TD1 MRZ using StructOCR Python SDK. Supports native Hungarian text and accents.

Python · személyazonosító

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 No Credit Card