EasyPost Python Client Library
EasyPost is the simple shipping API. You can sign up for an account at https://easypost.com.
Requirements
Looking for a client library for another language? Check out https://www.easypost.com/docs/libraries.
Installation
You can install easypost via pip with:
pip install easypost
Alternatively, you can clone the EasyPost python client repository:
git clone https://github.com/EasyPost/easypost-python
Install:
python setup.py install
Import the EasyPost client:
import easypost
Example
import 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)
Documentation
Up-to-date documentation is available at: https://www.easypost.com/docs
Client Library Development
Releasing
- Add new features to CHANGELOG.md
- Bump the version in
easypost/version.pyandsetup.py - Create a git tag
- Push to PyPI with
python setup.py sdist upload
Running Tests
To run tests:
- Create a virtualenv for your version of Python (e.g.,
python2.7 -m virtualenv venv) - Install dependencies in that virtualenv (
./venv/bin/pip install requests six) - Install test dependencies (
./venv/bin/pip install -r requirements-tests.txt) - Run the tests with
py.test(./venv/bin/py.test -vs tests)
Release files for easypost 4.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| easypost-4.0.2.tar.gz | 13.5 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| easypost-4.0.2-py3-none-any.whl | Python 3 | none | any | Details |
| easypost-4.0.2-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 33.8 kB
Release files / easypost-4.0.2.tar.gz
| Download URL | easypost-4.0.2.tar.gz |
|---|---|
| Size | 13.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4c15fe8ce3f71142c8db8c8c13470664b46f8d3a8d60bf2ed7e4362555353725
|
|
BLAKE2b-256 checksum How to use checksums |
558b4efa8e6573f6835ac260374ecd6ed61c324c4c01f27459c8ea84696ce84c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.6
|
Release files / easypost-4.0.2-py3-none-any.whl
| Download URL | easypost-4.0.2-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca64f0ee25a6a2129a0bee9883f641384721850aa0b3b250ad5b469e98621e0f
|
|
BLAKE2b-256 checksum How to use checksums |
02d3985f1d9807c8d71742794e5bdab0c753707553aa5af25af66173e328dda3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.6
|
Release files / easypost-4.0.2-py2-none-any.whl
| Download URL | easypost-4.0.2-py2-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
b4c92884134ae48df3ed02dee31296f8ea4bf27c9ae9d8ba14facee72a56aab6
|
|
BLAKE2b-256 checksum How to use checksums |
468a47b46d2650e949f9c73c114e9df214d91d13bbc355fa99ffd86763550ac8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.6
|