Skip to main content

Rating

Fetch

Using the fluent API with a gateway previously initialized, you can fetch live shipping rates

import karrio
from karrio.core.models import RateRequest

request = RateRequest(...)

rates, messages = karrio.Rating.fetch(request).from_(carrier_gateway).parse()
tip

In a multi-carrier integration, we would often want to get shipping quotes from multiple carriers. That can be achieve by fetching from multiple gateways

e.g: karrio.Rating.fetch(request).from_(candapost_gateway, purolator_gateway, ...).parse()

Parameters

RateRequest

NameTypeDescription
shipperAddressrequired
recipientAddressrequired
parcelsList[Parcel]required
servicesList[str]
optionsdict
referencestr

Address

NameTypeDescription
idstr
postal_codestr
citystr
person_namestr
company_namestr
country_codestr
emailstr
phone_numberstr
state_codestr
residentialbool
address_line1str
address_line2str
federal_tax_idstr
state_tax_idstr
extraAddressExtra

AddressExtra

NameTypeDescription
street_namestr
street_numberstr
street_typestr
suburbstr
suitestr

Parcel

NameTypeDescription
idstr
weightfloat
widthfloat
heightfloat
lengthfloat
packaging_typestr
package_presetstr
descriptionstr
contentstr
is_documentbool
weight_unitstr
dimension_unitstr

Response

RateDetails

NameTypeDescription
carrier_namestrrequired
carrier_idstrrequired
currencystrrequired
transit_daysint
servicestr
discountfloat
base_chargefloat
total_chargefloat
duties_and_taxesfloat
extra_chargesList[ChargeDetails]
metadict
idstr

ChargeDetails

NameTypeDescription
namestr
amountfloat
currencystr

Message

NameTypeDescription
carrier_namestrrequired
carrier_idstrrequired
messageUnion[str, Any]
codestr
detailsdict

Code sample

import karrio
from karrio.core.models import Address, Parcel, RateRequest

shipper = Address(
postal_code="V6M2V9",
city="Vancouver",
country_code="CA",
state_code="BC",
address_line1="5840 Oak St"
)

recipient = Address(
postal_code="E1C4Z8",
city="Moncton",
country_code="CA",
state_code="NB",
residential=False,
address_line1="125 Church St"
)

parcel = Parcel(
height=3.0,
length=6.0,
width=3.0,
weight=0.5,
weight_unit='KG',
dimension_unit='CM'
)

request = karrio.Rating.fetch(
RateRequest(
shipper=shipper,
recipient=recipient,
parcels=[parcel],
services=["canadapost_xpresspost"]
)
)

rates, messages = request.from_(carrier_gateway).parse()
On success
print(rates)
# [
# RateDetails(
# carrier_name="canadapost",
# carrier_id="canadapost",
# currency="CAD",
# transit_days=2,
# service="canadapost_xpresspost",
# discount=1.38,
# base_charge=12.26,
# total_charge=13.64,
# duties_and_taxes=0.0,
# extra_charges=[
# ChargeDetails(name="Automation discount", amount=-0.37, currency="CAD"),
# ChargeDetails(name="Fuel surcharge", amount=1.75, currency="CAD"),
# ],
# meta=None,
# id=None,
# )
# ]