Brazil CIN OCR Python SDK

Instantly extract visual data, CPF numbers, and validate cryptographic MRZ checksums from the new Brazilian Identity Cards (CIN) using our native Python library.

AI extracting Portuguese text, CPF, and TD1 MRZ data from a new Brazil Carteira de Identidade Nacional (CIN)
StructOCR engine extracting Visual Zone (VIZ) and validating the MRZ on a Brazilian CIN in real-time.

Parsing Carteira de Identidade (CIN) Challenges

Identity verification in Brazil is undergoing a massive transition. Organizations must process both the legacy RG (Registro Geral)—which has 27 different layout variations across states—and the newly unified Carteira de Identidade Nacional (CIN). Standard OCR engines struggle with this high variance, frequently misreading critical numbers or failing on complex Portuguese layouts. Furthermore, the new CIN introduces a Machine-Readable Zone (MRZ) on the reverse side, requiring advanced mathematical parsing to verify the document's authenticity against identity fraud.

Why StructOCR for Brazil

StructOCR is explicitly trained to bridge this transition. Our models gracefully handle both legacy RG layouts and the new, unified CIN standard, enabling unparalleled accuracy. Our Python SDK automatically locates the CPF (Cadastro de Pessoas Físicas)—now the single identifier for Brazilians—extracting it seamlessly via our national ID parsing API to power your KYC automation platform.

Common Use Cases in Latin America

  • Digital Onboarding & PIX: Verify users for Fintech apps and PIX payments in Brazil by pre-filling CIN and CPF data in < 2 seconds.
  • Telecom Registration: Automate robust SIM card registration by natively extracting the unified CPF number.
  • Pan-LatAm Expansion: Seamlessly process users across Mercosur. Our unified Python SDK automatically detects and extracts data from neighboring documents, such as the Argentina DNI or Chile RUN, without requiring any custom rules.

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 Brazil-specific fields (like CPF) and parses the TD1 MRZ block found on the new CIN.

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

from structocr import StructOCR

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

def scan_brazil_id():
    # Note: Supports JPG, PNG, WebP (Max 4.5MB)
    image_path = "brazil_cin_front_back.jpg"

    try:
        print(f"Scanning {image_path}...")
        result = client.scan_national_id(image_path)

        if result.get('success'):
            data = result['data']
            print("✅ Brazil CIN Extraction Successful!")
            
            # Basic Identity
            print(f"Region:      {data.get('country_code')}")
            print(f"Name:        {data.get('given_names')} {data.get('surname')}")
            
            # Critical Local Field: Unified CPF
            print(f"CPF:         {data.get('personal_number')}")
            
            # Demographics
            print(f"DOB:         {data.get('date_of_birth')} ({data.get('sex')})")
            print(f"Address:     {data.get('address', 'Extracted from back')}")
            
            # Extract TD1 MRZ Data (New CIN)
            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_brazil_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

  • Unified CPF Extraction: Automatically identifies and formats the 11-digit CPF format (XXX.XXX.XXX-XX) from both legacy RG and new CIN documents.
  • Legacy & Modern Support: Dynamically routes extraction logic to handle all 27 state-level RG layouts alongside the unified federal CIN format.
  • Hybrid VIZ + MRZ AI: Cross-validates unstructured visual data against cryptographic TD1 MRZ checksums for the new CIN.
  • Smart Crop: Removes background noise and deskews rotated images automatically, ideal for user-submitted mobile photos.

JSON Response Example

The SDK returns a Python dictionary containing the parsed visual data (VIZ), the Brazilian CPF, and the raw Machine-Readable Zone (MRZ) block found on the back of the CIN.

{
  "success": true,
  "data": {
    "type": "national_id",
    "country_code": "BRA",
    "nationality": "BRASILEIRA",
    "document_number": "12345678900",
    "card_series": "",
    "personal_number": "123.456.789-00",
    "surname": "DA SILVA",
    "given_names": "JOÃO PEDRO",
    "sex": "M",
    "date_of_birth": "1990-05-15",
    "place_of_birth": "SÃO PAULO - SP",
    "address": "AV PAULISTA 1000, SÃO PAULO - SP",
    "date_of_issue": "2023-11-20",
    "date_of_expiry": "2033-11-20",
    "issuing_authority": "GOVERNO FEDERAL",
    "additional_fields": {
      "tramite_number": null,
      "mrz_line_1": "IDBRA1234567890<<<<<<<<<<<<<<<",
      "mrz_line_2": "9005156M3311208BRA<<<<<<<<<<<4",
      "mrz_line_3": "DA<SILVA<<JOAO<PEDRO<<<<<<<<<<"
    }
  }
}

Frequently Asked Questions

Does the SDK support both the old RG and the new Carteira de Identidade Nacional (CIN)?

Yes. Our engine is trained on the legacy state-issued RG formats as well as the new federal CIN. The API automatically detects the document version and extracts the relevant fields accordingly.

Can it validate the MRZ on the new Brazilian CIN?

Absolutely. The back of the new CIN features a TD1 MRZ. Our SDK extracts these lines and runs the ICAO 9303 checksum verification (modulus 10) to ensure the CPF and date of birth match the visual data.

How does it handle the CPF number?

The SDK targets the CPF as the primary identifier. It extracts the raw number and formats it into the standard `XXX.XXX.XXX-XX` structure, mapping it directly to the `personal_number` field in the JSON response.

You May Also Like

Related tutorials, platform guides, and comparisons

Country Tutorial

Brazil Driver License OCR with Python SDK

Extract structured fields from a Brazil Carteira Nacional de Habilitação (CNH) with the StructOCR Python SDK and FastAPI.

Python · Driver License
Country Tutorial

Brazil Passport OCR with Python SDK

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

Python · Passport
Country Tutorial

Brazil Driver License OCR with Node.js SDK

Extract structured fields from a Brazil Carteira Nacional de Habilitação (CNH) with the StructOCR Node.js SDK and TypeScript + Express.

Node.js · Driver License
Country Tutorial

Singapore Passport OCR with Python SDK

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

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

Netherlands Identiteitskaart OCR Python SDK

Python Tutorial: Automate KYC in Netherlands. Extract data from Identiteitskaart using StructOCR Python SDK. Supports native text and MRZ extraction.

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

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
Country Tutorial

Uganda Passport OCR with Node.js SDK

Use the official StructOCR Node.js SDK with TypeScript and Express to extract structured MRZ and VIZ data from Uganda passports.

Node.js · Passport

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