HTS MCP
Skip to Content
CLIData Loading

Data Loading

CLI commands for loading tariff data, sections, chapters, and resources.

load

Load tariff data from a CSV or text file in the source-data/ directory.

Usage

uv run hts load <file_name>

Arguments

ArgumentDescription
file_nameName of the file in source-data/ (e.g., general_tariff_data.txt)

Details

The loader:

  • Auto-detects file type by extension (.txt/.csv → text loader, .xlsx → Excel loader)
  • Converts numeric columns (*_rate, *_ave, ad_val, specific) to float
  • Converts date columns to YYYY-MM-DD format
  • Validates HTS8 codes are exactly 8 digits
  • Uses ON CONFLICT DO UPDATE for idempotent upserts
  • Processes in batches of 1,000 rows

Example Output

Loading general_tariff_data.txt... Loaded 12,769 tariff records in 28.3 seconds

load-sections

Load HTS section structure from a CSV file and extract 4-digit headings.

Usage

uv run hts load-sections <file_name>

Arguments

ArgumentDescription
file_nameName of the sections CSV in source-data/

Details

  • Truncates and reloads the hts_sections table
  • Extracts 4-digit headings (indent=0 rows) into hts_headings
  • Returns counts for both tables

Example Output

Loading sections from hts_sections.csv... Sections loaded: 5,432 Headings extracted: 961

load-chapters

Fetch HTS chapter data from the USITC API.

Usage

uv run hts load-chapters

Details

Makes concurrent HTTP requests to https://hts.usitc.gov/reststop/ to fetch:

  • All 98 chapters with descriptions and section groupings
  • Sections (Roman numerals I–XXII) with chapter ranges
  • Interpretive notes at chapter and section levels
  • Raw full-text HTML note blobs

Example Output

Fetching chapters from USITC API... Sections loaded: 22 Chapters loaded: 98 Notes loaded: 1,067 Raw notes loaded: 121

load-tariff-resources

Load trade policy resources from a JSON file.

Usage

uv run hts load-tariff-resources

Details

  • Reads from source-data/tariff_resources.json
  • Full refresh: deletes existing resources and reloads all
  • Validates resource_type against allowed values: reference, guidance, legal, educational, news, tool
  • Resources are loaded as verified by default

Example Output

Loading tariff resources... Loaded 45 resources