aftership-tracking-sdk 2.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. LICENSE +21 -0
  2. README.md +307 -0
  3. aftership_tracking_sdk-2.0.1.dist-info/LICENSE +21 -0
  4. aftership_tracking_sdk-2.0.1.dist-info/METADATA +335 -0
  5. aftership_tracking_sdk-2.0.1.dist-info/RECORD +79 -0
  6. aftership_tracking_sdk-2.0.1.dist-info/WHEEL +4 -0
  7. tracking/__init__.py +14 -0
  8. tracking/api/__init__.py +18 -0
  9. tracking/api/courier.py +79 -0
  10. tracking/api/estimated_delivery_date.py +43 -0
  11. tracking/api/last_checkpoint.py +92 -0
  12. tracking/api/notification.py +237 -0
  13. tracking/api/tracking.py +477 -0
  14. tracking/auth.py +131 -0
  15. tracking/client.py +29 -0
  16. tracking/configuration.py +112 -0
  17. tracking/exceptions.py +121 -0
  18. tracking/models/__init__.py +152 -0
  19. tracking/models/additional_fields_v1.py +23 -0
  20. tracking/models/aftership_estimated_delivery_date_tracking.py +39 -0
  21. tracking/models/carbon_emissions_tracking.py +37 -0
  22. tracking/models/checkpoint.py +55 -0
  23. tracking/models/coordinate_checkpoint.py +37 -0
  24. tracking/models/courier.py +45 -0
  25. tracking/models/courier_response_v1.py +40 -0
  26. tracking/models/custom_estimated_delivery_date_tracking.py +39 -0
  27. tracking/models/custom_fields_tracking_update_tracking_by_slug_tracking_number_request.py +34 -0
  28. tracking/models/data_courier_response_v1.py +39 -0
  29. tracking/models/data_notification_response_v1.py +38 -0
  30. tracking/models/data_tracking_delete_response_v1.py +38 -0
  31. tracking/models/data_tracking_response_get_multiple_v1.py +52 -0
  32. tracking/models/data_tracking_response_v1.py +38 -0
  33. tracking/models/destination_address_estimated_delivery_date_request.py +40 -0
  34. tracking/models/destination_address_estimated_delivery_date_response.py +40 -0
  35. tracking/models/detect_courier_response.py +39 -0
  36. tracking/models/estimated_delivery_date_request.py +56 -0
  37. tracking/models/estimated_delivery_date_response.py +60 -0
  38. tracking/models/estimated_pickup_estimated_delivery_date_request.py +45 -0
  39. tracking/models/estimated_pickup_estimated_delivery_date_response.py +46 -0
  40. tracking/models/events_checkpoint.py +39 -0
  41. tracking/models/first_estimated_delivery_tracking.py +40 -0
  42. tracking/models/get_all_couriers_response.py +39 -0
  43. tracking/models/get_checkpoint_by_slug_tracking_number_response.py +45 -0
  44. tracking/models/get_checkpoint_by_tracking_id_response.py +45 -0
  45. tracking/models/get_trackings_response.py +40 -0
  46. tracking/models/get_user_couriers_response.py +39 -0
  47. tracking/models/latest_estimated_delivery_tracking.py +40 -0
  48. tracking/models/mark_tracking_completed_by_id_request.py +36 -0
  49. tracking/models/mark_tracking_completed_by_slug_tracking_number_request.py +36 -0
  50. tracking/models/meta_v1.py +38 -0
  51. tracking/models/next_couriers_tracking.py +38 -0
  52. tracking/models/next_couriers_tracking_create_tracking_request.py +37 -0
  53. tracking/models/notification.py +37 -0
  54. tracking/models/notification_request_v1.py +37 -0
  55. tracking/models/notification_response_v1.py +40 -0
  56. tracking/models/order_processing_time_estimated_pickup_estimated_delivery_date_request.py +37 -0
  57. tracking/models/order_processing_time_estimated_pickup_estimated_delivery_date_response.py +37 -0
  58. tracking/models/origin_address_estimated_delivery_date_request.py +40 -0
  59. tracking/models/origin_address_estimated_delivery_date_response.py +40 -0
  60. tracking/models/pagination.py +38 -0
  61. tracking/models/partial_delete_tracking.py +45 -0
  62. tracking/models/partial_update_tracking.py +46 -0
  63. tracking/models/predict_batch_request.py +38 -0
  64. tracking/models/predict_batch_response.py +38 -0
  65. tracking/models/reason_events_checkpoint.py +36 -0
  66. tracking/models/slug_group_v1.py +28 -0
  67. tracking/models/tag_v1.py +25 -0
  68. tracking/models/tracking.py +126 -0
  69. tracking/models/tracking_create_tracking_request.py +81 -0
  70. tracking/models/tracking_delete_response_v1.py +40 -0
  71. tracking/models/tracking_detect_courier_request.py +49 -0
  72. tracking/models/tracking_response_get_multiple_v1.py +40 -0
  73. tracking/models/tracking_response_v1.py +40 -0
  74. tracking/models/tracking_update_tracking_by_id_request.py +71 -0
  75. tracking/models/tracking_update_tracking_by_slug_tracking_number_request.py +64 -0
  76. tracking/models/weight_estimated_delivery_date_request.py +37 -0
  77. tracking/models/weight_estimated_delivery_date_response.py +37 -0
  78. tracking/request.py +140 -0
  79. tracking/response.py +94 -0
LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 AfterShip
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md ADDED
@@ -0,0 +1,307 @@
1
+ # AfterShip Tracking API library for Python
2
+
3
+ This library allows you to quickly and easily use the AfterShip Tracking API via Python.
4
+
5
+ For updates to this library, see our [GitHub release page](https://github.com/AfterShip/tracking-sdk-python/releases).
6
+
7
+ If you need support using AfterShip products, please contact support@aftership.com.
8
+
9
+ ## Table of Contents
10
+
11
+ - [AfterShip Tracking API library for Python](#aftership-tracking-api-library-for-python)
12
+ - [Table of Contents](#table-of-contents)
13
+ - [Before you begin](#before-you-begin)
14
+ - [Quick Start](#quick-start)
15
+ - [Installation](#installation)
16
+ - [Usage](#usage)
17
+ - [Constructor](#constructor)
18
+ - [Example](#example)
19
+ - [Rate Limiter](#rate-limiter)
20
+ - [Error Handling](#error-handling)
21
+ - [Error List](#error-list)
22
+ - [Endpoints](#endpoints)
23
+ - [/trackings](#trackings)
24
+ - [/couriers](#couriers)
25
+ - [/last\_checkpoint](#last_checkpoint)
26
+ - [/notifications](#notifications)
27
+ - [/estimated-delivery-date](#estimated-delivery-date)
28
+ - [Help](#help)
29
+ - [License](#license)
30
+
31
+
32
+ ## Before you begin
33
+
34
+ Before you begin to integrate:
35
+
36
+ - [Create an AfterShip account](https://admin.aftership.com/).
37
+ - [Create an API key](https://organization.automizely.com/api-keys).
38
+ - [Install Python](https://www.python.org/downloads/) version 3.8 or later.
39
+
40
+ ## Quick Start
41
+
42
+ ### Installation
43
+ ```bash
44
+ pip install aftership-tracking-sdk
45
+ ```
46
+
47
+ ### Usage
48
+ ```python
49
+ import tracking
50
+ from tracking import exceptions
51
+
52
+ try:
53
+ sdk = tracking.Client(
54
+ tracking.Configuration(
55
+ api_key="YOUR_API_KEY",
56
+ authentication_type=tracking.ApiKey,
57
+ )
58
+ )
59
+ result = sdk.tracking.get_tracking_by_id("qshqj7p2ugqhclxlg4ef3004")
60
+ print(result)
61
+ except exceptions.InvalidOptionError:
62
+ pass
63
+ except exceptions.InvalidApiKeyError:
64
+ pass
65
+ except exceptions.RateLimitExceedError:
66
+ pass
67
+ ```
68
+
69
+
70
+ ## Constructor
71
+
72
+ Create AfterShip instance with options
73
+
74
+ | Name | Type | Required | Description |
75
+ |------------|--------|----------|-----------------------------------------------------------------------------------------------------------------------------------|
76
+ | api_key | string | ✔ | Your AfterShip API key |
77
+ | auth_type | enum | | Default value: `AuthType.API_KEY` <br > AES authentication: `AuthType.AES` <br > RSA authentication: `AuthType.RSA` |
78
+ | api_secret | string | | Required if the authentication type is `AuthType.AES` or `AuthType.RSA` |
79
+ | domain | string | | AfterShip API domain. Default value: https://api.aftership.com |
80
+ | user_agent | string | | User-defined user-agent string, please follow [RFC9110](https://www.rfc-editor.org/rfc/rfc9110#field.user-agent) format standard. |
81
+ | proxy | string | | HTTP proxy URL to use for requests. <br > Default value: `null` <br > Example: `http://192.168.0.100:8888` |
82
+ | max_retry | number | | Number of retries for each request. Default value: 2. Min is 0, Max is 10. |
83
+ | timeout | number | | Timeout for each request in milliseconds. |
84
+
85
+ ### Example
86
+
87
+ ```python
88
+ import tracking
89
+
90
+ sdk = tracking.Client(
91
+ tracking.Configuration(
92
+ api_key="YOUR_API_KEY",
93
+ api_secret="YOUR_API_SECRET",
94
+ authentication_type=tracking.Aes,
95
+ )
96
+ )
97
+ ```
98
+
99
+ ## Rate Limiter
100
+
101
+ See the [Rate Limit](https://www.aftership.com/docs/aftership/quickstart/rate-limit) to understand the AfterShip rate limit policy.
102
+
103
+ ## Error Handling
104
+
105
+ The SDK will return an error object when there is any error during the request, with the following specification:
106
+
107
+ | Name | Type | Description |
108
+ |---------------|--------|--------------------------------|
109
+ | message | string | Detail message of the error |
110
+ | code | enum | Error code enum for API Error. |
111
+ | meta_code | number | API response meta code. |
112
+ | status_code | number | HTTP status code. |
113
+ | response_body | string | API response body. |
114
+
115
+
116
+ ### Error List
117
+
118
+ | code | meta_code | status_code | message |
119
+ |-----------------------------------|------------------|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
120
+ | INVALID_REQUEST | 400 | 400 | The request was invalid or cannot be otherwise served. |
121
+ | INVALID_JSON | 4001 | 400 | Invalid JSON data. |
122
+ | TRACKING_ALREADY_EXIST | 4003 | 400 | Tracking already exists. |
123
+ | TRACKING_DOES_NOT_EXIST | 4004 | 404 | Tracking does not exist. |
124
+ | TRACKING_NUMBER_INVALID | 4005 | 400 | The value of tracking_number is invalid. |
125
+ | TRACKING_REQUIRED | 4006 | 400 | tracking object is required. |
126
+ | TRACKING_NUMBER_REQUIRED | 4007 | 400 | tracking_number is required. |
127
+ | VALUE_INVALID | 4008 | 400 | The value of [field_name] is invalid. |
128
+ | VALUE_REQUIRED | 4009 | 400 | [field_name] is required. |
129
+ | SLUG_INVALID | 4010 | 400 | The value of slug is invalid. |
130
+ | 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] |
131
+ | BAD_COURIER | 4012 | 400 | The error message will be one of the following:<br/>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/couriers<br/>2. Unable to import shipment as we don’t recognize the carrier from this tracking number.<br/>3. Unable to import shipment as the tracking number has an invalid format.<br/>4. Unable to import shipment as this carrier is no longer supported.<br/>5. Unable to import shipment as the tracking number does not belong to a carrier in that group. |
132
+ | INACTIVE_RETRACK_NOT_ALLOWED | 4013 | 400 | Retrack is not allowed. You can only retrack an inactive tracking. |
133
+ | NOTIFICATION_REUQIRED | 4014 | 400 | notification object is required. |
134
+ | ID_INVALID | 4015 | 400 | The value of id is invalid. |
135
+ | RETRACK_ONCE_ALLOWED | 4016 | 400 | Retrack is not allowed. You can only retrack each shipment once. |
136
+ | TRACKING_NUMBER_FORMAT_INVALID | 4017 | 400 | The format of tracking_number is invalid. |
137
+ | API_KEY_INVALID | 401 | 401 | The API key is invalid. |
138
+ | REQUEST_NOT_ALLOWED | 403 | 403 | The request is understood, but it has been refused or access is not allowed. |
139
+ | NOT_FOUND | 404 | 404 | The URI requested is invalid or the resource requested does not exist. |
140
+ | TOO_MANY_REQUEST | 429 | 429 | You have exceeded the API call rate limit. The default limit is 10 requests per second. |
141
+ | INTERNAL_ERROR | 500 502 503 504 | 500 502 503 504 | Something went wrong on AfterShip's end. |
142
+
143
+ ## Endpoints
144
+
145
+ The AfterShip instance has the following properties which are exactly the same as the API endpoints:
146
+
147
+ - courier - Get a list of our supported couriers.
148
+ - tracking - Create trackings, update trackings, and get tracking results.
149
+ - last_checkpoint - Get tracking information of the last checkpoint of a tracking.
150
+ - notification - Get, add or remove contacts (sms or email) to be notified when the status of a tracking has changed.
151
+ - estimated-delivery-date - Get estimated delivery date for your order.
152
+
153
+
154
+ ### /trackings
155
+
156
+ **POST** /trackings
157
+
158
+ ```python
159
+ import tracking
160
+ from tracking import exceptions
161
+
162
+ try:
163
+ sdk = tracking.Client(
164
+ tracking.Configuration(
165
+ api_key="asak_da8a673f24ff4475a44defe7bd3d2de7",
166
+ api_secret="assk_33532102503846b28e879455d0e0122e",
167
+ authentication_type=tracking.Aes,
168
+ )
169
+ )
170
+ data = tracking.TrackingCreateTrackingRequest()
171
+ data.tracking_number = "9505513461174170617209"
172
+ data.slug = "usps"
173
+ result = sdk.tracking.create_tracking(data)
174
+ print(result)
175
+ except exceptions.InvalidOptionError:
176
+ pass
177
+ ```
178
+
179
+ **DELETE** /trackings/:id
180
+
181
+ ```python
182
+ sdk.tracking.delete_tracking_by_id("pugd4lue1oxtjlxlphas600f")
183
+ ```
184
+
185
+ **GET** /trackings
186
+
187
+ ```python
188
+ result = sdk.tracking.get_trackings(keyword="1234")
189
+ print(result)
190
+ ```
191
+
192
+ **GET** /trackings/:id
193
+
194
+ ```python
195
+ result = sdk.tracking.get_tracking_by_id("rft4xu2rs1um1lwhm8j1p02r")
196
+ print(result)
197
+ ```
198
+
199
+ **PUT** /trackings/:id
200
+
201
+ ```python
202
+ data = tracking.TrackingUpdateTrackingByIdRequest()
203
+ data.note = "test"
204
+ result = sdk.tracking.update_tracking_by_id("hqhyzb21sm0colweuats7001", data)
205
+ print(result)
206
+ ```
207
+
208
+ **POST** /trackings/:id/retrack
209
+
210
+ ```python
211
+ result = sdk.tracking.retrack_tracking_by_id("hqhyzb21sm0colweuats7001")
212
+ print(result)
213
+ ```
214
+
215
+ **POST** /trackings/:id/mark-as-completed
216
+
217
+ ```python
218
+ data = tracking.MarkTrackingCompletedByIdRequest()
219
+ data.reason = "DELIVERED"
220
+ result = sdk.tracking.mark_tracking_completed_by_id("hqhyzb21sm0colweuats7001", data)
221
+ print(result)
222
+ ```
223
+
224
+ ### /couriers
225
+ **GET** /couriers
226
+
227
+ ```python
228
+ result = sdk.courier.get_user_couriers()
229
+ print(result)
230
+ ```
231
+
232
+ **GET** /couriers/all
233
+
234
+ ```python
235
+ result = sdk.courier.get_all_couriers()
236
+ print(result)
237
+ ```
238
+
239
+ **POST** /couriers/detect
240
+
241
+ ```python
242
+ data = tracking.TrackingDetectCourierRequest()
243
+ data.tracking_number = "9434609105464265845274"
244
+ result = sdk.courier.detect_courier(data)
245
+ print(result)
246
+ ```
247
+
248
+ ### /last_checkpoint
249
+
250
+ **GET** /last_checkpoint/:id
251
+
252
+ ```python
253
+ result = sdk.last_checkpoint.get_checkpoint_by_tracking_id("qshqj7p2ugqhclxlg4ef3004")
254
+ print(result)
255
+ ```
256
+
257
+ ### /notifications
258
+
259
+ **GET** /notifications/:id
260
+
261
+ ```python
262
+ result = sdk.notification.get_notification_by_tracking_id("qshqj7p2ugqhclxlg4ef3004")
263
+ print(result)
264
+ ```
265
+
266
+ **POST** /notifications/:id/add
267
+
268
+ ```python
269
+ data = tracking.NotificationRequestV1()
270
+ data.emails = ["test@gmail.com"]
271
+ result = sdk.notification.add_notification_by_tracking_id("qshqj7p2ugqhclxlg4ef3004", data)
272
+ print(result)
273
+ ```
274
+
275
+ **POST** /notifications/:id/remove
276
+
277
+ ```python
278
+ data = tracking.NotificationRequestV1()
279
+ data.emails = ["123@gmail.com"]
280
+ result = sdk.notification.delete_notification_by_tracking_id("kponlnb1w64fmlxlakyln00l", data)
281
+ print(result)
282
+ ```
283
+
284
+ ### /estimated-delivery-date
285
+
286
+ **POST** /estimated-delivery-date/predict-batch
287
+
288
+ ```python
289
+ req = tracking.PredictBatchRequest()
290
+ date = tracking.EstimatedDeliveryDateRequest()
291
+ date.slug = 'usps'
292
+ req.estimated_delivery_dates = [date]
293
+ result = sdk.estimated_delivery_date.predict_batch(req)
294
+ print(result)
295
+ ```
296
+
297
+ ## Help
298
+
299
+ If you get stuck, we're here to help:
300
+
301
+ - [Issue Tracker](https://github.com/AfterShip/tracking-sdk-python/issues) for questions, feature requests, bug reports and general discussion related to this package. Try searching before you create a new issue.
302
+ - Contact AfterShip official support via support@aftership.com
303
+
304
+ ## License
305
+ Copyright (c) 2024 AfterShip
306
+
307
+ Licensed under the MIT license.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 AfterShip
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.