
Tariff Calculator Amazon
- 4 installs
- 41 repo stars
- Updated April 19, 2026
- liangdabiao/amazon-skills-liang
Helps with ai & agent building tasks.
About
tariff-calculator-amazon is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted development.
- tariff-calculator-amazon
- AI & Agent Building
- AI-coding skill
Tariff Calculator Amazon by the numbers
- 4 all-time installs (skills.sh)
- Ranked #13,372 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/liangdabiao/amazon-skills-liang --skill tariff-calculator-amazonAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 4 |
|---|---|
| repo stars | ★ 41 |
| Last updated | April 19, 2026 |
| Repository | liangdabiao/amazon-skills-liang ↗ |
What it does
Helps with ai & agent building tasks.
Files
关税计算器 — 亚马逊 💰
面向国际亚马逊卖家的通用关税和到岸成本计算器。
安装
npx skills add nexscope-ai/eCommerce-Skills --skill tariff-calculator-amazon -g功能
- 通用贸易路线 — 任意原产国到任意目的国
- 关税税率查询 — HS编码 → 税率
- 301条款关税 — 中国进口商品的美国附加关税
- 增值税/消费税计算 — 欧盟、英国、加拿大、澳大利亚、中国税率
- 到岸成本 — 完整成本细分
- HS编码匹配 — 产品描述 → HS编码建议
- 贸易协定 — USMCA、EVFTA、RCEP优惠税率
支持的贸易路线
| 路线 | 主要关税 | 增值税/消费税 |
|---|---|---|
| 🇨🇳 → 🇺🇸 中国 → 美国 | 301条款(7.5-25%) | 不适用 |
| 🇨🇳 → 🇪🇺 中国 → 欧盟 | 标准关税 | 19-22% |
| 🇨🇳 → 🇬🇧 中国 → 英国 | 标准关税 | 20% |
| 🇺🇸 → 🇪🇺 美国 → 欧盟 | 标准关税 | 19-22% |
| 🇪🇺 → 🇺🇸 欧盟 → 美国 | 标准关税 | 不适用 |
| 🇺🇸 → 🇨🇳 美国 → 中国 | 报复性关税 | 13%增值税 |
| 🇨🇳 → 🇨🇦 中国 → 加拿大 | 标准关税 | 5%消费税 |
| 🇨🇳 → 🇦🇺 中国 → 澳大利亚 | 标准关税 | 10%消费税 |
| 自定义 | 用户定义 | 用户定义 |
301条款关税(中国 → 美国)
| HS章节 | 产品 | 附加税率 |
|---|---|---|
| 84xx | 电脑、机械 | 25% |
| 85xx | 电子产品(部分) | 0-25% |
| 94xx | 家具、照明 | 25% |
| 95xx | 玩具 | 25% |
| 61/62 | 服装 | 7.5% |
| 64xx | 鞋类 | 7.5% |
| 42xx | 箱包、配饰 | 7.5% |
到岸成本公式
到岸成本 =
FOB价
+ 国际运费
+ 保险
+ 进口关税
+ 增值税/消费税(如适用)
+ 清关费用
+ 港口费用
+ 内陆运费工作流程
第一步: 收集关税计算需求 — 产品类型、HS编码、原产国、目的国、FOB货值、数量、运费等基本信息。
第二步: 通过多选题补充信息 — 产品材质、是否涉及301条款关税、是否需要贸易协定优惠、是否涉及多个SKU计算。
第三步: 使用以下框架和方法论进行研究分析。
到岸成本计算公式: 到岸成本=FOB货值+国际运费+保险费+进口关税+VAT/GST+清关费+港口费+内陆运输费。逐步计算:CIF价值=FOB货值+国际运费+保险费;关税总额=CIF价值×基础关税率+CIF×301税率(中国→美国);增值税=VAT基数×VAT税率,其中VAT基数=CIF+关税总额;税费总额=关税+VAT+清关费($150)+港口费($50);到岸总成本=CIF+税费总额+内陆运输费。
HS编码体系: HS编码是国际贸易通用商品分类编码,前2位代表章(Chapter),前4位代表税号(Heading)。章和税号国际统一,子目(6-10位)各国自定义。HS查询优先级:直接输入HS编码精确匹配(置信度100%);关键词匹配内置映射表(置信度60-80%);描述模糊匹配遍历数据库(置信度70%)。
基础关税率: 基础关税率按HS章节和目的国确定,数据来源为各国最惠国待遇(MFN)税率。例如:塑料制品(39章)美国6.5%、欧盟6.5%;机械设备(84章)美国0%、欧盟2%;电子电气(85章)美国0%、欧盟2%;家具(94章)美国0%、欧盟0%;玩具(95章)美国0%、欧盟4.5%。
301条款关税计算: 美国对从中国进口部分商品征收额外附加关税,按HS4位税号判定。关税与基础关税叠加计算,非替代关系。例如:电脑(8471)25%;电源/变压器(8504)25%;通讯设备(8517)25%;家具(9403)25%;玩具(9503)25%;服装(6110/6203/6204)7.5%;鞋类(6402)7.5%。
VAT/GST计算方法: VAT基数=CIF价值+关税总额;VAT=VAT基数×VAT税率。例如:中国→欧盟:CIF=$5215+关税=$1304;VAT基数=$6519;VAT=$6519×19%=$1239。
第四步: 提供完整的关税计算报告,包含成本细分、税费明细、到岸总成本和单价分析。
使用方法
基本计算
python3 scripts/calculator.py带参数
python3 scripts/calculator.py '{
"hs_code": "8518300000",
"origin_country": "CN",
"destination_country": "US",
"fob_value": 5000.00,
"quantity": 500,
"freight_cost": 200.00
}'HS编码查询
python3 scripts/hs_lookup.py "wireless earbuds"
python3 scripts/hs_lookup.py "bluetooth speaker"自定义贸易路线
python3 scripts/calculator.py '{
"hs_code": "9503009000",
"origin_country": "VN",
"destination_country": "DE",
"fob_value": 10000.00,
"quantity": 1000,
"freight_cost": 500.00,
"custom_duty_rate": 0.047,
"custom_vat_rate": 0.19
}'输出示例
💰 关税与到岸成本报告
产品:无线蓝牙耳机
HS编码:8518300000
路线:中国 🇨🇳 → 美国 🇺🇸
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📦 成本细分
FOB价 $ 5,000.00
国际运费 $ 200.00
保险 $ 15.00
CIF价 $ 5,215.00
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🏛️ 关税与税费
基础关税(0.0%) $ 0.00
301条款(0.0%) $ 0.00
总关税 $ 0.00
清关费用 $ 150.00
港口费用 $ 50.00
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
💵 到岸成本总结
总到岸成本 $ 5,515.00
单价 $ 11.03贸易协定支持
| 协定 | 国家 | 优惠 |
|---|---|---|
| USMCA | 美国、墨西哥、加拿大 | 减税/零关税 |
| EVFTA | 欧盟、越南 | 减税 |
| RCEP | 亚太地区 | 减税 |
| UK-Japan | 英国、日本 | 减税 |
自定义配置
为您的路线创建自定义配置:
{
"default_origin": "CN",
"default_destination": "US",
"include_insurance": true,
"insurance_rate": 0.003,
"customs_fee": 150,
"port_fee": 50
}---
属于 [Nexscope AI](https://www.nexscope.ai/?co-from=skill) — 面向电商卖家的AI工具。
Amazon 关税与到岸成本计算器 — 原理详解
概述
本工具为跨境电商卖家计算从产地到目的地的完整到岸成本(Landed Cost),包括基础关税、Section 301 附加关税、VAT/GST、运费、保险费以及各类杂费。支持多条贸易路线和自由贸易协定优惠。
核心计算原理
1. 到岸成本公式
到岸成本是商品从工厂到达 Amazon 仓库的总成本:
到岸成本 = FOB货值 + 国际运费 + 保险费 + 进口关税 + VAT/GST + 清关费 + 港口费 + 内陆运输费逐步计算链路(calculator.py:246-335):
FOB货值 (Free on Board)
+ 国际运费 (Freight)
+ 保险费 (Insurance = FOB × 0.3%)
────────────────────
= CIF价值 (Cost, Insurance & Freight)
CIF价值
× 基础关税率
+ CIF × Section 301税率(仅中国→美国)
────────────────────
= 关税总额
CIF + 关税
× VAT/GST税率
────────────────────
= 增值税
关税 + VAT + 清关费($150) + 港口费($50)
────────────────────
= 税费总额
CIF + 税费总额 + 内陆运输费
────────────────────
= 到岸总成本2. HS 编码体系
HS(Harmonized System)编码是国际贸易通用的商品分类编码,前 2 位代表章(Chapter),前 4 位代表税号(Heading)。
HS编码: 8518 30 0000
├─── ── ────
│ │ └── 子目(6-10位,各国自定义)
│ └────── 税号(国际统一,决定关税率)
└─────────── 章(国际统一,代表产品大类)hs_lookup.py 内置了 24 个常见跨境电商产品的 HS 编码数据库,支持通过产品描述关键词和HS编码两种方式查询。
查询优先级(hs_lookup.py:311-356): 1. 直接输入 HS 编码 → 精确匹配(置信度 100%) 2. 关键词匹配 → 内置映射表(置信度 60-80%) 3. 描述模糊匹配 → 遍历数据库的英/中文描述(置信度 70%)
3. 基础关税率
基础关税率按 HS 章节和目的国确定。数据来源为各国公布的最惠国待遇(MFN)税率:
| HS章 | 产品类别 | 美国税率 | 欧盟税率 |
|---|---|---|---|
| 39 | 塑料制品 | 6.5% | 6.5% |
| 84 | 机械设备 | 0% | 2% |
| 85 | 电子电气 | 0% | 2% |
| 94 | 家具 | 0% | 0% |
| 95 | 玩具 | 0% | 4.5% |
完整税率表见 calculator.py:46-58。
4. Section 301 关税(中国→美国)
美国对从中国进口的部分商品征收额外附加关税,按 HS 4位税号判定:
| HS税号 | 产品 | 附加税率 |
|---|---|---|
| 8471 | 电脑 | 25% |
| 8504 | 电源/变压器 | 25% |
| 8517 | 通讯设备 | 25% |
| 9403 | 家具 | 25% |
| 9503 | 玩具 | 25% |
| 6110/6203/6204 | 服装 | 7.5% |
| 6402 | 鞋类 | 7.5% |
注意:Section 301 关税与基础关税叠加计算,不是替代关系。例如家具从中国出口到美国的总关税率可能是 0%(基础)+ 25%(301)= 25%。
5. VAT/GST 计算
VAT基数 = CIF价值 + 关税总额
VAT = VAT基数 × VAT税率关键点:VAT 的计税基数包含关税,形成税上加税效应。
| 目的国 | VAT/GST税率 |
|---|---|
| 美国 | 无联邦VAT(各州销售税不同) |
| 德国 | 19% |
| 法国 | 20% |
| 意大利 | 22% |
| 英国 | 20% |
| 加拿大 | 5% GST |
| 澳大利亚 | 10% GST |
6. 自由贸易协定优惠
工具支持以下贸易协定的税率减免:
| 协定 | 国家 | 减免幅度 |
|---|---|---|
| USMCA | 墨西哥/加拿大→美国 | 100% 免税 |
| AUSFTA | 澳大利亚→美国 | 100% 免税 |
| KORUS | 韩国→美国 | 100% 免税 |
| EVFTA | 越南→欧盟 | 50% 减免 |
当检测到符合条件的贸易路线时,自动应用减免(calculator.py:222-225)。
7. 运费估算
当未提供实际运费时,按重量和运输方式估算:
| 运输方式 | 目的地 | 估算费率 |
|---|---|---|
| 海运 | 美国 | $0.8/kg |
| 空运 | 美国 | $5.0/kg |
| 快递 | 美国 | $8.0/kg |
使用方法
# 基本关税计算
python3 scripts/calculator.py
# 自定义参数
python3 scripts/calculator.py '{
"hs_code": "8518300000",
"origin_country": "CN",
"destination_country": "US",
"fob_value": 5000.00,
"quantity": 500,
"freight_cost": 200.00
}'
# HS编码查询
python3 scripts/hs_lookup.py "wireless earbuds"
python3 scripts/hs_lookup.py "8518" --zh数据来源
本技能的所有关税和费率数据均内置在Python脚本中,无任何外部API调用。hs_lookup.py 包含一个24个常见跨境电商产品的HS编码数据库,每条记录包含HS编码(6-10位)、中英文产品描述和Section 301附加税率,支持通过产品描述关键词或HS编码两种方式查询。calculator.py 中硬编码了三组税率数据:(1) 11个HS章节(Chapter)的基础关税率,涵盖塑料制品(6.5%)、机械设备(0-2%)、电子电气(0-2%)、家具(0-4.5%)、玩具(0-4.5%)等;(2) 14个HS四位税号(Heading)的Section 301附加税率(7.5%-25%),主要针对中国出口到美国的电脑、通讯设备、家具、玩具、服装、鞋类等产品;(3) 6个目的国的VAT/GST税率(德国19%、法国20%、意大利22%、英国20%、加拿大5%GST、澳大利亚10%GST)以及6个自由贸易协定的减免规则(USMCA、AUSFTA、KORUS、EVFTA等)。
用户需提供HS编码、原产国、目的国、FOB货值、数量、运费等输入参数。当未提供运费时,脚本会按运输方式(海运$0.8/kg、空运$5.0/kg、快递$8.0/kg)和目的地进行估算。汇率数据为固定值,不随市场实时变动。HS编码数据库仅覆盖24个常见品类,非常规产品需用户手动输入准确的HS编码和税率。
局限性
- 基础关税率为章节级近似值,精确税率需以 HS 10位编码查询
- HS 编码数据库仅覆盖常见品类(24个),非常规产品需手动输入
- 运费估值为简化模型,实际费用受货代报价、航线、季节等因素影响
- 汇率数据为固定值,实际交易按实时汇率结算
- 不包含反倾销税、反补贴税等特殊关税
#!/usr/bin/env python3
"""
Tariff Calculator - Core Engine
TariffCalculate - Core Engine
Features:
- TariffTax RateQuery (HScode → Tax Rate)
- TariffCalculate (goodsValue × Tax Rate)
- VAT/GST Calculate
- to shoreCost (Landed Cost) CompleteCalculate
- Section 301 TariffQuery
- Trade agreement benefits
- many CurrencySupport
Version: 1.0.0
"""
import json
from dataclasses import dataclass, field
from typing import List, Dict, Optional, Tuple
from enum import Enum
from datetime import datetime
import sys
class Country(Enum):
"""Country/Region"""
CN = "CN" # in country
US = "US" # USA
EU = "EU" # EU
UK = "UK" # UK
CA = "CA" # Canada big
AU = "AU" # Australia
VN = "VN" # Vietnam
MX = "MX" # Mexico
IN = "IN" # printDegree
JP = "JP" # Daybasic
KR = "KR" # Korea
# ============================================================
# Tax RateData (2024)
# ============================================================
# BasicTariffTax Rate (MFN most MFN)
BASE_TARIFF_RATES = {
# HS Chapter before 2position → BasicTax Rate
"39": {"US": 0.065, "EU": 0.065, "UK": 0.065, "CA": 0.06, "AU": 0.05}, # Plastic
"42": {"US": 0.08, "EU": 0.04, "UK": 0.04, "CA": 0.08, "AU": 0.05}, # Leather products
"61": {"US": 0.12, "EU": 0.12, "UK": 0.12, "CA": 0.18, "AU": 0.10}, # Knitted apparel
"62": {"US": 0.12, "EU": 0.12, "UK": 0.12, "CA": 0.18, "AU": 0.10}, # Non-knitted apparel
"64": {"US": 0.10, "EU": 0.08, "UK": 0.08, "CA": 0.18, "AU": 0.05}, # shoeCategory
"84": {"US": 0.0, "EU": 0.02, "UK": 0.02, "CA": 0.0, "AU": 0.0}, # Mechanical equipment
"85": {"US": 0.0, "EU": 0.02, "UK": 0.02, "CA": 0.0, "AU": 0.0}, # Electronicelectric
"94": {"US": 0.0, "EU": 0.0, "UK": 0.0, "CA": 0.08, "AU": 0.05}, # Furniture
"95": {"US": 0.0, "EU": 0.045, "UK": 0.045, "CA": 0.0, "AU": 0.05}, # Toy
"default": {"US": 0.05, "EU": 0.05, "UK": 0.05, "CA": 0.05, "AU": 0.05},
}
# Section 301 Tariff ( in country → USA)
SECTION_301_RATES = {
# HS 4Digit code → AdditionalTax Rate
"8471": 0.25, # Computer
"8473": 0.25, # Computer accessories
"8504": 0.25, # Transformer/Power
"8517": 0.25, # Communication equipment
"8528": 0.25, # Display
"9403": 0.25, # Furniture
"9405": 0.25, # Lighting
"9503": 0.25, # Toy
"6110": 0.075, # Knit shirt
"6203": 0.075, # Men wear
"6204": 0.075, # Women wear
"6402": 0.075, # shoeCategory
"3926": 0.25, # Plastic products
"4202": 0.075, # boxPackage
}
# VAT/GST Tax Rate
VAT_RATES = {
"US": 0.0, # US has no federal VAT ( each state has Sales Tax)
"EU": 0.20, # EUAverage (Germany19%, France20%, meaning big profit22%)
"UK": 0.20, # UK VAT 20%
"CA": 0.05, # Canada big GST 5% (+ PST varies)
"AU": 0.10, # Australia GST 10%
}
# EU each country VAT
EU_VAT_RATES = {
"DE": 0.19, # Germany
"FR": 0.20, # France
"IT": 0.22, # meaning big profit
"ES": 0.21, # Spain
"NL": 0.21, # Netherlands
"PL": 0.23, # Poland
}
# Trade agreement benefits
TRADE_AGREEMENTS = {
("MX", "US"): {"name": "USMCA", "reduction": 1.0}, # 100% Exemption
("CA", "US"): {"name": "USMCA", "reduction": 1.0},
("VN", "EU"): {"name": "EVFTA", "reduction": 0.5}, # 50% Exemption
("AU", "US"): {"name": "AUSFTA", "reduction": 1.0},
("KR", "US"): {"name": "KORUS", "reduction": 1.0},
}
# CurrencyExchange rate ( for USD)
EXCHANGE_RATES = {
"USD": 1.0,
"EUR": 1.08,
"GBP": 1.26,
"CAD": 0.74,
"AUD": 0.65,
"CNY": 0.14,
"JPY": 0.0067,
}
# ============================================================
# Data Structures
# ============================================================
@dataclass
class ProductInfo:
"""ProductInformation"""
description: str = ""
hs_code: str = "" # 6-10position HScode
origin_country: str = "CN" # Country of origin
fob_value: float = 0.0 # FOB Price (USD)
quantity: int = 1
unit_weight_kg: float = 0.0
currency: str = "USD"
@dataclass
class ShippingInfo:
"""TransportInformation"""
destination_country: str = "US"
destination_eu_country: str = "" # EU specificCountry
shipping_method: str = "sea" # sea/air/express
freight_cost: float = 0.0 # Shipping (USD)
insurance_rate: float = 0.003 # InsuranceRate (0.3%)
@dataclass
class CostBreakdown:
"""Cost Breakdown"""
# Basic
fob_value: float = 0.0
freight: float = 0.0
insurance: float = 0.0
cif_value: float = 0.0
# Taxes and fees
base_tariff_rate: float = 0.0
base_tariff: float = 0.0
section_301_rate: float = 0.0
section_301_tariff: float = 0.0
total_tariff_rate: float = 0.0
total_tariff: float = 0.0
vat_rate: float = 0.0
vat: float = 0.0
# Miscellaneous fees
customs_clearance: float = 0.0
port_fees: float = 0.0
inland_freight: float = 0.0
other_fees: float = 0.0
# Summary
total_taxes_fees: float = 0.0
landed_cost: float = 0.0
landed_cost_per_unit: float = 0.0
# Trade agreement
trade_agreement: str = ""
tariff_reduction: float = 0.0
@dataclass
class TariffResult:
"""CalculateResult"""
product: ProductInfo
shipping: ShippingInfo
breakdown: CostBreakdown
hs_code_info: Dict
warnings: List[str]
summary: str
summary_zh: str
# ============================================================
# CoreCalculateFunction
# ============================================================
def get_hs_chapter(hs_code: str) -> str:
"""Get HS Chapter ( before 2position)"""
return hs_code[:2] if len(hs_code) >= 2 else "00"
def get_hs_heading(hs_code: str) -> str:
"""Get HS Tax ID ( before 4position)"""
return hs_code[:4] if len(hs_code) >= 4 else "0000"
def get_base_tariff_rate(hs_code: str, destination: str) -> float:
"""GetBasicTariffTax Rate"""
chapter = get_hs_chapter(hs_code)
rates = BASE_TARIFF_RATES.get(chapter, BASE_TARIFF_RATES["default"])
return rates.get(destination, 0.05)
def get_section_301_rate(hs_code: str, origin: str, destination: str) -> float:
"""Get Section 301 AdditionalTariff"""
if origin != "CN" or destination != "US":
return 0.0
heading = get_hs_heading(hs_code)
return SECTION_301_RATES.get(heading, 0.0)
def get_trade_agreement(origin: str, destination: str) -> Optional[Dict]:
"""Get trade agreement benefits"""
return TRADE_AGREEMENTS.get((origin, destination))
def get_vat_rate(destination: str, eu_country: str = "") -> float:
"""GetVAT/GST Tax Rate"""
if destination == "EU" and eu_country:
return EU_VAT_RATES.get(eu_country, VAT_RATES["EU"])
return VAT_RATES.get(destination, 0.0)
def estimate_freight(weight_kg: float, method: str, destination: str) -> float:
"""EstimateShipping"""
# Simple estimate
rates = {
"sea": {"US": 0.8, "EU": 1.0, "UK": 1.1, "CA": 0.7, "AU": 1.2}, # $/kg
"air": {"US": 5.0, "EU": 5.5, "UK": 5.5, "CA": 4.5, "AU": 6.0}, # $/kg
"express": {"US": 8.0, "EU": 9.0, "UK": 9.0, "CA": 7.5, "AU": 10.0}, # $/kg
}
rate = rates.get(method, rates["sea"]).get(destination, 1.0)
return weight_kg * rate
def calculate_landed_cost(
product: ProductInfo,
shipping: ShippingInfo,
customs_clearance: float = 150.0,
port_fees: float = 50.0,
inland_freight: float = 100.0,
other_fees: float = 0.0
) -> TariffResult:
"""Calculate to shoreCost"""
warnings = []
hs_info = {
"code": product.hs_code,
"chapter": get_hs_chapter(product.hs_code),
"heading": get_hs_heading(product.hs_code),
}
# 1. FOB
fob = product.fob_value
# 2. Shipping
freight = shipping.freight_cost
if freight == 0 and product.unit_weight_kg > 0:
total_weight = product.unit_weight_kg * product.quantity
freight = estimate_freight(total_weight, shipping.shipping_method, shipping.destination_country)
warnings.append(f"Freight estimated: ${freight:.2f} based on {total_weight}kg")
# 3. Insurance
insurance = fob * shipping.insurance_rate
# 4. CIF
cif = fob + freight + insurance
# 5. BasicTariff
base_rate = get_base_tariff_rate(product.hs_code, shipping.destination_country)
# 6. Section 301 ( in country→USA)
s301_rate = get_section_301_rate(product.hs_code, product.origin_country, shipping.destination_country)
if s301_rate > 0:
warnings.append(f"⚠️ Section 301 tariff applies: {s301_rate*100:.1f}%")
# 7. Trade agreement benefits
agreement = get_trade_agreement(product.origin_country, shipping.destination_country)
tariff_reduction = 0.0
agreement_name = ""
if agreement:
agreement_name = agreement["name"]
tariff_reduction = base_rate * agreement["reduction"]
base_rate = base_rate * (1 - agreement["reduction"])
warnings.append(f"✅ Trade agreement {agreement_name} applies: {agreement['reduction']*100:.0f}% tariff reduction")
# 8. totalTariff
total_tariff_rate = base_rate + s301_rate
total_tariff = cif * total_tariff_rate
# 9. VAT/GST
vat_rate = get_vat_rate(shipping.destination_country, shipping.destination_eu_country)
vat_base = cif + total_tariff # VAT UsuallyBased on CIF + Tariff
vat = vat_base * vat_rate
# 10. totalTaxes and fees
total_taxes = total_tariff + vat + customs_clearance + port_fees
# 11. to shoreCost
landed_cost = cif + total_taxes + inland_freight + other_fees
landed_cost_per_unit = landed_cost / product.quantity if product.quantity > 0 else landed_cost
breakdown = CostBreakdown(
fob_value=round(fob, 2),
freight=round(freight, 2),
insurance=round(insurance, 2),
cif_value=round(cif, 2),
base_tariff_rate=round(base_rate, 4),
base_tariff=round(cif * base_rate, 2),
section_301_rate=round(s301_rate, 4),
section_301_tariff=round(cif * s301_rate, 2),
total_tariff_rate=round(total_tariff_rate, 4),
total_tariff=round(total_tariff, 2),
vat_rate=round(vat_rate, 4),
vat=round(vat, 2),
customs_clearance=round(customs_clearance, 2),
port_fees=round(port_fees, 2),
inland_freight=round(inland_freight, 2),
other_fees=round(other_fees, 2),
total_taxes_fees=round(total_taxes, 2),
landed_cost=round(landed_cost, 2),
landed_cost_per_unit=round(landed_cost_per_unit, 2),
trade_agreement=agreement_name,
tariff_reduction=round(tariff_reduction, 4),
)
# Summary
summary = f"Landed Cost: ${landed_cost:.2f} | Tariff: {total_tariff_rate*100:.1f}% (${total_tariff:.2f}) | VAT: {vat_rate*100:.0f}%"
summary_zh = f" to shoreCost: ${landed_cost:.2f} | Tariff: {total_tariff_rate*100:.1f}% (${total_tariff:.2f}) | VAT: {vat_rate*100:.0f}%"
return TariffResult(
product=product,
shipping=shipping,
breakdown=breakdown,
hs_code_info=hs_info,
warnings=warnings,
summary=summary,
summary_zh=summary_zh,
)
# ============================================================
# OutputFormat
# ============================================================
def format_report(result: TariffResult, lang: str = "en") -> str:
"""FormatReport"""
p = result.product
s = result.shipping
b = result.breakdown
origin_names = {"CN": "China 🇨🇳", "VN": "Vietnam 🇻🇳", "MX": "Mexico 🇲🇽", "IN": "India 🇮🇳"}
dest_names = {"US": "USA 🇺🇸", "EU": "EU 🇪🇺", "UK": "UK 🇬🇧", "CA": "Canada 🇨🇦", "AU": "Australia 🇦🇺"}
origin_display = origin_names.get(p.origin_country, p.origin_country)
dest_display = dest_names.get(s.destination_country, s.destination_country)
if lang == "zh":
lines = [
"💰 **Tariff and to shoreCostCalculateReport**",
"",
f"**Product**: {p.description or 'N/A'}",
f"**HScode**: {p.hs_code}",
f"**Route**: {origin_display} → {dest_display}",
f"**Quantity**: {p.quantity} piece",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## 📦 Cost Breakdown",
"",
"```",
f"FOB goodsValue ${b.fob_value:>10,.2f}",
f"InternationalShipping ${b.freight:>10,.2f}",
f"Insurance fee (0.3%) ${b.insurance:>10,.2f}",
f"────────────────────────────────────",
f"CIF to CIF price ${b.cif_value:>10,.2f}",
"```",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## 🏛️ Taxes and feesBreakdown",
"",
"```",
f"BasicTariff ({b.base_tariff_rate*100:>5.1f}%) ${b.base_tariff:>10,.2f}",
]
if b.section_301_rate > 0:
lines.append(f"Section 301 ({b.section_301_rate*100:>4.1f}%) ${b.section_301_tariff:>10,.2f}")
lines.extend([
f"────────────────────────────────────",
f"totalTariff ({b.total_tariff_rate*100:>5.1f}%) ${b.total_tariff:>10,.2f}",
])
if b.vat_rate > 0:
lines.append(f"VAT/GST ({b.vat_rate*100:>4.0f}%) ${b.vat:>10,.2f}")
lines.extend([
f"Customs clearancefee ${b.customs_clearance:>10,.2f}",
f"Portfee ${b.port_fees:>10,.2f}",
f"────────────────────────────────────",
f"Taxes and feesTotal ${b.total_taxes_fees:>10,.2f}",
"```",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## 🚚 OtherFee",
"",
"```",
f" inside landShipping ${b.inland_freight:>10,.2f}",
f"Other Fees ${b.other_fees:>10,.2f}",
"```",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## 💵 to shoreCostSummary",
"",
"```",
f"CIF to CIF price ${b.cif_value:>10,.2f}",
f"Taxes and feesTotal ${b.total_taxes_fees:>10,.2f}",
f"OtherFee ${b.inland_freight + b.other_fees:>10,.2f}",
f"════════════════════════════════════",
f"total to shoreCost ${b.landed_cost:>10,.2f}",
f"Single pieceCost ${b.landed_cost_per_unit:>10,.2f}",
"```",
])
if result.warnings:
lines.extend([
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## ⚠️ NoticeItem",
"",
])
for w in result.warnings:
lines.append(f"• {w}")
lines.extend([
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
result.summary_zh,
])
else:
lines = [
"💰 **Tariff & Landed Cost Report**",
"",
f"**Product**: {p.description or 'N/A'}",
f"**HS Code**: {p.hs_code}",
f"**Route**: {origin_display} → {dest_display}",
f"**Quantity**: {p.quantity} units",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## 📦 Cost Breakdown",
"",
"```",
f"FOB Value ${b.fob_value:>10,.2f}",
f"International Freight ${b.freight:>10,.2f}",
f"Insurance (0.3%) ${b.insurance:>10,.2f}",
f"────────────────────────────────────",
f"CIF Value ${b.cif_value:>10,.2f}",
"```",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## 🏛️ Duties & Taxes",
"",
"```",
f"Base Tariff ({b.base_tariff_rate*100:>5.1f}%) ${b.base_tariff:>10,.2f}",
]
if b.section_301_rate > 0:
lines.append(f"Section 301 ({b.section_301_rate*100:>4.1f}%) ${b.section_301_tariff:>10,.2f}")
lines.extend([
f"────────────────────────────────────",
f"Total Tariff ({b.total_tariff_rate*100:>4.1f}%) ${b.total_tariff:>10,.2f}",
])
if b.vat_rate > 0:
lines.append(f"VAT/GST ({b.vat_rate*100:>4.0f}%) ${b.vat:>10,.2f}")
lines.extend([
f"Customs Clearance ${b.customs_clearance:>10,.2f}",
f"Port Fees ${b.port_fees:>10,.2f}",
f"────────────────────────────────────",
f"Total Taxes & Fees ${b.total_taxes_fees:>10,.2f}",
"```",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## 🚚 Other Costs",
"",
"```",
f"Inland Freight ${b.inland_freight:>10,.2f}",
f"Other Fees ${b.other_fees:>10,.2f}",
"```",
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## 💵 Landed Cost Summary",
"",
"```",
f"CIF Value ${b.cif_value:>10,.2f}",
f"Total Taxes & Fees ${b.total_taxes_fees:>10,.2f}",
f"Other Costs ${b.inland_freight + b.other_fees:>10,.2f}",
f"════════════════════════════════════",
f"Total Landed Cost ${b.landed_cost:>10,.2f}",
f"Cost Per Unit ${b.landed_cost_per_unit:>10,.2f}",
"```",
])
if result.warnings:
lines.extend([
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
"## ⚠️ Notices",
"",
])
for w in result.warnings:
lines.append(f"• {w}")
lines.extend([
"",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
"",
result.summary,
])
return "\n".join(lines)
# ============================================================
# CLI
# ============================================================
def main():
lang = "zh" if "--zh" in sys.argv else "en"
# DemoData
product = ProductInfo(
description="Wireless Bluetooth Earbuds",
hs_code="8518300000",
origin_country="CN",
fob_value=5000.00,
quantity=500,
unit_weight_kg=0.1,
)
shipping = ShippingInfo(
destination_country="US",
shipping_method="sea",
freight_cost=200.00,
insurance_rate=0.003,
)
# Calculate
result = calculate_landed_cost(product, shipping)
# Output
print(format_report(result, lang))
if __name__ == "__main__":
main()
#!/usr/bin/env python3
"""
HS Code Lookup & Matcher
HScodeQuery and smart can Match
Features:
- ProductDescription → HScodeRecommendation
- HScode → ProductCategoryother
- Section 301 ListQuery
- Common HScodeDataLibrary
Version: 1.0.0
"""
import re
from typing import List, Dict, Tuple
from dataclasses import dataclass
@dataclass
class HSCodeInfo:
"""HScodeInformation"""
code: str
description: str
description_zh: str
chapter: str
section_301: bool
section_301_rate: float
notes: str = ""
# ============================================================
# HScodeDataLibrary (Common e-commerceProduct)
# ============================================================
HS_DATABASE = {
# ElectronicProduct (Chapter 85)
"8517120000": HSCodeInfo(
code="8517120000",
description="Smartphones",
description_zh="Smartphone",
chapter="85",
section_301=True,
section_301_rate=0.0, # example outside
notes="Usually exempt from Section 301"
),
"8518300000": HSCodeInfo(
code="8518300000",
description="Headphones and earphones",
description_zh="Headphones",
chapter="85",
section_301=True,
section_301_rate=0.075,
),
"8471300000": HSCodeInfo(
code="8471300000",
description="Laptops and notebooks",
description_zh="Laptop computer",
chapter="84",
section_301=True,
section_301_rate=0.0, # example outside
notes="Currently exempt from Section 301"
),
"8504400000": HSCodeInfo(
code="8504400000",
description="Power adapters and chargers",
description_zh="Power adapter/Charging",
chapter="85",
section_301=True,
section_301_rate=0.25,
),
"8528590000": HSCodeInfo(
code="8528590000",
description="Monitors",
description_zh="Display",
chapter="85",
section_301=True,
section_301_rate=0.25,
),
# Home goods (Chapter 94)
"9403200000": HSCodeInfo(
code="9403200000",
description="Metal furniture",
description_zh="Metal furniture",
chapter="94",
section_301=True,
section_301_rate=0.25,
),
"9403600000": HSCodeInfo(
code="9403600000",
description="Wooden furniture",
description_zh="Wooden furniture",
chapter="94",
section_301=True,
section_301_rate=0.25,
),
"9405100000": HSCodeInfo(
code="9405100000",
description="Chandeliers and ceiling lights",
description_zh="Chandelier/Ceiling light",
chapter="94",
section_301=True,
section_301_rate=0.25,
),
"9405400000": HSCodeInfo(
code="9405400000",
description="LED lights and strips",
description_zh="LEDlight/Light strip",
chapter="94",
section_301=True,
section_301_rate=0.25,
),
# Apparel (Chapter 61/62)
"6109100000": HSCodeInfo(
code="6109100000",
description="Cotton T-shirts",
description_zh="CottonTshirt",
chapter="61",
section_301=True,
section_301_rate=0.075,
),
"6110200000": HSCodeInfo(
code="6110200000",
description="Cotton sweaters",
description_zh="Cotton sweater",
chapter="61",
section_301=True,
section_301_rate=0.075,
),
"6203420000": HSCodeInfo(
code="6203420000",
description="Men's cotton trousers",
description_zh="Men cotton pants",
chapter="62",
section_301=True,
section_301_rate=0.075,
),
"6204620000": HSCodeInfo(
code="6204620000",
description="Women's cotton trousers",
description_zh="Women cotton pants",
chapter="62",
section_301=True,
section_301_rate=0.075,
),
# shoeCategory (Chapter 64)
"6402990000": HSCodeInfo(
code="6402990000",
description="Rubber/plastic footwear",
description_zh="Rubber/Plastic shoes",
chapter="64",
section_301=True,
section_301_rate=0.075,
),
"6403990000": HSCodeInfo(
code="6403990000",
description="Leather footwear",
description_zh="Leather shoes",
chapter="64",
section_301=True,
section_301_rate=0.075,
),
"6404190000": HSCodeInfo(
code="6404190000",
description="Textile footwear",
description_zh="Textile shoes",
chapter="64",
section_301=True,
section_301_rate=0.075,
),
# boxPackage (Chapter 42)
"4202210000": HSCodeInfo(
code="4202210000",
description="Leather handbags",
description_zh="Leather handbag",
chapter="42",
section_301=True,
section_301_rate=0.075,
),
"4202920000": HSCodeInfo(
code="4202920000",
description="Backpacks and bags (textile)",
description_zh="backPackage/bag (Textile)",
chapter="42",
section_301=True,
section_301_rate=0.075,
),
# Toy (Chapter 95)
"9503000000": HSCodeInfo(
code="9503000000",
description="Toys and games",
description_zh="ToyAndGame",
chapter="95",
section_301=True,
section_301_rate=0.25,
),
# Plastic products (Chapter 39)
"3924100000": HSCodeInfo(
code="3924100000",
description="Plastic tableware and kitchenware",
description_zh="Plastic tableware/Kitchenware",
chapter="39",
section_301=True,
section_301_rate=0.25,
),
"3926909000": HSCodeInfo(
code="3926909000",
description="Other plastic articles",
description_zh="OtherPlastic products",
chapter="39",
section_301=True,
section_301_rate=0.25,
),
# Beauty care (Chapter 33)
"3304990000": HSCodeInfo(
code="3304990000",
description="Beauty and makeup products",
description_zh="BeautyProduct",
chapter="33",
section_301=False,
section_301_rate=0.0,
),
# Pet supplies
"6307900000": HSCodeInfo(
code="6307900000",
description="Pet beds and textile products",
description_zh="Pet bed/Textile products",
chapter="63",
section_301=True,
section_301_rate=0.075,
),
}
# Keywords → HScodeMapping
KEYWORD_MAPPING = {
# Electronic
"earphone": "8518300000",
"earbud": "8518300000",
"headphone": "8518300000",
"earbuds": "8518300000",
"Headphones": "8518300000",
"charger": "8504400000",
"adapter": "8504400000",
"Charging": "8504400000",
"monitor": "8528590000",
"Display": "8528590000",
"laptop": "8471300000",
"notebook": "8471300000",
"Computer": "8471300000",
"phone": "8517120000",
"smartphone": "8517120000",
"Phone": "8517120000",
# Home
"furniture": "9403600000",
"Furniture": "9403600000",
"desk": "9403200000",
"table": "9403200000",
"chair": "9401610000",
"light": "9405400000",
"lamp": "9405100000",
"light": "9405400000",
"led": "9405400000",
# Apparel
"t-shirt": "6109100000",
"tshirt": "6109100000",
"shirt": "6109100000",
"sweater": "6110200000",
"Sweater": "6110200000",
"pants": "6203420000",
"trousers": "6203420000",
"Pants": "6203420000",
# shoe
"shoe": "6402990000",
"footwear": "6402990000",
"sneaker": "6404190000",
"boot": "6403990000",
"shoe": "6402990000",
# boxPackage
"bag": "4202920000",
"backpack": "4202920000",
"handbag": "4202210000",
"Package": "4202920000",
# Toy
"toy": "9503000000",
"game": "9503000000",
"Toy": "9503000000",
# Plastic
"plastic": "3926909000",
"Plastic": "3926909000",
# Pet
"pet": "6307900000",
"Pet": "6307900000",
}
def search_hs_code(query: str) -> List[Tuple[str, HSCodeInfo, float]]:
"""Search HScode
Return: [(hs_code, info, confidence), ...]
"""
results = []
query_lower = query.lower()
# 1. Direct HScodeQuery
if query.isdigit() and len(query) >= 4:
for code, info in HS_DATABASE.items():
if code.startswith(query):
results.append((code, info, 1.0))
if results:
return sorted(results, key=lambda x: -x[2])
# 2. KeywordsMatch
for keyword, hs_code in KEYWORD_MAPPING.items():
if keyword in query_lower:
if hs_code in HS_DATABASE:
info = HS_DATABASE[hs_code]
confidence = 0.8 if len(keyword) > 3 else 0.6
results.append((hs_code, info, confidence))
# 3. DescriptionMatch
for code, info in HS_DATABASE.items():
desc_match = False
if query_lower in info.description.lower():
desc_match = True
confidence = 0.7
elif query_lower in info.description_zh:
desc_match = True
confidence = 0.7
if desc_match and (code, info, confidence) not in results:
results.append((code, info, confidence))
# remove heavy andSort
seen = set()
unique_results = []
for code, info, conf in sorted(results, key=lambda x: -x[2]):
if code not in seen:
seen.add(code)
unique_results.append((code, info, conf))
return unique_results[:5]
def get_hs_info(hs_code: str) -> HSCodeInfo:
"""Get HScodeDetails"""
# PreciseMatch
if hs_code in HS_DATABASE:
return HS_DATABASE[hs_code]
# before suffixMatch
for code, info in HS_DATABASE.items():
if code.startswith(hs_code) or hs_code.startswith(code[:4]):
return info
# Return default
chapter = hs_code[:2] if len(hs_code) >= 2 else "00"
return HSCodeInfo(
code=hs_code,
description=f"HS Chapter {chapter} product",
description_zh=f"HS number {chapter} chapterProduct",
chapter=chapter,
section_301=False,
section_301_rate=0.0,
notes="Custom HS code - verify with customs authority"
)
def format_search_results(results: List[Tuple[str, HSCodeInfo, float]], lang: str = "en") -> str:
"""FormatSearchResult"""
if not results:
if lang == "zh":
return "❌ Not foundMatch HScode,Please manuallyInputOr consult customs。"
return "❌ No matching HS codes found. Please enter manually or consult customs."
lines = []
if lang == "zh":
lines.append("🔍 **HScodeSearchResult**\n")
for i, (code, info, conf) in enumerate(results, 1):
conf_icon = "🟢" if conf >= 0.8 else "🟡" if conf >= 0.6 else "🔴"
s301 = f"⚠️ 301Tariff {info.section_301_rate*100:.1f}%" if info.section_301 and info.section_301_rate > 0 else ""
lines.append(f"**{i}. {code}** {conf_icon}")
lines.append(f" {info.description_zh}")
if s301:
lines.append(f" {s301}")
lines.append("")
else:
lines.append("🔍 **HS Code Search Results**\n")
for i, (code, info, conf) in enumerate(results, 1):
conf_icon = "🟢" if conf >= 0.8 else "🟡" if conf >= 0.6 else "🔴"
s301 = f"⚠️ Section 301: {info.section_301_rate*100:.1f}%" if info.section_301 and info.section_301_rate > 0 else ""
lines.append(f"**{i}. {code}** {conf_icon}")
lines.append(f" {info.description}")
if s301:
lines.append(f" {s301}")
lines.append("")
return "\n".join(lines)
# ============================================================
# CLI
# ============================================================
def main():
import sys
lang = "zh" if "--zh" in sys.argv else "en"
query = sys.argv[1] if len(sys.argv) > 1 and not sys.argv[1].startswith("--") else "earbuds"
results = search_hs_code(query)
print(format_search_results(results, lang))
if __name__ == "__main__":
main()