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
| Argument | Description |
|---|---|
file_name | Name 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-DDformat - Validates HTS8 codes are exactly 8 digits
- Uses
ON CONFLICT DO UPDATEfor idempotent upserts - Processes in batches of 1,000 rows
Example Output
Loading general_tariff_data.txt...
Loaded 12,769 tariff records in 28.3 secondsload-sections
Load HTS section structure from a CSV file and extract 4-digit headings.
Usage
uv run hts load-sections <file_name>Arguments
| Argument | Description |
|---|---|
file_name | Name of the sections CSV in source-data/ |
Details
- Truncates and reloads the
hts_sectionstable - 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: 961load-chapters
Fetch HTS chapter data from the USITC API.
Usage
uv run hts load-chaptersDetails
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: 121load-tariff-resources
Load trade policy resources from a JSON file.
Usage
uv run hts load-tariff-resourcesDetails
- Reads from
source-data/tariff_resources.json - Full refresh: deletes existing resources and reloads all
- Validates
resource_typeagainst allowed values:reference,guidance,legal,educational,news,tool - Resources are loaded as verified by default
Example Output
Loading tariff resources...
Loaded 45 resources