Spain Passport OCR with the StructOCR Python SDK

Install the official Python SDK, extract validated Spain passport fields, and add the same workflow to a FastAPI service.

AI executing passport data extraction API on a Spanish document
StructOCR API engine analyzing a Spanish passport via global edge computing.

Challenges with Spain Passport Verification

Extracting accurate data from Spanish passports can be a complex task. Security features, intricate background patterns, and laminate glare often obscure critical information. Manual entry is prone to errors and delays. Our core passport data extraction api is specifically engineered to overcome these optical obstacles, ensuring high accuracy without relying on heavy client-side processing.

Why Use Our Passport Extraction API

Our engine excels in processing Spanish identity documents with unparalleled accuracy. Delivered as a pure REST API deployed on a global edge network, it integrates seamlessly into your existing stack regardless of the framework. Whether you are building a fintech identity verification software solution or a travel booking platform, our passport extraction API handles raw PDFs, image files, Base64 strings, or direct URLs to provide reliable, structured JSON results instantly. For the fastest Python integration, install the official StructOCR SDK and see the Python SDK documentation.

Built for High-Compliance Industries

  • Travel & Aviation: Our technology provides a seamless verification solution for travel, significantly speeding up check-in by using the API to validate Spanish passport details in under a second.
  • Financial Services: Leverage our robust fintech identity verification software to automate KYC onboarding, utilizing direct Base64 uploads to maintain strict data compliance.

Live Demo: Passport 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 Passport scans).

Spain Passport OCR with the Python SDK

The official Python SDK handles file encoding, API communication, and structured passport results. Use the SDK directly or open the FastAPI tab for a server endpoint. Keep your API key in STRUCTOCR_API_KEY.

Prerequisite: `pip install structocr`; set the server-side `STRUCTOCR_API_KEY` environment variable.

Prefer another stack? Open the Node.js SDK + Express integration.

import os
from structocr import StructOCR

# Initialize API Client for Edge Processing
client = StructOCR(os.environ["STRUCTOCR_API_KEY"])

def extract_spain_passport():
    # Supports local files (PDF/Images), Base64 encoded strings, or URLs
    document_source = "spain_passport_sample.pdf"

    try:
        print(f"Executing passport data extraction API for {document_source}...")
        result = client.scan_passport(document_source)

        if result.get('success'):
            data = result['data']
            print("✅ Passport Extraction Successful!")
            print(f"Passport #:  {data.get('passport_number')}")
            print(f"Name:        {data.get('given_names')} {data.get('surname')}")
            print(f"Nationality: {data.get('nationality')}")
            print(f"DOB:         {data.get('date_of_birth')}")
        else:
            print(f"❌ API Extraction Failed: {result.get('error')}")

    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    extract_spain_passport()

Technical Specs

  • Infrastructure: Distributed Global Edge Network
  • Latency: < 1s (Average response time)
  • Security: In-memory processing, zero data retention
  • Inputs Supported: PDF, File Upload (JPG/PNG/WebP), Base64 String, Image URL
  • Output: Structured JSON

Key Features

  • Official Python SDK: Handles image input, authentication, API communication, and structured results.
  • Multi-Format Processing: Natively parse multi-page PDFs or standard image formats.
  • Visual Extraction (VIZ): Reliably extracts data directly from the visual inspection zone alongside MRZ.
  • Flexible Payloads: Pass Base64 data directly from frontend clients to bypass intermediate storage.

JSON API Response Example

The Python SDK returns a dictionary matching this normalized JSON structure.

{
  "success": true,
  "data": {
    "type": "passport",
    "country_code": "ESP",
    "nationality": "ESP",
    "passport_number": "PA123456",
    "surname": "GARCÍA",
    "given_names": "ANTONIO",
    "sex": "M",
    "date_of_birth": "1975-01-20",
    "place_of_birth": "MADRID",
    "date_of_issue": "2020-01-01",
    "date_of_expiry": "2025-01-19",
    "issuing_authority": "DGP"
  }
}

Frequently Asked Questions

Do I have to use the Python SDK?

No, our core product is a language-agnostic REST API. The Python library is simply a convenient wrapper. You can make direct HTTP POST requests using cURL, Node.js, Go, or any other language.

Does it work with older passport formats?

Yes, our passport extraction api is trained on diverse datasets to handle both legacy formats and modern biometric passport layouts globally.

How much does the passport data extraction API cost?

Our service operates on a transparent, pay-as-you-go model starting with free credits for testing. You can view our full pricing details to find a volume tier that fits your application's needs.

You May Also Like

Related tutorials, platform guides, and comparisons

Country Tutorial

Kazakhstan Passport OCR with Python SDK

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

Python · Passport
Country Tutorial

Tanzania Passport OCR with Python SDK

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

Python · Passport
Country Tutorial

Sweden Passport OCR with Python SDK

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

Python · Passport
Country Tutorial

Kenya Passport OCR with Python SDK

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

Python · Passport
Country Tutorial

Algeria Passport OCR with Python SDK

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

Python · Passport
Country Tutorial

UK Passport OCR with Python SDK

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

Python · Passport
Country Tutorial

Belgium Passport OCR with Python SDK

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

Python · Passport
Country Tutorial

Switzerland Passport OCR with Python SDK

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

Python · Passport
Country Tutorial

Tajikistan 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 Tajikistan passports.

Node.js · Passport
Country Tutorial

Switzerland 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 Switzerland 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