The Best Python Library for Shipping Container OCR

Stop using regex. Extract structured data from shipping containers using Python.

The Problem with Shipping Container Parsing

Shipping containers often present challenges for traditional OCR methods. Factors like glare, holograms, skewed angles, varying fonts, and damage degrade the accuracy of regular expression or template-based systems. Vertical text, common in port environments, is especially difficult. These systems struggle to cope with real-world variations, leading to high error rates.

The StructOCR Solution

StructOCR utilizes advanced deep learning models specifically trained on shipping container data, ensuring ISO 6346 compliant extraction is achieved. Our AI automatically handles deskewing, perspective correction, smart cropping, and vertical text reading, providing accurate and reliable results for applications such as logistics and port automation every time.

Common Use Cases

  • KYC/Onboarding: Automate user verification flow.
  • Data Entry Automation: Eliminate manual typing errors.
  • Fraud Detection: Identify inconsistent data fields.
Need more testing? Create a free account to get 200 free credits (equals 200 Container 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.

PYTHON EXAMPLE
from structocr import StructOCR
from structocr.exceptions import APIError, InvalidAPIKeyError

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

def scan_shipping_container():
    # Note: Supports JPG, PNG, WebP (Max 4.5MB)
    # Target: Shipping Container Number (ISO 6346)
    image_path = "container_image.jpg"

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

        if result and result.get('success'):
            data = result['data']
            print("✅ Container Extraction Successful!")
            
            print(f"Container Number: {data.get('container_number')}")
            print(f"Is Valid (Check Digit): {data.get('is_valid')}")
            print(f"Confidence: {data.get('confidence')}")

            parsed_data = data.get('parsed', {})
            print(f"Owner Code: {parsed_data.get('owner_code')}")
            print(f"Category: {parsed_data.get('category')}")
            print(f"Serial Number: {parsed_data.get('serial_number')}")
            print(f"Check Digit: {parsed_data.get('check_digit')}")

            if data.get('is_valid'):
                print("\nContainer number check digit is valid.")
            else:
                print("\nContainer number check digit is invalid. Please verify.")

        else:
            print(f"❌ Extraction Failed: {result.get('error')}")

    except InvalidAPIKeyError as e:
        print(f"Error: Invalid API Key. {e}")
    except APIError as e:
        print(f"Error communicating with the API: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    scan_shipping_container()

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

  • •Smart Crop: Auto-detects document boundaries.
  • •Field Validation: Cross-validates dates and checksums.
  • •Specialized Models: Trained specifically on Shipping Containers.

Sample JSON Response

The API returns a clean JSON object with normalized fields.

{
  "success": true,
  "data": {
    "container_number": "TTNU5194822",
    "is_valid": true,
    "confidence": "High",
    "parsed": {
      "owner_code": "TTN",
      "category": "U",
      "serial_number": "519482",
      "check_digit": "2"
    }
  }
}

Frequently Asked Questions

What file formats are supported?

JPG, PNG, and WebP images up to 4.5MB.

Is data stored?

Only briefly. Uploaded images and results are kept for at most 24 hours for quality spot-checks, then deleted.

How to handle errors?

Check the 'success' flag and 'error' message in the response.

You May Also Like

Related tutorials, platform guides, and comparisons

Tutorial

Java Shipping Container OCR API

Upload an image for a free test! Tutorial: Learn how to use the StructOCR Java Client to extract data from Shipping Containers. Extract ISO 6346 container numbers and check them against the ISO check digit.

Java · Container
Tutorial

PHP Shipping Container OCR API

Tutorial: Learn how to use the StructOCR PHP Client via cURL for shipping container OCR. Upload an image for a free test! Extract ISO 6346 container numbers and check them against the ISO check digit. Includes code samples and JSON schemas.

PHP · Container
Tutorial

Node.js Shipping Container OCR API

Tutorial: How to use the StructOCR Node.js SDK to extract data from Shipping Containers. Upload an image for a free test! Includes code samples and JSON schema.

Node.js · Container
Tutorial

Go Shipping Container OCR API

Upload an image for a free test! Tutorial: Learn how to use the StructOCR Go Client to extract data from Shipping Containers. Extract ISO 6346 container numbers and check them against the ISO check digit. Includes code samples and JSON schema.

Go · Container
Tutorial

C# Shipping Container OCR API

Upload an image for a free test! Tutorial: Learn how to use the StructOCR C# Client to extract data from Shipping Containers. Extract ISO 6346 container numbers and check them against the ISO check digit. Includes code samples and JSON schemas.

C# · Container
Country Tutorial

Kenya National ID (Maisha Card) OCR Python SDK

Python Tutorial: Automate KYC in Kenya. Extract data, Maisha Namba (UPI), and validate TD1 MRZ from National ID (Maisha Card) using StructOCR Python SDK.

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

Mexico INE OCR API & Python SDK

Python Tutorial: Automate KYC in Mexico. Extract data from INE cards using our SDK. Upload your ID image to test the OCR engine live—no signup required. Supports native text and MRZ.

Python · ine credencial
Country Tutorial

Morocco CNIE OCR Python SDK

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

Python · cnie
Country Tutorial

Malaysia MyKad OCR Python SDK

Python Tutorial: Automate KYC in Malaysia. Extract data from the Malaysian Identity Card (MyKad) using StructOCR Python SDK. Supports NRIC extraction and multi-line address parsing.

Python · mykad

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