EasyPost is the simple shipping API. You can sign up for an account at https://easypost.com.
Looking for a client library for another language? Check out https://www.easypost.com/docs/libraries.
You can install easypost via pip with:
pip install easypostAlternatively, you can clone the EasyPost python client repository:
git clone https://github.com/EasyPost/easypost-pythonInstall Locally:
make installImport the EasyPost client:
import easypostimport easypost
easypost.api_key = '<YOUR API KEY FROM https://www.easypost.com/account/api-keys>'
# create and verify addresses
to_address = easypost.Address.create(
verify=["delivery"],
name = "Dr. Steve Brule",
street1 = "179 N Harbor Dr",
street2 = "",
city = "Redondo Beach",
state = "CA",
zip = "90277",
country = "US",
phone = "310-808-5243"
)
from_address = easypost.Address.create(
verify=["delivery"],
name = "EasyPost",
street1 = "118 2nd Street",
street2 = "4th Floor",
city = "San Francisco",
state = "CA",
zip = "94105",
country = "US",
phone = "415-456-7890"
)
# create parcel
try:
parcel = easypost.Parcel.create(
predefined_package = "Parcel",
weight = 21.2
)
except easypost.Error as e:
print(str(e))
if e.param is not None:
print('Specifically an invalid param: %r' % e.param)
parcel = easypost.Parcel.create(
length = 10.2,
width = 7.8,
height = 4.3,
weight = 21.2
)
# create customs_info form for intl shipping
customs_item = easypost.CustomsItem.create(
description = "EasyPost t-shirts",
hs_tariff_number = 123456,
origin_country = "US",
quantity = 2,
value = 96.27,
weight = 21.1
)
customs_info = easypost.CustomsInfo.create(
customs_certify = 1,
customs_signer = "Hector Hammerfall",
contents_type = "gift",
contents_explanation = "",
eel_pfc = "NOEEI 30.37(a)",
non_delivery_option = "return",
restriction_type = "none",
restriction_comments = "",
customs_items = [customs_item]
)
# create shipment
shipment = easypost.Shipment.create(
to_address = to_address,
from_address = from_address,
parcel = parcel,
customs_info = customs_info
)
# buy postage label with one of the rate objects
shipment.buy(rate = shipment.rates[0])
# alternatively: shipment.buy(rate = shipment.lowest_rate())
print(shipment.tracking_code)
print(shipment.postage_label.label_url)
# Insure the shipment for the value
shipment.insure(amount=100)
print(shipment.insurance)Up-to-date documentation is available at: https://www.easypost.com/docs
- Add new features to CHANGELOG.md
- Bump the version in
easypost/version.py - Bump the version in
setup.py - Create and push a signed git tag
- Create a Release in Github based on the tag, with a human-readable summary of changes
- Build sdist and wheel:
rm -rf build/ dist/ ./*.egg-info; python3 setup.py sdist bdist_wheel - Push to PyPI with
twine upload dist/*
# Run tests
EASYPOST_TEST_API_KEY=123... EASYPOST_PROD_API_KEY=123... make test
# Run test coverage
EASYPOST_TEST_API_KEY=123... EASYPOST_PROD_API_KEY=123... make coverage