Vietnam CCCD OCR Python SDK

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

AI extracting data from a Vietnam ID card
StructOCR engine analyzing a Vietnamese Căn cước công dân (CCCD) in real-time.

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.

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

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

Bulgaria Passport OCR with Python SDK

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

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

Bulgaria Lichna karta (Лична карта) OCR Python SDK

Python Tutorial: Automate KYC in Bulgaria. Extract Cyrillic/Latin text, EGN (ЕГН), and validate TD1 MRZ from Lichna karta using StructOCR Python SDK.

Python · lichna karta (лична карта)
Country Tutorial

Belgium eID OCR Python SDK

Python Tutorial: Automate KYC in Belgium. Extract data from Electronic Identity Card (eID) using StructOCR Python SDK. Supports native text, National Register Number, and MRZ extraction.

Python · eid

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