Given some shipment details and rate options, this method returns a list of rate quotes. Please see our docs to learn more about calculating rates.
The get_rates_from_shipment
method accepts shipment related params as seen below.
shipment = {
"rate_options": {"carrier_ids": ["se-656171"]},
"shipment": {
"validate_address": "no_validation",
"ship_to": {
"name": "Amanda Miller",
"phone": "555-555-5555",
"address_line1": "525 S Winchester Blvd",
"city_locality": "San Jose",
"state_province": "CA",
"postal_code": "95128",
"country_code": "US",
"address_residential_indicator": "yes",
},
"ship_from": {
"company_name": "Example Corp.",
"name": "John Doe",
"phone": "111-111-1111",
"address_line1": "4008 Marathon Blvd",
"address_line2": "Suite 300",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "no",
},
"packages": [{"weight": {"value": 1, "unit": "ounce"}}],
},
}
The get_rates_from_shipment
method returns a set of rates that corresopnd to the shipment
details that you pass in.
- Pass in a dictionary of shipment details you wish to fetch shipping rates for.
import os
from shipengine import ShipEngine
from shipengine.errors import ShipEngineError
def get_rate_from_shipment_demo():
api_key = os.getenv("SHIPENGINE_API_KEY")
shipengine = ShipEngine(
{"api_key": api_key, "page_size": 75, "retries": 3, "timeout": 10}
)
try:
shipment = {
"rate_options": {"carrier_ids": ["se-656171"]},
"shipment": {
"validate_address": "no_validation",
"ship_to": {
"name": "Amanda Miller",
"phone": "555-555-5555",
"address_line1": "525 S Winchester Blvd",
"city_locality": "San Jose",
"state_province": "CA",
"postal_code": "95128",
"country_code": "US",
"address_residential_indicator": "yes",
},
"ship_from": {
"company_name": "Example Corp.",
"name": "John Doe",
"phone": "111-111-1111",
"address_line1": "4008 Marathon Blvd",
"address_line2": "Suite 300",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "no",
},
"packages": [{"weight": {"value": 1, "unit": "ounce"}}],
},
}
result = shipengine.get_rates_from_shipment(shipment=shipment)
print("::SUCCESS::")
print(result)
except ShipEngineError as err:
print("::ERROR::")
print(err.to_json())
get_rate_from_shipment_demo()
- A list of shipping rates that correspond to the shipment details provided.
{
"rate_response": {
"rates": [
{
"rate_id": "se-799373191",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 0.5100},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "letter",
"delivery_days": 3,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-09T00:00:00Z",
"carrier_delivery_days": "3",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS First Class Mail",
"service_code": "usps_first_class_mail",
"trackable": False,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373192",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 1.0000},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "large_envelope_or_flat",
"delivery_days": 3,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-09T00:00:00Z",
"carrier_delivery_days": "3",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS First Class Mail",
"service_code": "usps_first_class_mail",
"trackable": False,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373193",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 3.3500},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "package",
"delivery_days": 3,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-09T00:00:00Z",
"carrier_delivery_days": "3",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS First Class Mail",
"service_code": "usps_first_class_mail",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373194",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 8.5200},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "package",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail",
"service_code": "usps_priority_mail",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373195",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 13.7500},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "medium_flat_rate_box",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail",
"service_code": "usps_priority_mail",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373196",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 7.9000},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "small_flat_rate_box",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail",
"service_code": "usps_priority_mail",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373197",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 19.3000},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "large_flat_rate_box",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail",
"service_code": "usps_priority_mail",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373198",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 7.4000},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "flat_rate_envelope",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail",
"service_code": "usps_priority_mail",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373199",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 8.0000},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "flat_rate_padded_envelope",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail",
"service_code": "usps_priority_mail",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373200",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 11.6300},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "regional_rate_box_a",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail",
"service_code": "usps_priority_mail",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373201",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 20.1000},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "regional_rate_box_b",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail",
"service_code": "usps_priority_mail",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373202",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 7.7000},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "flat_rate_legal_envelope",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail",
"service_code": "usps_priority_mail",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373203",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 31.4000},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "package",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "1-2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail Express",
"service_code": "usps_priority_mail_express",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373204",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 22.7500},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "flat_rate_envelope",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "1-2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail Express",
"service_code": "usps_priority_mail_express",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373205",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 23.2500},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "flat_rate_padded_envelope",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "1-2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail Express",
"service_code": "usps_priority_mail_express",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373206",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 22.9500},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "flat_rate_legal_envelope",
"delivery_days": 2,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-07T00:00:00Z",
"carrier_delivery_days": "1-2",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Priority Mail Express",
"service_code": "usps_priority_mail_express",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373207",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 2.8900},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "package",
"delivery_days": 6,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-12T00:00:00Z",
"carrier_delivery_days": "6",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Media Mail",
"service_code": "usps_media_mail",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
{
"rate_id": "se-799373208",
"rate_type": "shipment",
"carrier_id": "se-656171",
"shipping_amount": {"currency": "usd", "amount": 7.9700},
"insurance_amount": {"currency": "usd", "amount": 0.0},
"confirmation_amount": {"currency": "usd", "amount": 0.0},
"other_amount": {"currency": "usd", "amount": 0.0},
"zone": 7,
"package_type": "package",
"delivery_days": 6,
"guaranteed_service": False,
"estimated_delivery_date": "2021-08-12T00:00:00Z",
"carrier_delivery_days": "6",
"ship_date": "2021-08-05T00:00:00Z",
"negotiated_rate": False,
"service_type": "USPS Parcel Select Ground",
"service_code": "usps_parcel_select",
"trackable": True,
"carrier_code": "stamps_com",
"carrier_nickname": "ShipEngine Test Account - Stamps.com",
"carrier_friendly_name": "Stamps.com",
"validation_status": "valid",
"warning_messages": [],
"error_messages": [],
},
],
"invalid_rates": [],
"rate_request_id": "se-87190257",
"shipment_id": "se-144794216",
"created_at": "2021-08-05T16:46:52.7833033Z",
"status": "completed",
"errors": [],
},
"shipment_id": "se-144794216",
"carrier_id": "se-656171",
"service_code": None,
"external_shipment_id": None,
"ship_date": "2021-08-05T00:00:00Z",
"created_at": "2021-08-05T16:46:52.087Z",
"modified_at": "2021-08-05T16:46:52.073Z",
"shipment_status": "pending",
"ship_to": {
"name": "Amanda Miller",
"phone": "555-555-5555",
"company_name": None,
"address_line1": "525 S Winchester Blvd",
"address_line2": None,
"address_line3": None,
"city_locality": "San Jose",
"state_province": "CA",
"postal_code": "95128",
"country_code": "US",
"address_residential_indicator": "yes",
},
"ship_from": {
"name": "John Doe",
"phone": "111-111-1111",
"company_name": "Example Corp.",
"address_line1": "4008 Marathon Blvd",
"address_line2": "Suite 300",
"address_line3": None,
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "unknown",
},
"warehouse_id": None,
"return_to": {
"name": "John Doe",
"phone": "111-111-1111",
"company_name": "Example Corp.",
"address_line1": "4008 Marathon Blvd",
"address_line2": "Suite 300",
"address_line3": None,
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "unknown",
},
"confirmation": None,
"customs": {
"contents": "merchandise",
"customs_items": [],
"non_delivery": "return_to_sender",
},
"external_order_id": None,
"order_source_code": None,
"advanced_options": {
"bill_to_account": None,
"bill_to_country_code": None,
"bill_to_party": None,
"bill_to_postal_code": None,
"contains_alcohol": False,
"delivered_duty_paid": False,
"non_machinable": False,
"saturday_delivery": False,
"dry_ice": False,
"dry_ice_weight": None,
"freight_class": None,
"custom_field1": None,
"custom_field2": None,
"custom_field3": None,
"collect_on_delivery": None,
},
"insurance_provider": None,
"tags": [],
"packages": [
{
"package_code": "package",
"weight": {"value": 1.00, "unit": "ounce"},
"dimensions": {"unit": "inch", "length": 0.0, "width": 0.0, "height": 0.0},
"insured_value": {"currency": "usd", "amount": 0.00},
"label_messages": {
"reference1": None,
"reference2": None,
"reference3": None,
},
"external_package_id": None,
}
],
"total_weight": {"value": 1.00, "unit": "ounce"},
"items": [],
}
- This method will only throw an exception that is an instance/extension of (ShipEngineError) if there is a problem if a problem occurs, such as a network error or an error response from the API.