Vietnam CCCD OCR Python SDK

Instantly extract data from Vietnamese Identity Cards (CCCD) using our native Python library.

Parsing Căn cước công dân (CCCD) Challenges

The Vietnamese Identity Card (Căn cước công dân), especially the newer chip-based format, poses unique OCR challenges. Accurately extracting the 12-digit personal identification number, handling complex Vietnamese diacritics (accents and tones), parsing multi-line addresses (quê quán, nơi thường trú), and scanning the 3-line MRZ on the reverse side require highly specialized computer vision models.

Why StructOCR for Vietnam

StructOCR's model is specifically trained on a large dataset of Vietnamese 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 12-digit ID mapped to the personal number field, and automate your verification workflows.

Common Use Cases in Vietnam

  • E-Wallet & Fintech Onboarding: Verify users for digital wallets, microlending apps, and payment gateways in Vietnam.
  • Telecom SIM Registration: Automate document parsing for mobile network operators complying with strict local SIM registration laws.
  • Banking Account Opening: Speed up eKYC processes for digital banks by instantly capturing and validating CCCD details.
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

# Get 200 free credits:
# 👉 https://structocr.com/register
# Initialize with your API Key
client = StructOCR("YOUR_API_KEY_HERE")

def scan_vietnam_id():
    # Note: Supports JPG, PNG, WebP (Max 4.5MB)
    # Target: Căn cước công dân (CCCD)
    image_path = "vietnam_national_id.jpg"

    try:
        print(f"Scanning {image_path}...")
        
        # The SDK handles file upload and API communication
        # It automatically detects that this is a Vietnamese 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("✅ Vietnam Extraction Successful!")
            
            # Basic Identity
            print(f"Region:      {data.get('country_code')}")
            print(f"Name:        {data.get('surname')} {data.get('given_names')}")
            
            # Critical Field: 12-digit ID Number
            print(f"CCCD Number: {data.get('personal_number')}")
            
            # Demographics
            print(f"DOB:         {data.get('date_of_birth')} ({data.get('sex')})")
            print(f"Address:     {data.get('address')}")
            
            # MRZ Extraction (Present on the back of chip-based CCCD)
            additional = data.get('additional_fields', {})
            if additional.get('mrz_line_1'):
                print("\n🔍 MRZ Data Found:")
                print(additional.get('mrz_line_1'))
                print(additional.get('mrz_line_2'))
                print(additional.get('mrz_line_3') or "")
        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_vietnam_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

  • •Vietnamese Diacritics Support: Reads complex Vietnamese tones and accents seamlessly.
  • •MRZ Extraction: Automatically parses the 3-line Machine Readable Zone (MRZ) on the reverse of the electronic CCCD.
  • •12-digit ID Extraction: Automatically extracts and validates the 12-digit personal identification number layout.
  • •Multi-line Address Support: Capable of reconstructing complex multi-line residential and origin addresses common on Vietnamese cards.
  • •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": "VNM",
    "nationality": "VIỆT NAM",
    "document_number": "079090123456",
    "card_series": "",
    "personal_number": "079090123456",
    "surname": "NGUYỄN",
    "given_names": "VĂN A",
    "sex": "M",
    "date_of_birth": "1990-01-01",
    "place_of_birth": "Quận 1, TP Hồ Chí Minh",
    "address": "Phường Bến Nghé, Quận 1, TP Hồ Chí Minh",
    "date_of_issue": "2021-05-15",
    "date_of_expiry": "2030-01-01",
    "issuing_authority": "CỤC TRƯỞNG CỤC CẢNH SÁT QUẢN LÝ HÀNH CHÍNH VỀ TRẬT TỰ XÃ HỘI",
    "additional_fields": {
      "phone_number": null,
      "tramite_number": null,
      "ejemplar": null,
      "mrz_line_1": "IDVNM079090123456<<<<<<<<<<<<<",
      "mrz_line_2": "9001014M3001018VNM<<<<<<<<<<<4",
      "mrz_line_3": "NGUYEN<<VAN<A<<<<<<<<<<<<<<<<<"
    }
  }
}

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 data protection regulations.

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

Vietnam Passport OCR with Python SDK

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

Python · Passport
Country Tutorial

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.

Python · Passport
Tutorial

Python Passport OCR API

Reliable Python Passport OCR API for high-accuracy data extraction. Upload an image for a free test! Get structured JSON output in seconds using our dedicated Python SDK. Eliminate errors.

Python · Passport
Country Tutorial

Argentina DNI OCR Python SDK

Python Tutorial: Automate KYC in Argentina. Extract Spanish text, CUIL/CUIT, and validate TD1 MRZ from DNI using StructOCR Python SDK.

Python · dni
Country Tutorial

Indian Passport OCR with Python SDK

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

Python · Passport
Country Tutorial

Thailand ID Card OCR Python SDK

Python Tutorial: Automate KYC in Thailand. Extract data from the Thai National Identity Card using StructOCR Python SDK. Supports Thai script, dual-language fields, and 13-digit Citizen ID extraction.

Python · thai id card
Tutorial

Go Weighbridge Ticket OCR API Tutorial

Build a Go weighbridge ticket OCR client. Send Base64 images and parse vehicle, material, gross, tare, net, and weight validation results.

Go · Weighbridge Ticket
Tutorial

Java Weighbridge Ticket OCR API Tutorial

Integrate a weighbridge ticket OCR API in Java. Extract ticket, vehicle, material, gross, tare, net, and review signals from images or PDFs.

Java · Weighbridge Ticket
Tutorial

Java Receipt OCR API

Tutorial: Integrate StructOCR's Receipt API into your Java enterprise applications. Upload an image for a free test! Extract line items, merchants, and taxes from POS receipts into structured JSON.

Java · Receipt
Tutorial

Go Receipt OCR API

Upload an image for a free test! Tutorial: Build scalable expense reporting apps in Go. Learn how to extract merchants, line items, and totals from POS receipts using our Golang OCR integration.

Go · Receipt

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