Thailand ID Card OCR Python SDK
Instantly extract data from Thai National Identity Cards using our native Python library.
Parsing Thai ID Card Challenges
The Thai National Identity Card (บัตรประจำตัวประชาชนไทย) poses unique OCR challenges. Accurately extracting the 13-digit Citizen Identification Number, handling complex Thai script (with specific vowels and tone marks) alongside English translations, and parsing highly detailed multi-line addresses (including Moo, Soi, and Tambon) require highly specialized computer vision models.
Why StructOCR for Thailand
StructOCR's model is specifically trained on a large dataset of Thai ID images, ensuring high accuracy for national id ocr extraction. The Python SDK simplifies the integration process with just a few lines of code, allowing you to instantly extract structural data, including the 13-digit Citizen ID mapped to the personal number field, and automate your verification workflows.
Common Use Cases in Thailand
- E-Wallet & PromptPay Onboarding: Verify users for digital wallets, payment gateways, and microlending apps in Thailand.
- Crypto & Digital Asset KYC: Automate compliant user identity verification for digital asset exchanges operating under Thai SEC regulations.
- Telecom SIM Registration: Speed up mobile SIM card registrations by instantly capturing customer identity data complying with NBTC laws.
Python SDK Integration
Install the SDK via pip: `pip install structocr`. Then use the following code.
Prerequisite: Python 3.6+ and `structocr` library installed.
from structocr import StructOCR
# Get 200 free credits:
# 👉 https://structocr.com/register
# Initialize with your API Key
client = StructOCR("YOUR_API_KEY_HERE")
def scan_thailand_id():
# Note: Supports JPG, PNG, WebP (Max 4.5MB)
# Target: Thai National Identity Card
image_path = "thailand_national_id.jpg"
try:
print(f"Scanning {image_path}...")
# The SDK handles file upload and API communication
# It automatically detects that this is a Thai document
result = client.scan_national_id(image_path)
# Check success flag (SDK returns a dict matching the JSON response)
if result.get('success'):
data = result['data']
print("✅ Thailand Extraction Successful!")
# Basic Identity
print(f"Region: {data.get('country_code')}")
print(f"Name: {data.get('given_names')} {data.get('surname')}")
# Critical Field: 13-digit Citizen ID
print(f"Citizen ID: {data.get('personal_number')}")
# Demographics
print(f"DOB: {data.get('date_of_birth')} ({data.get('sex')})")
print(f"Address: {data.get('address')}")
# Additional Fields
additional = data.get('additional_fields', {})
if additional.get('laser_code') or additional.get('mrz_line_1'):
print("\n🔍 Additional Data Found.")
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_thailand_id()Technical Specs
- •Latency: < 4s (Average)
- •Availability: Served from Cloudflare's global edge network
- •Security: AES-256 Encryption & SOC2 Compliant
- •Input: JPG, PNG, WebP (Max 4.5MB)
- •Output: JSON (Structured Data)
Key Features
- •Native Thai Script Support: Reads complex Thai characters, vowels, and tone marks seamlessly alongside English text.
- •13-digit Citizen ID Extraction: Automatically extracts and structure-validates the 13-digit Thai National ID number.
- •Multi-line Address Support: Capable of reconstructing complex Thai addresses including sub-districts (Tambon) and districts (Amphoe).
- •Buddhist Era (BE) Date Normalization: Automatically converts Thai BE dates (e.g., 2533) into the standard Gregorian `YYYY-MM-DD` format.
- •Smart Crop & Blur Detection: Rejects blurry images and removes background noise automatically.
JSON Response Example
The SDK returns a Python dictionary matching this JSON structure.
{
"success": true,
"data": {
"type": "national_id",
"country_code": "THA",
"nationality": "THAI",
"document_number": "1234567890123",
"card_series": "",
"personal_number": "1234567890123",
"surname": "SANTISUK",
"given_names": "SOMCHAI",
"sex": "M",
"date_of_birth": "1990-04-15",
"place_of_birth": "BANGKOK",
"address": "123/45 Moo 6, Tambon Bang Khen, Amphoe Mueang, Nonthaburi",
"date_of_issue": "2021-04-14",
"date_of_expiry": "2030-04-14",
"issuing_authority": "BORA / DOPA",
"additional_fields": {
"phone_number": null,
"tramite_number": null,
"ejemplar": null,
"mrz_line_1": null,
"mrz_line_2": null,
"mrz_line_3": null
}
}
}Frequently Asked Questions
Does the Python SDK handle image uploads?
Yes, the SDK automatically handles base64 encoding and file uploads.
Is data stored?
Only briefly. Uploaded images and results are kept for at most 24 hours for quality spot-checks, then deleted, which helps with Thailand's PDPA and global data protection laws.
How to handle errors?
The SDK result dictionary contains a 'success' boolean and an 'error' code (e.g., FILE_TOO_LARGE) if failed.
You May Also Like
Related tutorials, platform guides, and comparisons
Thailand Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Thailand passports with a server-side integration.
Philippines UMID OCR Python SDK
Python Tutorial: Automate KYC in Philippines. Extract data from UMID using StructOCR Python SDK. Supports native text.
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.
Ukraine National ID OCR Python SDK
Python Tutorial: Automate KYC in Ukraine. Extract data from National ID using StructOCR Python SDK. Supports native text and MRZ extraction.
Brazil CIN OCR Python SDK: Extract CPF & MRZ
Python Tutorial: Automate KYC in Brazil. Extract Portuguese text, CPF numbers, and validate TD1 MRZ from the new CIN using the StructOCR Python SDK.
Bangladesh Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Bangladesh passports with a server-side integration.
Tanzania NIDA Card OCR Python SDK
Python Tutorial: Automate KYC in Tanzania. Extract data from NIDA Card using StructOCR Python SDK. Supports native text and MRZ extraction.
Uzbekistan ID Karta OCR Python SDK
Python Tutorial: Automate KYC in Uzbekistan. Extract data from ID Karta using StructOCR Python SDK. Supports native text and MRZ parsing.
Tajikistan ID Card (Karta) OCR Python SDK
Python Tutorial: Automate KYC in Tajikistan. Extract data from ID Card (Karta) using StructOCR Python SDK. Supports native text and MRZ extraction.
UAE Emirates ID OCR Python SDK
Python Tutorial: Automate KYC in the UAE. Extract data from Emirates ID using the StructOCR Python SDK. Supports bilingual (Arabic/English) text, front/back sides, and 3-line MRZ extraction.
Technical Comparisons & Integrations
Explore platform integrations and competitive analysis
Add Invoice OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR invoice API into a Lovable.dev app. No backend required — just paste a prompt and add your API key.
Add National ID OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a Lovable.dev app. Build KYC and identity verification flows with zero backend.
Add Passport OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR Passport scanner API into a Lovable.dev app through a secure server-side function for travel and KYC flows.
Add Receipt OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR receipt API into a Lovable.dev app. No backend required — just paste a prompt and add your API key.
Add VIN OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR VIN scanner API into a Lovable.dev app. Build automotive and fleet tools with zero backend required.
Manual TOS Entry vs. Container OCR Automation API
Analyzing the ROI and operational efficiency of replacing manual gate checkers with an automated Container OCR API in logistics yards.
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.