AfterShip Tracking API library for Python
This library allows you to quickly and easily use the AfterShip Tracking API via Python.
For updates to this library, see our GitHub release page.
If you need support using AfterShip products, please contact support@aftership.com.
Table of Contents
Before you begin
Before you begin to integrate:
- Create an AfterShip account.
- Create an API key.
- Install Python version 3.8 or later.
API and SDK Version
- SDK Version: 9.0.0
- API Version: 2026-01
Quick Start
Installation
pip install aftership-tracking-sdk
Constructor
Create AfterShip instance with options
| Name | Type | Required | Description |
|---|---|---|---|
| api_key | string | ✔ | Your AfterShip API key |
| auth_type | enum | Default value: ApiKey AES authentication: Aes RSA authentication: Rsa |
|
| api_secret | string | Required if the authentication type is auth.Aes or auth.Rsa |
|
| domain | string | AfterShip API domain. Default value: https://api.aftership.com | |
| user_agent | string | User-defined user-agent string, please follow RFC9110 format standard. | |
| proxy | string | HTTP proxy URL to use for requests. Default value: null Example: http://192.168.0.100:8888 |
|
| max_retry | number | Number of retries for each request. Default value: 2. Min is 0, Max is 10. | |
| timeout | number | Timeout for each request in milliseconds. |
Example
import tracking
from tracking import exceptions, auth
try:
sdk = tracking.Client(
tracking.Configuration(
api_key="YOUR_API_KEY",
authentication_type=auth.ApiKey,
)
)
result = sdk.tracking.get_tracking_by_id(
'valid_value',
)
print(result)
except exceptions.InvalidOptionError:
pass
except exceptions.InvalidApiKeyError:
pass
except exceptions.RateLimitExceedError:
pass
Rate Limiter
See the Rate Limit to understand the AfterShip rate limit policy.
Error Handling
The SDK will return an error object when there is any error during the request, with the following specification:
| Name | Type | Description |
|---|---|---|
| message | string | Detail message of the error |
| code | enum | Error code enum for API Error. |
| meta_code | number | API response meta code. |
| status_code | number | HTTP status code. |
| response_body | string | API response body. |
| response_header | object | API response header. |
Error List
| code | meta_code | status_code | message |
|---|---|---|---|
| INVALID_REQUEST | 400 | 400 | The request was invalid or cannot be otherwise served. |
| INVALID_JSON | 4001 | 400 | Invalid JSON data. |
| TRACKING_ALREADY_EXIST | 4003 | 400 | Tracking already exists. |
| TRACKING_DOES_NOT_EXIST | 4004 | 404 | Tracking does not exist. |
| TRACKING_NUMBER_INVALID | 4005 | 400 | The value of tracking_number is invalid. |
| TRACKING_REQUIRED | 4006 | 400 | tracking object is required. |
| TRACKING_NUMBER_REQUIRED | 4007 | 400 | tracking_number is required. |
| VALUE_INVALID | 4008 | 400 | The value of [field_name] is invalid. |
| VALUE_REQUIRED | 4009 | 400 | [field_name] is required. |
| SLUG_INVALID | 4010 | 400 | The value of slug is invalid. |
| MISSING_OR_INVALID_REQUIRED_FIELD | 4011 | 400 | Missing or invalid value of the required fields for this courier. Besides tracking_number, also required: [field_name] |
| BAD_COURIER | 4012 | 400 | The error message will be one of the following:1. Unable to import shipment as the carrier is not on your approved list for carrier auto-detection. Add the carrier here: https://admin.aftership.com/settings/couriers2. Unable to import shipment as we don't recognize the carrier from this tracking number.3. Unable to import shipment as the tracking number has an invalid format.4. Unable to import shipment as this carrier is no longer supported.5. Unable to import shipment as the tracking number does not belong to a carrier in that group. |
| INACTIVE_RETRACK_NOT_ALLOWED | 4013 | 400 | Retrack is not allowed. You can only retrack an inactive tracking. |
| NOTIFICATION_REQUIRED | 4014 | 400 | notification object is required. |
| ID_INVALID | 4015 | 400 | The value of id is invalid. |
| RETRACK_ONCE_ALLOWED | 4016 | 400 | Retrack is not allowed. You can only retrack each shipment once. |
| TRACKING_NUMBER_FORMAT_INVALID | 4017 | 400 | The format of tracking_number is invalid. |
| API_KEY_INVALID | 401 | 401 | The API Key is invalid. |
| REQUEST_NOT_ALLOWED | 403 | 403 | The request is understood, but it has been refused or access is not allowed. |
| NOT_FOUND | 404 | 404 | The URI requested is invalid or the resource requested does not exist. |
| TOO_MANY_REQUEST | 429 | 429 | You have exceeded the API call rate limit. The default limit is 10 requests per second. |
| INTERNAL_ERROR | 500 | 500 | Something went wrong on AfterShip's end. |
| INTERNAL_ERROR | 502 | 502 | Something went wrong on AfterShip's end. |
| INTERNAL_ERROR | 503 | 503 | Something went wrong on AfterShip's end. |
| INTERNAL_ERROR | 504 | 504 | Something went wrong on AfterShip's end. |
Endpoints
The AfterShip instance has the following properties which are exactly the same as the API endpoints:
- tracking
- Get trackings
- Create a tracking
- Get a tracking by ID
- Update a tracking by ID
- Delete a tracking by ID
- Retrack an expired tracking by ID
- Mark tracking as completed by ID
- courier
- Get couriers
- Detect courier
- courier_connection
- Get courier connections
- Create courier connections
- Get courier connection by id
- Update courier connection by id
- Delete courier connection by id
- estimated_delivery_date
- Prediction for the Estimated Delivery Date
- Batch prediction for the Estimated Delivery Date
/trackings
GET /trackings
result = sdk.tracking.get_trackings(
)
print(result)
POST /trackings
req = tracking.CreateTrackingRequest()
req.tracking_number = 'valid_value'
result = sdk.tracking.create_tracking(
req,
)
print(result)
GET /trackings/{id}
result = sdk.tracking.get_tracking_by_id(
'valid_value',
)
print(result)
PUT /trackings/{id}
req = tracking.UpdateTrackingByIdRequest()
result = sdk.tracking.update_tracking_by_id(
'valid_value',
req,
)
print(result)
DELETE /trackings/{id}
result = sdk.tracking.delete_tracking_by_id(
'valid_value',
)
print(result)
POST /trackings/{id}/retrack
result = sdk.tracking.retrack_tracking_by_id(
'valid_value',
)
print(result)
POST /trackings/{id}/mark-as-completed
req = tracking.MarkTrackingCompletedByIdRequest()
result = sdk.tracking.mark_tracking_completed_by_id(
'valid_value',
req,
)
print(result)
/couriers
GET /couriers
result = sdk.courier.get_couriers(
)
print(result)
POST /couriers/detect
req = tracking.DetectCourierRequest()
req.tracking_number = 'valid_value'
result = sdk.courier.detect_courier(
req,
)
print(result)
/courier-connections
GET /courier-connections
result = sdk.courier_connection.get_courier_connections(
)
print(result)
POST /courier-connections
req = tracking.PostCourierConnectionsRequest()
req.courier_slug = 'valid_value'
req.credentials = {}
result = sdk.courier_connection.post_courier_connections(
req,
)
print(result)
GET /courier-connections/{id}
result = sdk.courier_connection.get_courier_connections_by_id(
'valid_value',
)
print(result)
PATCH /courier-connections/{id}
req = tracking.PutCourierConnectionsByIdRequest()
req.credentials = {}
result = sdk.courier_connection.put_courier_connections_by_id(
'valid_value',
req,
)
print(result)
DELETE /courier-connections/{id}
result = sdk.courier_connection.delete_courier_connections_by_id(
'valid_value',
)
print(result)
/estimated-delivery-date
POST /estimated-delivery-date/predict
req = tracking.EstimatedDeliveryDateRequest()
req.slug = 'valid_value'
req.origin_address = tracking.EstimatedDeliveryDateRequestOriginAddress()
req.destination_address = tracking.EstimatedDeliveryDateRequestDestinationAddress()
result = sdk.estimated_delivery_date.predict(
req,
)
print(result)
POST /estimated-delivery-date/predict-batch
req = tracking.PredictBatchRequest()
result = sdk.estimated_delivery_date.predict_batch(
req,
)
print(result)
Help
If you get stuck, we're here to help:
- Issue Tracker for questions, feature requests, bug reports and general discussion related to this package. Try searching before you create a new issue.
- Contact AfterShip official support via support@aftership.com
License
Copyright (c) 2025 AfterShip
Licensed under the MIT license.
Metadata
Release files for aftership-tracking-sdk 9.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aftership_tracking_sdk-9.0.1.tar.gz | 29.5 kB | Without provenance | Details for aftership_tracking_sdk-9.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aftership_tracking_sdk-9.0.1-py3-none-any.whl | Python 3 | none | any | Details for aftership_tracking_sdk-9.0.1-py3-none-any.whl |
Total release size: 121.4 kB
Release files / aftership_tracking_sdk-9.0.1.tar.gz
| Download URL | aftership_tracking_sdk-9.0.1.tar.gz |
|---|---|
| Size | 29.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a6b7b837fd00b49d6061b3eed91449883bdd634ad66f2da49e9f7ccd1bf20e2
|
|
BLAKE2b-256 checksum How to use checksums |
4ac886eaa8643573ff6034510b1642baa1e5c9b74475a37308f9faeca4262e24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.18
|
Release files / aftership_tracking_sdk-9.0.1-py3-none-any.whl
| Download URL | aftership_tracking_sdk-9.0.1-py3-none-any.whl |
|---|---|
| Size | 91.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
22acfe7340014864a77ea8a7aeb5c5307ec7a6a4fca00dcf1b07f6bc5692f550
|
|
BLAKE2b-256 checksum How to use checksums |
226cf2ae893ca93915836ffccb77f8ed614901783169aced69c760b59eab0dd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.18
|
Security for aftership-tracking-sdk 9.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.