Skip to main content

EasyPost Shipping API Client Library for Python

Project description

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 (if not on Google App Engine)
  • six

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 and setup.py
  3. Create a git tag
  4. 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)
  • 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)

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

easypost-5.1.1.tar.gz (15.2 kB view details)

Uploaded Source

Built Distributions

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

easypost-5.1.1-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

easypost-5.1.1-py2-none-any.whl (9.8 kB view details)

Uploaded Python 2

File details

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

File metadata

  • Download URL: easypost-5.1.1.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for easypost-5.1.1.tar.gz
Algorithm Hash digest
SHA256 c0571137cd5177639467e89f4177091e80fcced70aa1a059477b32da98d7203f
MD5 68694179aaddd285475de22cf0e72bab
BLAKE2b-256 f1809af1d7e9ee456525794f0ff21f844635ce6bd2c89faf0050553a70a29b4a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easypost-5.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for easypost-5.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46a7831cd6774b7c92d8f1b7765a03ad001fdf09afac010db583d019b8ccc388
MD5 705f2c44040bbc64f8c78da2f4c9df63
BLAKE2b-256 666c7ae43ff25420610a16d81305a80354d67b79d55eb56d8735be176f4f5ff6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easypost-5.1.1-py2-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for easypost-5.1.1-py2-none-any.whl
Algorithm Hash digest
SHA256 f55d05eea5ec39ad50a62c39982432524d400a50ecdc5c64ea89c57d3b74d14d
MD5 c92b0a7d9b831889b3c55d35a116827c
BLAKE2b-256 1ad80760deba1935c5ffa4ef1f8b29fb714f9830b635045c1fefa608fde02df7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page