Git Product home page Git Product logo

easypost-python's Introduction

EasyPost Python Client Library

Build Status 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 by .travis.yml for CI)
  • Run the tests with py.test (./venv/bin/py.test -vs tests)

easypost-python's People

Contributors

abramclark avatar agconti avatar dev-guest-easypost avatar dlc37 avatar doriangray avatar gsinkin avatar jamesbeith avatar jontsai avatar jstreebin avatar justintime50 avatar k-funk avatar mbeale avatar mwaldt avatar rblakemesser avatar roehnan avatar roguelazer avatar sameerkumar18 avatar sawyer avatar shalakhin avatar thepsyjo avatar victoryftw avatar wyounas avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.