Kenya National ID (Maisha Card) OCR Python SDK

Instantly extract visual data, Maisha Namba, and validate cryptographic MRZ checksums from Kenyan IDs using our native Python library.

AI extracting data, Maisha Namba, and TD1 MRZ from a Kenya Maisha Card
StructOCR engine analyzing a Kenyan Maisha Card and cross-validating the ICAO MRZ in real-time.

Parsing National ID (Maisha Card) Challenges

Extracting data from the Kenya National ID (Maisha Card) presents unique challenges. First, the print quality on some cards can be inconsistent, leading to blurred or distorted characters that are difficult for standard OCR engines to recognize. Second, navigating the layout differences between legacy laminated IDs and the 3rd-generation Maisha smart cards requires high adaptability. Finally, ensuring document authenticity requires reliably locating and strictly parsing the Machine-Readable Zone (MRZ) on the back of the modern card to avoid engineering overhead.

Why StructOCR for Kenya

StructOCR's model is specifically trained on a vast dataset of Kenyan National ID (Maisha Card) variations. This ensures high accuracy even with low-quality prints and layout differences. Our Python SDK simplifies integration into your existing systems, providing a clean id parsing api for uploading images and receiving structured data in JSON format. Specifically designed to handle the 14 digits structure of Kenyan IDs and decode its embedded MRZ, it effectively minimizes development time and complexity.

