Skip to main content

Python wrapper for the USPS API

Project description

Python 2.7, 3.x MIT 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

from usps import USPSApi

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

Create Shipment

The create_shipment function needs a to and crom 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.

Project details


Download files

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

Source Distribution

usps-api-0.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

usps_api-0.1-py3.5.egg (7.8 kB view details)

Uploaded Egg

File details

Details for the file usps-api-0.1.tar.gz.

File metadata

  • Download URL: usps-api-0.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.2

File hashes

Hashes for usps-api-0.1.tar.gz
Algorithm Hash digest
SHA256 799f1149cba98a1e48154afecedcf7497afdcf1bb661476d07a4e1553052c1cf
MD5 938968d2a4eb4727eaeded94e1148484
BLAKE2b-256 a0d3a3c81e0bf70df752526a48a88376e957f98353a9014f549e331adfefef95

See more details on using hashes here.

File details

Details for the file usps_api-0.1-py3.5.egg.

File metadata

  • Download URL: usps_api-0.1-py3.5.egg
  • Upload date:
  • Size: 7.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.2

File hashes

Hashes for usps_api-0.1-py3.5.egg
Algorithm Hash digest
SHA256 3048dd8e5dca815201829f619fca1ff3710092bd5e6456ed5f3fb3c9f7eac1f4
MD5 6648d0f6875869cf7f26ff345c72bc84
BLAKE2b-256 bb8b4c923a638f4abf16a59ca0d8b999f02a7f945055fd9b9099242e8e502dcd

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