Skip to content

Instantly share code, notes, and snippets.

@joncalhoun
Created October 25, 2012 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joncalhoun/3950772 to your computer and use it in GitHub Desktop.
Save joncalhoun/3950772 to your computer and use it in GitHub Desktop.
EasyPost Python Examples
import easypost
easypost.api_key = 'rWI791GTPCIwGMaQEGFQmJyEeZ925kln'
# Setting up data...
to_address = {
"street1": '388 Townsend St',
"street2": 'Apt 20',
"city": 'San Francisco',
"state": 'CA',
"zip": '94107'
}
from_address = {
"street1":"10 Hacker Way",
"city":"Menlo Park",
"state":"CA",
"zip":"94025"
}
parcel = {
"length": "9",
"width": "5",
"height": "2",
"weight": "12"
}
# Verify the 'to' address...
verified_data = easypost.Address.verify(address = to_address)
rates_data = easypost.Postage.rates(**{
"to": verified_data.address.to_dict(),
"from": from_address,
"parcel": parcel
})
# Buying postage...
to_person = {
"name": "Jon Calhoun",
"phone": "4445556666",
"email": "jon@easypost.co",
"address": verified_data.address.to_dict()
}
from_person = {
"name": "Jarrett Streebin",
"phone": "1112223333",
"email": "jarrett@easypost.co",
"address": from_address
}
label_data = easypost.Postage.buy(**{
"to": to_person,
"from": from_person,
"parcel": parcel,
"carrier": rates_data.rates[0].carrier,
"service": rates_data.rates[0].service
})
print 'Success: %r' % (label_data, )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment