Skip to main content

USPS API

Python 2.7, 3.4, 3.5, 3.6 Code Coverage 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.

Metadata

Release files for usps-api 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for usps-api 0.3
File Size Uploaded
usps-api-0.3.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for usps-api 0.3
File Interpreter ABI Platform
usps_api-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / usps-api-0.3.tar.gz

Download URL usps-api-0.3.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
70973f6c952fcf2760374ad9718199b780e8fca81fb1677c6971bb7412750c8c
BLAKE2b-256 checksum
How to use checksums
dd881b3dc193b4c69851cfe6bf008509da2c0e27bf24c0fa93bc88558e226255
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / usps_api-0.3-py3-none-any.whl

Download URL usps_api-0.3-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25f280691ca34ff8de6872ab3dddcca2035ea74f48e27d4574593ca90aa36817
BLAKE2b-256 checksum
How to use checksums
d8675b52e60528417ad8d76655cd808df3d368c5f79e313b5dcd2da5c1fb151a
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

0.5

1 release file

0.4

1 release file

This release

0.3 This release

2 release files

0.2

1 release file

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page