The landed cost of a unit is what it costs once it is in your warehouse: its price, plus its share of the US duties, the entry fees, the freight and the insurance. A short Python script reads a purchase order, estimates it as one US import declaration with the official client, and prints the landed cost per unit of each SKU. Replace the CSV file with a query to your ERP or inventory system, and the result can go back into it.
Run the example
pip install tarifftrust TARIFFTRUST_API_KEY=tarifftrust_... python landed_cost.py purchase_order.csv
The order is a CSV file with one line per SKU:
sku,hts,origin,customs_value,quantity TEE-001,6109.10.00.12,CN,10000,2000 TEE-002,6109.10.00.12,VN,5000,1000
One declaration, so that the fees count once
The merchandise processing fee (MPF) has a minimum and a maximum per entry, not per product: adding up single-product estimates would overstate it. The script sends the whole order in one call, with its mode of transport, its freight and its insurance:
entry = client.estimate_entry(
reference=reference,
transport_mode="ocean",
freight=FREIGHT,
insurance=INSURANCE,
lines=[
{"reference": line["sku"], "hts": line["hts"], "origin": line["origin"],
"customs_value": line["customs_value"]}
for line in order
],
)Spread what the order pays once
Each line keeps its own duty; the fees, the freight and the insurance are spread by customs value, then divided by the quantity. Use your own allocation rule if your accounting has one:
cost = value + duty + (fees + FREIGHT + INSURANCE) * value / total_value
unit = (cost / int(line["quantity"])).quantize(CENT, ROUND_HALF_UP)A line whose duty is unknown stays unknown: the script prints "unknown" for its landed cost rather than counting the duty as zero, and lists what to send for it, such as an answer to a question about the goods.
The whole example
The complete, runnable example is in the public repository of the official clients, under the MIT license. The API reference describes every field of the request and of the answer, the errors and how to retry safely, and the integration guides how to read an answer and estimate a declaration.