Skip to main content

EasyPost Python Client Library

CI PyPI version

EasyPost is the simple shipping API. You can sign up for an account at https://easypost.com.

Requirements

  • Python 2.7 or 3.3+ (or corresponding PyPy versions). Note that we only test on Python 2.7 and 3.5+; we strongly recommend against using 3.3.x or 3.4.x as they are no longer supported by many libraries.
  • requests >= v2.4.3 (if not on Google App Engine) (will be installed automatically)
  • six (will be installed automatically)

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

  1. Add new features to CHANGELOG.md
  2. Bump the version in easypost/version.py
  3. Bump the version in setup.py
  4. Create and push a signed git tag
  5. Create a Release in Github based on the tag, with a human-readable summary of changes
  6. Build sdist and wheel: rm -rf build/ dist/ ./*.egg-info; python3 setup.py sdist bdist_wheel
  7. Push to PyPI with twine upload dist/*

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)
  • Export $TEST_API_KEY and $PROD_API_KEY appropriately (these are set automatically for CI)
  • Run the tests with py.test (./venv/bin/py.test -vs tests)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easypost-6.0.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

easypost-6.0.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

easypost-6.0.0-py2-none-any.whl (9.4 kB view details)

Uploaded Python 2

File details

Details for the file easypost-6.0.0.tar.gz.

File metadata

  • Download URL: easypost-6.0.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for easypost-6.0.0.tar.gz
Algorithm Hash digest
SHA256 638bb5554195ba2997254678f9fda677614a792302e6fa7563f06cd088ee8beb
MD5 3ad137d93f2ec406a5f6a0db266cac64
BLAKE2b-256 659be3586df8909b3c64c272ef0925c4c7fec0ce251a8ad8d08387d75397c885

See more details on using hashes here.

File details

Details for the file easypost-6.0.0-py3-none-any.whl.

File metadata

  • Download URL: easypost-6.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for easypost-6.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6988ba09470bfd6f9c484e80993504d9034f643ca509103194ba1ec1a25f2072
MD5 a3729b4f3295143179a58992f0129dca
BLAKE2b-256 aed14b14452ca2664b865fd789dcab65b270d56715798f0c73f0bb37ae07ee5e

See more details on using hashes here.

File details

Details for the file easypost-6.0.0-py2-none-any.whl.

File metadata

  • Download URL: easypost-6.0.0-py2-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for easypost-6.0.0-py2-none-any.whl
Algorithm Hash digest
SHA256 34be12aa931d2a0d24cb46cbf4b83044999fb957a887e778ab2b4e4378121f76
MD5 512f8874d2877c0719f17b390efe62ae
BLAKE2b-256 904c612053cc023af408e2dac52bec17c7154459e2faf9dc6196d927937418bd

See more details on using hashes here.

Release history Release notifications | RSS feed

10.7.0

2 files

10.6.0

2 files

10.5.1

2 files

10.5.0

2 files

10.4.0

2 files

10.3.0

2 files

10.2.0

2 files

10.1.0

2 files

10.0.1

2 files

10.0.0

2 files

9.5.0

2 files

9.4.1

2 files

9.4.0

2 files

9.3.0

2 files

9.2.0

2 files

9.1.0

2 files

9.0.1

2 files

9.0.0

2 files

8.2.1

2 files

8.2.0

2 files

8.1.1

2 files

8.1.0

2 files

8.0.0

2 files

7.15.0

2 files

7.14.1

2 files

7.14.0

2 files

7.13.1

2 files

7.13.0

2 files

7.12.0

2 files

7.11.0

2 files

7.10.0

2 files

7.9.0

2 files

7.8.0

2 files

7.7.0

2 files

7.6.1

2 files

7.6.0

2 files

7.5.0

2 files

7.4.0

2 files

7.3.0

2 files

7.2.0

2 files

7.1.1

2 files

7.1.0

2 files

7.0.0

2 files

6.0.1

2 files

This release

6.0.0 This release

3 files

5.1.3

3 files

5.1.2

3 files

5.1.1

3 files

5.1.0

3 files

5.0.0

3 files

4.1.0

3 files

4.0.2

3 files

4.0.1

3 files

4.0.0

3 files

3.6.5

3 files

3.6.3

3 files

3.6.2

1 file

3.6.1

1 file

3.6.0

1 file

3.5.2

1 file

3.5.1

1 file

3.5.0

1 file

3.4.0

1 file

3.3.0

1 file

3.2.2

1 file

3.2.1

1 file

3.2.0

1 file

3.1.3

1 file

3.1.2

1 file

3.1.1

1 file

3.1.0

1 file

3.0.6

1 file

3.0.5

1 file

3.0.4

1 file

3.0.3

1 file

3.0.2

1 file

3.0.1

1 file

3.0.0

1 file

2.0.16

1 file

2.0.14

1 file

2.0.12

1 file

2.0.11

1 file

2.0.10

1 file

2.0.9

1 file

2.0.8

1 file

2.0.7

1 file

2.0.6

1 file

2.0.5

1 file

2.0.4

1 file

2.0.3

1 file

2.0.2

1 file

2.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page