Skip to main content

Python wrapper for the USPS API

Project description

Python 3.5, 3.6, 3.7, 3.8 build Code Coverage MIT License


This is a simple async Python wrapper for the USPS API. It was forked from the usps-api project to make an async version. Instead of having to deal with XML, use this library and receive well formatted dictionaries back for tracking shipments, creating shipments, and validating addresses.

Installation

NOTE: aiousps is not yet published on pypi, so you’ll have to install from source.

To install usps-api, use pip:

pip install aiousps

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. For the create_shipment endpoint, you will also need to request further permissions by emailing uspstechnicalsupport@mailps.custhelp.com about Label API access.

The USPS developer guide is available at https://www.usps.com/business/web-tools-apis/general-api-developer-guide.htm

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.

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

aiousps-0.1.2.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

aiousps-0.1.2-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file aiousps-0.1.2.tar.gz.

File metadata

  • Download URL: aiousps-0.1.2.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.3

File hashes

Hashes for aiousps-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fab4464baac818a067e7a1f1597a7b663e026359cea37fc1e462f66be632edaa
MD5 961147ffbcbca6b8bc535f0701140ef3
BLAKE2b-256 52b3839c322828e14ec6001a5e167c091516c514b808f5596f46401508ed185a

See more details on using hashes here.

File details

Details for the file aiousps-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: aiousps-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.3

File hashes

Hashes for aiousps-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f18aeb7ed23e161a2482fb6985cf4e4a96235f7bf3cc671585362ba401189567
MD5 3241c9ab599385e1c5b365bdb6ad3c35
BLAKE2b-256 4b29153e8c1869e8aef2381a584e35cde933c726f79c36bbe42f954f8e00722c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page