Thailand ID Card OCR Python SDK

Instantly extract data from Thai National Identity Cards using our native Python library.

AI extracting data from a Thailand ID card
StructOCR engine analyzing a Thai National Identity Card in real-time.

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.

Live Demo: ID card 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 National ID scans).

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

# 💰 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_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)
  • Uptime: 99.9% SLA
  • 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?

No. Images are processed in-memory and deleted immediately to comply 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

Country Tutorial

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.

Python · Passport
Country Tutorial

Philippines UMID OCR Python SDK

Python Tutorial: Automate KYC in Philippines. Extract data from UMID using StructOCR Python SDK. Supports native text.

Python · umid
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

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.

Python · National ID
Country Tutorial

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.

Python · carteira de identidade (cin)
Country Tutorial

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.

Python · Passport
Country Tutorial

Vietnam CCCD OCR Python SDK

Python Tutorial: Automate KYC in Vietnam. Extract data from the Vietnamese Identity Card (Căn cước công dân / CCCD) using StructOCR Python SDK. Supports native text, diacritics, and MRZ extraction.

Python · cccd
Country Tutorial

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.

Python · id karta
Country Tutorial

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.

Python · id card (karta)
Country Tutorial

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.

Python · emirates id

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