Common Use Cases in Kenya

  • Digital Onboarding: Verify users for Fintech apps in Kenya by pre-filling the Maisha Namba and matching VIZ data against the cryptographic MRZ.
  • Telecom Registration: Automate SIM card registration with National ID (Maisha Card) compliant with local regulations.
  • Hotel Check-in: Speed up guest registration workflows with automated MRZ scanning.

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`. The SDK automatically maps Kenya-specific fields (like Maisha Namba) and extracts the raw TD1 MRZ block.

Prerequisite: Python 3.6+ and `structocr` library installed.

from structocr import StructOCR

# 🔑 Need a key for Kenya? Get 200 free credits instantly:
# 👉 https://structocr.com/register
# Initialize with your API Key
client = StructOCR("YOUR_API_KEY_HERE")

def scan_kenya_id():
    # Note: Supports JPG, PNG, WebP (Max 4.5MB)
    # Target: National ID (Maisha Card)
    image_path = "kenya_national_id.jpg"

    try:
        print(f"Scanning {image_path}...")
        
        # The SDK handles file upload and API communication
        result = client.scan_national_id(image_path)

        if result.get('success'):
            data = result['data']
            print("✅ Kenya Extraction Successful!")
            
            # Basic Identity
            print(f"Region:      {data.get('country_code')} (Series: {data.get('card_series')})")
            print(f"Name:        {data.get('given_names')} {data.get('surname')}")
            print(f"ID Number:   {data.get('document_number')}")
            
            # Critical Field: Maisha Namba (Personal Identity Number)
            print(f"Personal #:  {data.get('personal_number')}")
            
            # Demographics
            print(f"DOB:         {data.get('date_of_birth')} ({data.get('sex')})")
            print(f"Address:     {data.get('address')}")
            
            # Extract TD1 MRZ Data
            additional = data.get('additional_fields', {})
            if additional.get('mrz_line_1'):
                print("\n🔍 MRZ Data Extracted & Validated:")
                print(f"Line 1: {additional.get('mrz_line_1')}")
                print(f"Line 2: {additional.get('mrz_line_2')}")
                print(f"Line 3: {additional.get('mrz_line_3')}")
        else:
            print(f"❌ Extraction Failed: {result.get('error')}")

    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    scan_kenya_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 + MRZ Block)

Key Features

  • Maisha Namba Extraction: Automatically extracts and maps the lifelong Unique Personal Identifier (UPI) directly to the personal number field.
  • Hybrid VIZ + MRZ AI: Cross-validates unstructured visual data against cryptographic TD1 MRZ checksums for bulletproof identity security.
  • Blur Detection: Automatically flags and rejects blurry images from unoptimized mobile phone capture.
  • Smart Crop: Removes background noise and deskews rotated images automatically.

JSON Response Example

The SDK returns a Python dictionary containing the parsed visual data (VIZ), the Maisha Namba, and the raw Machine-Readable Zone (MRZ) block.

{
  "success": true,
  "data": {
    "type": "national_id",
    "country_code": "KEN",
    "nationality": "KENYAN",
    "document_number": "12345678",
    "card_series": "",
    "personal_number": "12345678",
    "surname": "ODHIAMBO",
    "given_names": "JAPHETH",
    "sex": "M",
    "date_of_birth": "1990-05-15",
    "place_of_birth": "NAIROBI",
    "address": "P.O. BOX 100, NAIROBI, KENYA",
    "date_of_issue": "2020-01-01",
    "date_of_expiry": "2030-01-01",
    "issuing_authority": "National Registration Bureau",
    "additional_fields": {
      "tramite_number": null,
      "mrz_line_1": "IDKEN123456788<<<<<<<<<<<<<<<<",
      "mrz_line_2": "9005156M3001018KEN12345678<<<<",
      "mrz_line_3": "ODHIAMBO<<JAPHETH<<<<<<<<<<<<<"
    }
  }
}

Frequently Asked Questions

Does the SDK validate the MRZ on the back of the Kenya Maisha Card?

Yes. Our engine extracts the TD1 format MRZ lines from the new-generation smart ID and runs the ICAO 9303 checksum verification (modulus 10 with 7-3-1 weighting) on the document numbers and dates to ensure data integrity.

Can it extract the Maisha Namba / Unique Personal Identifier (UPI)?

Absolutely. The models natively target the unique identification number on the face of the card, mapping it directly to the `personal_number` field and double-checking it against the MRZ block.

Are legacy laminated Kenyan IDs supported?

Yes, our OCR engine dynamically checks the document generation and falls back to pure Visual Zone (VIZ) extraction if a legacy ID card without an MRZ is processed.

You May Also Like

Related tutorials, platform guides, and comparisons

Tutorial

Python National ID OCR API

High-accuracy National ID OCR for Python. Upload an image for a free test! Get structured JSON output via our dedicated Python SDK. Automate KYC and data entry with 99%+ accuracy.

Python · National ID
Country Tutorial

Côte d'Ivoire CNI (Carte Nationale d'Identité) OCR Python SDK

Python Tutorial: Automate KYC in Côte d'Ivoire. Extract French text, NNI, and validate TD1 MRZ from the ONECI CNI using StructOCR Python SDK.

Python · National ID
Country Tutorial

Uganda National ID Card OCR Python SDK

Python Tutorial: Automate KYC in Uganda. Extract data from National ID Card using StructOCR Python SDK. Supports native text and MRZ extraction.

Python · National ID
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

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.

Python · National ID
Country Tutorial

Saudi Arabia National ID & Iqama OCR Python SDK

Python Tutorial: Automate KYC in Saudi Arabia. Extract data from National IDs and Iqamas using the StructOCR Python SDK. Supports bilingual (Arabic/English) text, 10-digit ID numbers, and 3-line MRZ extraction.

Python · National ID
Country Tutorial

France Carte Nationale d'Identité OCR Python SDK

Python Tutorial: Automate KYC in France. Extract data from Carte Nationale d'Identité and validate TD1/TD2 MRZ using StructOCR Python SDK. Supports native text.

Python · National ID
Country Tutorial

Malaysia MyKad OCR with Node.js SDK

Extract identity number, names, dates and other visible fields from MyKad with the StructOCR Node.js SDK and Express.

Node.js · National ID
Country Tutorial

India Aadhaar OCR with Node.js SDK

Extract Aadhaar number, names, dates and other visible fields from Aadhaar card with the StructOCR Node.js SDK and Express.

Node.js · National ID
Country Tutorial

Indonesia KTP OCR with Node.js SDK

Extract NIK, names, dates and other visible fields from Kartu Tanda Penduduk (KTP) with the StructOCR Node.js SDK and Express.

Node.js · National 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