The official Python client calls the TariffTrust API for you: an HTS code, a country of origin and a customs value go in; every US import duty and fee that applies comes back, from the base rate of the tariff to Sections 301, 232, 201 and 338 and the entry fees, each with its rate, its amount and its official source. It needs Python 3.10 or later, is fully typed, and works sync or async.
Install it and estimate a product
pip install tarifftrust
Create a key in your workspace, keep it on your server, and set it as TARIFFTRUST_API_KEY:
from tarifftrust import TariffTrust client = TariffTrust() # reads TARIFFTRUST_API_KEY result = client.estimate(hts="6109.10.00.12", origin="CN", customs_value="10000") print(result.status, result.estimated_duty) for duty in result.duties or []: print(duty.name, duty.rate, duty.amount, duty.source.url if duty.source else None)
Read the answer
Read status first, then the amounts: they are decimal strings in US dollars, ready for Decimal. Unknown is never zero: when estimated_duty is None, the duty is not established, and missing says what to send again, or withheld what is left out for now. A question nobody answered is taken in its ordinary case, when it has one, and said in facts; one without is asked in missing.
A whole declaration
The merchandise processing fee has a minimum and a maximum per entry, not per product: adding up single-product estimates would overstate it. Several products entered together go in one call, with the fees counted once:
entry = client.estimate_entry(
transport_mode="ocean",
lines=[
{"reference": "PO-1042-1", "hts": "6109.10.00.12", "origin": "CN", "customs_value": "1000"},
{"reference": "PO-1042-2", "hts": "6109.10.00.12", "origin": "VN", "customs_value": "2500"},
],
)
print(entry.estimated_duty, entry.estimated_fees, entry.estimated_landed_cost)What the client does for you
- Safe retries. Each estimate carries an idempotency key: if the connection drops or the API asks to wait, the call is tried again with the same key, and it counts once in your quota.
- Errors you can act on. Each refusal is its own exception, with its code, the fields refused and the request id to quote to support.
- Types from the contract. Every field of a request and of an answer is typed and described, generated from the OpenAPI contract the API serves.
The client also estimates a batch of products, the duties of a product over a period, and saves an estimate to read its detail again later: see its guide in the repository, and the package on PyPI.
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.