Skip to content
View customs-brokerage's full-sized avatar

Block or report customs-brokerage

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Maximum 250 characters. Please don’t include any personal information such as legal names or email addresses. Markdown is supported. This note will only be visible to you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
customs-brokerage/README.md

Customs Brokerage & HS Code Classification Workflows

Customs Brokerage & HS Code Classification Workflows

A technical engineering reference for building, maintaining, and scaling automated customs-compliance pipelines.

🌐 www.customs-brokerage.org

Customs clearance is an engineering problem long before it is a paperwork problem. Every duty figure a broker files traces back through a chain of deterministic, auditable transformations: a commercial description resolved to a Harmonized System code, a temporally-versioned tariff schedule, an origin determination, a duty formula, and a wire-format transmission to CBP. When any link in that chain is non-deterministic, duty leaks, filings get rejected, and a Focused Assessment finds gaps no one can reconstruct.

This site is a deep, code-first reference for the Python ETL teams, customs brokers, and trade-compliance officers who build those pipelines. Every article leads with runnable Python 3.10+ (exact Decimal money, structured logging, asyncpg/PostgreSQL, idempotent upserts) and anchors each pattern to the specific regulatory obligation it satisfies — WCO HS 2022 nomenclature, HTSUS (USITC), CBP ACE decimal-precision and rounding rules, ISF 19 CFR 149, and Post-Summary Correction workflows.

What it covers

The reference is organised into three connected areas, each with in-depth guides and focused implementation walkthroughs:

Treating the Harmonized System as a versioned, temporally-aware data layer.

  • Temporal HTS schedule database design and point-in-time resolution with recursive CTEs
  • Idempotent tariff-update ingestion pipelines and Polars memory profiling for large HTSUS releases
  • Rule-of-origin engines: regional value content over BOM hierarchies, USMCA tariff-shift testing
  • Duty-formula frameworks: ad valorem, specific, and compound rates with CBP half-up rounding
  • Fallback routing for unmapped codes, plus RBAC, envelope encryption, and audit-grade data isolation

Turning heterogeneous commercial documents into deterministic, schema-bound payloads.

  • Commercial-invoice PDF extraction (pdfplumber vs camelot vs tabula), multi-currency handling with Babel
  • Packing-list normalization and net-vs-gross weight reconciliation
  • OCR drift correction and confidence-threshold calibration for HS digit fields
  • Multi-language and CJK invoice parsing with Unicode NFC normalization
  • Exponential backoff, dead-letter queues, and high-volume async batch processing

Assembling and transmitting the entry to CBP, and keeping it defensible through liquidation.

  • Entry summary (CBP 7501) line assembly and ACE decimal-precision validation
  • Importer Security Filing (ISF 10+2) data assembly and late-filing / liquidated-damages handling
  • ABI/ACE rejection handling: decoding X12 824 application advice and idempotent resubmission
  • Post-entry amendment workflows: Post-Summary Corrections and duty-refund reconciliation

Who it's for

  • Python ETL / data engineers building customs and trade-compliance data pipelines
  • Customs brokers and licensed professionals automating classification and filing
  • Trade-compliance officers who need audit-ready, reconstructable workflows
  • Logistics developers integrating tariff, valuation, and ACE transmission systems

How it's built

A static site generated with Eleventy, authored in Markdown with hand-crafted inline SVG diagrams, KaTeX for duty-formula notation, structured data (JSON-LD), and a full accessibility and performance budget. It is deployed on Cloudflare Workers.

npm install
npm run build      # build the static site into _site/
npm run serve      # local preview on :8080
npm run deploy     # build + deploy to Cloudflare

License & use

Content and code samples are published as an educational engineering reference. The code patterns are illustrative — validate against the current WCO, USITC, and CBP instruments before relying on them for live customs filings.


Built for the people who keep goods moving across borders — explore the full reference →

Popular repositories Loading

  1. customs-brokerage customs-brokerage Public

    A code-first engineering reference for automated customs brokerage & HS code classification pipelines — HTS mapping, duty calculation, document ingestion, and CBP ACE transmission.

    JavaScript