Skip to main content

Extract recipient address from AWB/shipping label PDF using Claude AI

Project description

AWB Extractor

Python SDK for extracting receiver and shipment information from AWB/shipping label PDF files using Claude AI.

Features

  • Extract from PDF bytes, local PDF files, or PDF URLs
  • Batch extraction from multiple URLs
  • Optional default HTTP headers for protected AWB URLs
  • Typed AWBResult dataclass output
  • Custom exceptions for API key, PDF download, and JSON parsing failures

Requirements

  • Python 3.10+
  • Anthropic API key

Installation

Install from PyPI:

pip install awb-extractor

For local development:

pip install -e ".[dev]"

Usage

from awb_extractor import AWBExtractor

extractor = AWBExtractor(api_key="sk-ant-...")
result = extractor.from_file("label.pdf")

print(result.recipient_name)
print(result.to_dict())

Example result:

{
    "tracking_number": "NHSVC972103440",
    "recipient_name": "Nguyen Van A",
    "recipient_phone": "(+84)03******37",
    "recipient_address": "237 Nguyen Trai",
    "recipient_ward": "Phuong Ben Thanh",
    "recipient_district": "Quan 1",
    "recipient_province": "TP. Ho Chi Minh",
    "sender_name": "Onflow",
    "sender_address": "TP. Ho Chi Minh",
    "cod": "0",
    "weight": "0.700 KG",
    "order_id": "584425059595159079",
}

Supported Inputs

PDF bytes

from awb_extractor import AWBExtractor

extractor = AWBExtractor(api_key="sk-ant-...")

with open("label.pdf", "rb") as file:
    result = extractor.from_bytes(file.read())

Local PDF file

from awb_extractor import AWBExtractor

extractor = AWBExtractor(api_key="sk-ant-...")
result = extractor.from_file("label.pdf")

PDF URL

from awb_extractor import AWBExtractor

extractor = AWBExtractor(
    api_key="sk-ant-...",
    http_headers={"Authorization": "Bearer token"},
)

result = extractor.from_url("https://example.com/awb.pdf")

You can pass request-specific headers with extra_headers:

result = extractor.from_url(
    "https://example.com/awb.pdf",
    extra_headers={"X-Request-ID": "request-123"},
)

Multiple URLs

from_urls() returns a list of dictionaries with url, data, and error. Failed URLs do not stop the whole batch.

from awb_extractor import AWBExtractor

extractor = AWBExtractor(api_key="sk-ant-...")
results = extractor.from_urls([
    "https://example.com/good.pdf",
    "https://example.com/bad.pdf",
])

Result Fields

AWBResult includes:

  • tracking_number
  • recipient_name
  • recipient_phone
  • recipient_address
  • recipient_ward
  • recipient_district
  • recipient_province
  • sender_name
  • sender_address
  • cod
  • weight
  • order_id

Use to_dict() or to_json() to serialize the result.

Exceptions

  • APIKeyError: missing API key
  • PDFDownloadError: PDF URL download failed
  • ExtractionError: Claude response could not be parsed as JSON

Package Structure

  • awb_extractor/extractor.py: public AWBExtractor class
  • awb_extractor/models.py: AWBResult dataclass
  • awb_extractor/exceptions.py: package exceptions

Publishing

GitHub Actions builds and publishes the package to PyPI on every push to main.

The repository must define this GitHub secret:

PYPI_API_TOKEN

PyPI does not allow replacing an existing version. If a commit on main does not bump project.version in pyproject.toml, the publish step skips the existing distribution.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

awb_extractor-0.1.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

awb_extractor-0.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file awb_extractor-0.1.1.tar.gz.

File metadata

  • Download URL: awb_extractor-0.1.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for awb_extractor-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5b0bd2b561848ce3cf5674108797ce6b0802e1f4658045e47deac2792a078d13
MD5 d88715068a478c4b485acbb4249f2723
BLAKE2b-256 5e67da6de2ee67f6af39f067c7e298d43882c9a5da63183734edf03e595e8b02

See more details on using hashes here.

File details

Details for the file awb_extractor-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: awb_extractor-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for awb_extractor-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f07c4dd2fbdaee8f48e80cafad932c37c79cb6599f336ebe3becba33db73f3d9
MD5 0709560f1f78551406a5f66ab314d4f2
BLAKE2b-256 fd88443cb6fc249893e4c01356d11a7799c6684f2274baa30447d44b9ce683f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page