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
from usps import USPSApi
usps = 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.
from usps import USPSApi, Address
from usps import SERVICE_PRIORITY, LABEL_ZPL
to_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 ounces
usps = USPSApi('XXXXXXXXXXXX', test=True)
label = usps.create_label(to_address, from_address, weight, SERVICE_PRIORITY, LABEL_ZPL)
print(label.result)
Validate Address
from usps import USPSApi, Address
address = 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.
Metadata
Release files for usps-api 0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| usps-api-0.5.tar.gz | 5.0 kB | Details |
Release files / usps-api-0.5.tar.gz
| Download URL | usps-api-0.5.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20c2f19e02dde3eac01b794d6a4c1bcad03ab681d67a8579d090dbda5e5247a3
|
|
BLAKE2b-256 checksum How to use checksums |
1b74c3040f76285c9b7be3e72a7a94e0ef100ea94a93dcab0170bf5a60fee623
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.10.0 pkginfo/1.2.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.9
|