6.9 Installing the Package Dependencies
To make it easier to track packages being handled by
FedEx or UPS, we are going to use a Python package called
packagetrack
. This wrapper helps parse
the XML-formatted tracking data provided by the courier’s web
services, making it much easier to handle the data. While it would
have been possible to use a Python screen-scraping library like
Beautiful Soup, such solutions can be brittle. Not to mention,
couriers the size of FedEx and UPS offer comprehensive APIs to
their web services partially to discourage screen scrapers from
data harvesting their sites. As such, before installing the
packagetrack
library, you will need to
use an existing UPS and FedEx customer account to sign up for each
company’s service APIs. If you do not already have a customer
account number and login, you will need to visit each company’s
website and create a new account. The account creation process
requires a valid credit card number (used to bill for parcel
shipping charges).
With a valid username, password, and account number in hand, visit each company’s respective developer portals to sign up for a production web service API key (for FedEx) or license number (for UPS). FedEx will also generate additional security credentials (key password and meter number) when you request the production key. You will need these values to call the respective courier’s web service APIs.
Next, we will install the latest packagetrack
package. However, instead of retrieving
it via the simple easy_install
Python package retrieval and installation utility, I suggest using
git
to clone a fork of
packagetrack
maintained by Michael
Stella.[60] In
addition to Michael’s packagetrack
,
download his fork of its dependency, python-fedex
, which fixes a parsing issue with the
FedEx XML payload.[61] The python-fedex
package also relies on one more Python
library dependency, called the suds
library. This is a Simple Object Access Protocol (SOAP) library
implementation for Python that python-fedex
uses to parse the SOAP XML-wrapped
payload received by the FedEx web service. Use the sudo easy_install suds
Python command to
automatically download and install the suds
package.
Next, install both the python-fedex
and packagetrack
packages via the sudo python setup.py install
command in the
terminal window. Ensure that the packages were successfully
installed by launching the Python interpreter and typing
python
in the terminal window.
At the >>>
prompt, type
import packagetrack
and hit return. If
no error messages appeared, you installed the packages
correctly.
All the other packages we will call upon in the delivery detector script are included with the standard Python 2.5 or higher distribution. With the packagetrack dependencies and courier’s web service API key requirements satisfied, we are ready to write the delivery monitoring script.