Skip to content

Latest commit

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

USPS API

Python 3.5, 3.6, 3.7, 3.8Code CoverageMIT License


This is a simple Python wrapper for the USPS API. Instead of having to deal with XML, use this library and receive nicely formatted JSON back while tracking shipments, creating shipments, and validating addresses.

Installation

To install usps-api, use pip:

pip install usps-api

Or to install from source:

python setup.py install

Configuration

Note: In order to use any of these APIs, you need to register with USPS and get a USERID https://www.usps.com/business/web-tools-apis/welcome.htm. For the create_shipment endpoint, you will also need to request further permissions by emailing uspstechnicalsupport@mailps.custhelp.com about Label API access.

Usage

Track Shipments

fromuspsimportUSPSApiusps=USPSApi('XXXXXXXXXXXX')
track=usps.track('00000000000000000000')
print(track.result)

Create Shipment

The create_shipment function needs a to and from address, weight (in ounces), service type and label type. Service types and lable types can be found in usps/constants.py. Defaults are SERVICE_PRIORITY and LABEL_ZPL.

fromuspsimportUSPSApi, AddressfromuspsimportSERVICE_PRIORITY, LABEL_ZPLto_address=Address(
name='Tobin Brown',
address_1='1234 Test Ave.',
city='Test',
state='NE',
zipcode='55555'
)
from_address=Address(
name='Tobin Brown',
address_1='1234 Test Ave.',
city='Test',
state='NE',
zipcode='55555'
)
weight=12# weight in ouncesusps=USPSApi('XXXXXXXXXXXX', test=True)
label=usps.create_label(to_address, from_address, weight, SERVICE_PRIORITY, LABEL_ZPL)
print(label.result)

Validate Address

fromuspsimportUSPSApi, Addressaddress=Address(
name='Tobin Brown',
address_1='1234 Test Ave.',
city='Test',
state='NE',
zipcode='55555'
)
usps=USPSApi('XXXXXXXXXXXX', test=True)
validation=usps.validate_address(address)
print(validation.result)

License

MIT. See LICENSE for more details.

About

Python Wrapper for the USPS API 🚚 📦

Topics

Resources

Stars

60 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages