Python wrapper for the USPS API
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aiousps-0.1.tar.gz
.
File metadata
- Download URL: aiousps-0.1.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1.post20200604 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6232dd3baaf827ee0b92caa07eead1d0cf9c2188520a88352cac9d9e53ca3fc |
|
MD5 | bc052d43ab0293070ca7a2325074b12c |
|
BLAKE2b-256 | 23d5798c5c6858c612c05d0167084d66b10cf1b85dd33c336ee2870734f0f69f |
File details
Details for the file aiousps-0.1-py3-none-any.whl
.
File metadata
- Download URL: aiousps-0.1-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1.post20200604 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67a541160e9f13e1909b39069c831cff3d1e89ecd86bf3b165e77da38ebd45de |
|
MD5 | ca85966a327995c7d5f4bdd635504ba0 |
|
BLAKE2b-256 | 96e738d88ba51c825af0a237676b411067cfc8e2a9fd8bd352ac46142ea0287f |