Python package for AfterShip API.
This package helps developers to integrate with AfterShip easily.
AfterShip provides an automated way for online merchants to track packages and send their customers delivery status notifications. Customers no longer need to deal with tracking numbers and track packages on their own. With AfterShip, online merchants extend their customer service after the point of purchase by keeping their customers actively informed, while saving time and money by reducing customers’ questions about the status of their purchase delivery.
Install using pip or easy_install:
$ pip install aftership-python
or
$ easy_install aftership-python
If you want to install it from source, grab the git repository from GitHub and run setup.py:
$ git clone https://github.com/russelldavies/aftership-python.git
$ cd aftership-python
$ python setup.py install
You'll need to have a AfterShip account http://www.aftership.com.
You can retrieve your api key at https://www.aftership.com/connect/api
Before using API, please include the package in your script
import aftership
You should set you API key before making any request to AfterShip.
aftership.config.api_key = "YOUR_API_KEY"
Replace "YOUR_API_KEY" to your AfterShip api key.
Optionally, you can specify the API version:
aftership.config.api_version = '3'
You can retrive the list of supported couriers:
aftership.Courier.all()
Result (truncated for ease of reading):
{
"total": 3,
"couriers": [
{
"slug": "dhl",
"name": "DHL",
"phone": "+1 800 225 5345",
"other_name": "DHL Express",
"web_url": "http://www.dhl.com/"
},
{
"slug": "china-post",
"name": "China Post",
"phone": "+86 20 11185",
"other_name": "中国邮政",
"web_url": "http://www.chinapost.com.cn/"
},
{
"slug": "tnt",
"name": "TNT",
"phone": "+1 800 558 5555",
"other_name": "TNT Express",
"web_url": "http://www.tnt.com/"
}
]
}
Get a list of matched couriers for a tracking number based on the tracking number format:
aftership.Courier.detect('1Z1896X70305267337')
Result:
{
"total": 2,
"tracking_number": "1234567890",
"couriers": [
{
"slug": "dhl",
"name": "DHL",
"phone": "+1 800 225 5345",
"other_name": "DHL Express",
"web_url": "http://www.dhl.com/"
},
{
"slug": "yrc",
"name": "YRC",
"phone": "+1 800-468-5739",
"other_name": "YRC Freight",
"web_url": "http://www.yrc.com/"
}
]
}
For each of these examples, the first parameter is the tracking number and the
second is the carrier slug. They can also be specified as keyword arguments:
tracking_number
and slug
, respectively.
Some calls take extra optional parameters. The parameters have the same name as documented in the API.
You can add tracking number to AfterShip by calling
aftership.Tracking.create("218501627271", "toll-global-express")
Optionally, you can pass extra paramaters, for example, customer name:
aftership.Tracking.create("218501627271", "toll-global-express", customer_name="John Doe")
For extra parameters list, please consult the API.
To get the tracking results of multiple trackings:
aftership.Tracking.get()
To get the tracking results of a single tracking:
aftership.Tracking.get("218501627271", "toll-global-express")
To update a tracking:
aftership.Tracking.update("218501627271", "toll-global-express",
title="Computer parts",
customer_name="John Doe")
The keyword arguments are optional parameters and none or all may be specified.
To reactive an expired tracking:
aftership.Tracking.reactivate("218501627271", "toll-global-express")
Get tracking information of the last checkpoint of a tracking:
aftership.Tracking.last_checkpoint('218501627271', 'toll-global-express')
Optional parameters may be specified:
aftership.Tracking.last_checkpoint('218501627271', 'toll-global-express',
fields='title,order_id,tag',
lang='en')
You can view the API documentation at: https://www.aftership.com/docs/api