asindotdev 0.1.0__tar.gz → 0.2.0__tar.gz
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.
- {asindotdev-0.1.0 → asindotdev-0.2.0}/PKG-INFO +19 -10
- {asindotdev-0.1.0 → asindotdev-0.2.0}/README.md +17 -8
- {asindotdev-0.1.0 → asindotdev-0.2.0}/pyproject.toml +2 -2
- {asindotdev-0.1.0 → asindotdev-0.2.0}/src/asin/_operations.py +53 -18
- {asindotdev-0.1.0 → asindotdev-0.2.0}/src/asin/_response.py +7 -2
- {asindotdev-0.1.0 → asindotdev-0.2.0}/src/asin/_serialization.py +15 -2
- asindotdev-0.2.0/src/asin/_version.py +1 -0
- {asindotdev-0.1.0 → asindotdev-0.2.0}/src/asin/client.py +2 -2
- {asindotdev-0.1.0 → asindotdev-0.2.0}/src/asin/errors.py +3 -0
- {asindotdev-0.1.0 → asindotdev-0.2.0}/tests/test_client.py +49 -2
- asindotdev-0.1.0/src/asin/_version.py +0 -1
- {asindotdev-0.1.0 → asindotdev-0.2.0}/.gitignore +0 -0
- {asindotdev-0.1.0 → asindotdev-0.2.0}/LICENSE +0 -0
- {asindotdev-0.1.0 → asindotdev-0.2.0}/examples/README.md +0 -0
- {asindotdev-0.1.0 → asindotdev-0.2.0}/examples/any_endpoint.py +0 -0
- {asindotdev-0.1.0 → asindotdev-0.2.0}/examples/async_client.py +0 -0
- {asindotdev-0.1.0 → asindotdev-0.2.0}/examples/json_response.py +0 -0
- {asindotdev-0.1.0 → asindotdev-0.2.0}/src/asin/__init__.py +0 -0
- {asindotdev-0.1.0 → asindotdev-0.2.0}/src/asin/_endpoints.py +0 -0
- {asindotdev-0.1.0 → asindotdev-0.2.0}/src/asin/models.py +0 -0
- {asindotdev-0.1.0 → asindotdev-0.2.0}/src/asin/py.typed +0 -0
- {asindotdev-0.1.0 → asindotdev-0.2.0}/tests/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: asindotdev
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Official Python SDK for the Asin Amazon price tracking API.
|
|
5
5
|
Project-URL: Homepage, https://www.asin.dev
|
|
6
6
|
Project-URL: Documentation, https://www.asin.dev/docs
|
|
@@ -9,7 +9,7 @@ Project-URL: Issues, https://github.com/asindotdev/asin-python/issues
|
|
|
9
9
|
Author-email: Asin <contact@asin.dev>
|
|
10
10
|
License-Expression: MIT
|
|
11
11
|
License-File: LICENSE
|
|
12
|
-
Keywords: amazon
|
|
12
|
+
Keywords: amazon,api,asin,price-history,price-tracking,sdk
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
14
14
|
Classifier: Operating System :: OS Independent
|
|
15
15
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
@@ -84,7 +84,11 @@ asyncio.run(main())
|
|
|
84
84
|
|
|
85
85
|
## HTTP methods
|
|
86
86
|
|
|
87
|
-
Each method uses the HTTP verb of its endpoint. `GET` and `DELETE` send parameters in the query string; `POST` and `PATCH` send them as a JSON body, except `wait` on `/products/{id}/check`, which stays in the query string.
|
|
87
|
+
Each method uses the HTTP verb of its endpoint. `GET` and `DELETE` send parameters in the query string; `POST` and `PATCH` send them as a JSON body, except `wait` on `/products/{id}/check`, which stays in the query string. `None` values are never sent, so `update_product(target_price=None)` leaves the target price as it is: `clear_target_price(id=...)` removes it (it sends `{"target_price": null}`).
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
client.clear_target_price(id="p1")
|
|
91
|
+
```
|
|
88
92
|
|
|
89
93
|
`None` values are omitted, `False` and `0` are sent, and sequences repeat the parameter name.
|
|
90
94
|
|
|
@@ -102,7 +106,7 @@ from asin import AsinAPIError
|
|
|
102
106
|
try:
|
|
103
107
|
client.search_amazon(query="wireless earbuds")
|
|
104
108
|
except AsinAPIError as error:
|
|
105
|
-
print(error.status, error, error.response_body)
|
|
109
|
+
print(error.status, error.error_code, error, error.response_body)
|
|
106
110
|
```
|
|
107
111
|
|
|
108
112
|
| Error | When |
|
|
@@ -110,14 +114,14 @@ except AsinAPIError as error:
|
|
|
110
114
|
| `AsinConfigurationError` | Missing API key, invalid options, unsupported method, closed client. |
|
|
111
115
|
| `AsinSerializationError` | A required parameter is missing or a value can't be sent. |
|
|
112
116
|
| `AsinTransportError` | Network failure or timeout. |
|
|
113
|
-
| `AsinAPIError` | Non-2xx status (`status`, `error_message`, `response_body`, `raw_response`). |
|
|
117
|
+
| `AsinAPIError` | Non-2xx status (`status`, `error_message`, `error_code`, `response_body`, `raw_response`). `error_code` is the API's `error.code`, such as `insufficient_credits` or `product_limit` (`None` when the body has none). |
|
|
114
118
|
| `AsinResponseDecodingError` | A success response could not be decoded. |
|
|
115
119
|
|
|
116
120
|
All of them extend `AsinError`.
|
|
117
121
|
|
|
118
122
|
## Retries
|
|
119
123
|
|
|
120
|
-
Requests are retried up to 3 times after a network error, a `408`, `
|
|
124
|
+
Requests are retried up to 3 times after a network error, a `408`, `500`, `502`, `503` or `504`. Other statuses, such as `400`, `401`, `402`, `404` or `429`, and client-side timeouts are not retried: the API's rate limits last until the hour (or the day) is over, and on the free plan every retry would count as a request. The delay starts at 1 second and grows 1.5× per retry (capped at 30 seconds); a `Retry-After` header wins.
|
|
121
125
|
|
|
122
126
|
```python
|
|
123
127
|
client = AsinClient(max_retries=5, retry_delay=0.5)
|
|
@@ -145,7 +149,7 @@ for result in results:
|
|
|
145
149
|
| --- | --- | --- |
|
|
146
150
|
| `DEFAULT_CONCURRENCY` | `10` | Tasks run at the same time by batch |
|
|
147
151
|
| `DEFAULT_TIMEOUT` | `120.0` | Request timeout (seconds) |
|
|
148
|
-
| `MAX_RETRIES` | `3` | Retry attempts after a network error, a 408/
|
|
152
|
+
| `MAX_RETRIES` | `3` | Retry attempts after a network error, a 408/5xx |
|
|
149
153
|
| `RETRY_BACKOFF_FACTOR` | `1.5` | Exponential backoff multiplier |
|
|
150
154
|
| `DEFAULT_RETRY_DELAY` | `1.0` | Delay before the first retry (seconds) |
|
|
151
155
|
|
|
@@ -166,21 +170,22 @@ client = AsinClient(http_client=http_client)
|
|
|
166
170
|
|
|
167
171
|
## Endpoints
|
|
168
172
|
|
|
169
|
-
11 methods, generated from the [OpenAPI document](https://www.asin.dev/openapi.json)
|
|
173
|
+
11 methods, generated from the [OpenAPI document](https://www.asin.dev/openapi.json), plus `clear_target_price()`.
|
|
170
174
|
|
|
171
175
|
| Method | HTTP | Description |
|
|
172
176
|
| --- | --- | --- |
|
|
173
177
|
| `check_product()` | POST `/products/{id}/check` | Asks for a check right away (1 credit), at most once per 5 minutes; earlier calls return the product unchanged. A paused product has to be… |
|
|
178
|
+
| `clear_target_price()` | PATCH `/products/{id}` | Removes the target price: sends `{"target_price": null}`. |
|
|
174
179
|
| `delete_product()` | DELETE `/products/{id}` | Removes the product and its price history. |
|
|
175
180
|
| `fetch_offers()` | POST `/offers` | Reads the offers on Amazon for 1 credit, refunded if it doesn't answer. A read made in the last 3 hours, by anyone, is returned instead, fo… |
|
|
176
|
-
| `get_account()` | GET `/account` | Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month
|
|
181
|
+
| `get_account()` | GET `/account` | Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month, the credits each… |
|
|
177
182
|
| `get_asin_history()` | GET `/history` | Every price Asin read for an ASIN on a marketplace over the period, whoever tracks it, oldest first, with the lowest, highest and average o… |
|
|
178
183
|
| `get_offers()` | GET `/offers` | Who sells the product and at what price, as last read, cheapest first, with Amazon's own price and the cheapest new and used offers (used i… |
|
|
179
184
|
| `get_product()` | GET `/products/{id}` | The product's latest state and every price read of the period, oldest first. The history covers every read of this ASIN on this marketplace… |
|
|
180
185
|
| `list_products()` | GET `/products` | Your watchlist, newest first, with each product's latest state and its recent prices (trend). Filter with asin (and marketplace) to know if… |
|
|
181
186
|
| `search_amazon()` | GET `/search` | Amazon search results (up to 60, sponsored included), to find the ASIN of a product. Free, limited to 30 searches per hour. |
|
|
182
187
|
| `track_product()` | POST `/products` | Adds an ASIN, an Amazon link or a short link (amzn.to, a.co…) to your watchlist. The first check runs in the background within seconds (che… |
|
|
183
|
-
| `update_product()` | PATCH `/products/{id}` | Target price, drop alerts, check interval, or pause. Send only what changes. |
|
|
188
|
+
| `update_product()` | PATCH `/products/{id}` | Target price, drop alerts, check interval, or pause. Send only what changes. On the free plan, alerts (price drop, back in stock, target pr… |
|
|
184
189
|
|
|
185
190
|
## All Asin SDKs
|
|
186
191
|
|
|
@@ -196,6 +201,10 @@ client = AsinClient(http_client=http_client)
|
|
|
196
201
|
| CLI | [`@asindev/cli`](https://www.npmjs.com/package/@asindev/cli) | `npm install -g @asindev/cli` |
|
|
197
202
|
| MCP server | [`@asindev/mcp`](https://www.npmjs.com/package/@asindev/mcp) | `npx -y @asindev/mcp` |
|
|
198
203
|
|
|
204
|
+
## Trademarks
|
|
205
|
+
|
|
206
|
+
Amazon® is a trademark of Amazon.com, Inc. or its affiliates. Asin is not affiliated with, endorsed or sponsored by Amazon.
|
|
207
|
+
|
|
199
208
|
## License
|
|
200
209
|
|
|
201
210
|
MIT — see [LICENSE](LICENSE).
|
|
@@ -53,7 +53,11 @@ asyncio.run(main())
|
|
|
53
53
|
|
|
54
54
|
## HTTP methods
|
|
55
55
|
|
|
56
|
-
Each method uses the HTTP verb of its endpoint. `GET` and `DELETE` send parameters in the query string; `POST` and `PATCH` send them as a JSON body, except `wait` on `/products/{id}/check`, which stays in the query string.
|
|
56
|
+
Each method uses the HTTP verb of its endpoint. `GET` and `DELETE` send parameters in the query string; `POST` and `PATCH` send them as a JSON body, except `wait` on `/products/{id}/check`, which stays in the query string. `None` values are never sent, so `update_product(target_price=None)` leaves the target price as it is: `clear_target_price(id=...)` removes it (it sends `{"target_price": null}`).
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
client.clear_target_price(id="p1")
|
|
60
|
+
```
|
|
57
61
|
|
|
58
62
|
`None` values are omitted, `False` and `0` are sent, and sequences repeat the parameter name.
|
|
59
63
|
|
|
@@ -71,7 +75,7 @@ from asin import AsinAPIError
|
|
|
71
75
|
try:
|
|
72
76
|
client.search_amazon(query="wireless earbuds")
|
|
73
77
|
except AsinAPIError as error:
|
|
74
|
-
print(error.status, error, error.response_body)
|
|
78
|
+
print(error.status, error.error_code, error, error.response_body)
|
|
75
79
|
```
|
|
76
80
|
|
|
77
81
|
| Error | When |
|
|
@@ -79,14 +83,14 @@ except AsinAPIError as error:
|
|
|
79
83
|
| `AsinConfigurationError` | Missing API key, invalid options, unsupported method, closed client. |
|
|
80
84
|
| `AsinSerializationError` | A required parameter is missing or a value can't be sent. |
|
|
81
85
|
| `AsinTransportError` | Network failure or timeout. |
|
|
82
|
-
| `AsinAPIError` | Non-2xx status (`status`, `error_message`, `response_body`, `raw_response`). |
|
|
86
|
+
| `AsinAPIError` | Non-2xx status (`status`, `error_message`, `error_code`, `response_body`, `raw_response`). `error_code` is the API's `error.code`, such as `insufficient_credits` or `product_limit` (`None` when the body has none). |
|
|
83
87
|
| `AsinResponseDecodingError` | A success response could not be decoded. |
|
|
84
88
|
|
|
85
89
|
All of them extend `AsinError`.
|
|
86
90
|
|
|
87
91
|
## Retries
|
|
88
92
|
|
|
89
|
-
Requests are retried up to 3 times after a network error, a `408`, `
|
|
93
|
+
Requests are retried up to 3 times after a network error, a `408`, `500`, `502`, `503` or `504`. Other statuses, such as `400`, `401`, `402`, `404` or `429`, and client-side timeouts are not retried: the API's rate limits last until the hour (or the day) is over, and on the free plan every retry would count as a request. The delay starts at 1 second and grows 1.5× per retry (capped at 30 seconds); a `Retry-After` header wins.
|
|
90
94
|
|
|
91
95
|
```python
|
|
92
96
|
client = AsinClient(max_retries=5, retry_delay=0.5)
|
|
@@ -114,7 +118,7 @@ for result in results:
|
|
|
114
118
|
| --- | --- | --- |
|
|
115
119
|
| `DEFAULT_CONCURRENCY` | `10` | Tasks run at the same time by batch |
|
|
116
120
|
| `DEFAULT_TIMEOUT` | `120.0` | Request timeout (seconds) |
|
|
117
|
-
| `MAX_RETRIES` | `3` | Retry attempts after a network error, a 408/
|
|
121
|
+
| `MAX_RETRIES` | `3` | Retry attempts after a network error, a 408/5xx |
|
|
118
122
|
| `RETRY_BACKOFF_FACTOR` | `1.5` | Exponential backoff multiplier |
|
|
119
123
|
| `DEFAULT_RETRY_DELAY` | `1.0` | Delay before the first retry (seconds) |
|
|
120
124
|
|
|
@@ -135,21 +139,22 @@ client = AsinClient(http_client=http_client)
|
|
|
135
139
|
|
|
136
140
|
## Endpoints
|
|
137
141
|
|
|
138
|
-
11 methods, generated from the [OpenAPI document](https://www.asin.dev/openapi.json)
|
|
142
|
+
11 methods, generated from the [OpenAPI document](https://www.asin.dev/openapi.json), plus `clear_target_price()`.
|
|
139
143
|
|
|
140
144
|
| Method | HTTP | Description |
|
|
141
145
|
| --- | --- | --- |
|
|
142
146
|
| `check_product()` | POST `/products/{id}/check` | Asks for a check right away (1 credit), at most once per 5 minutes; earlier calls return the product unchanged. A paused product has to be… |
|
|
147
|
+
| `clear_target_price()` | PATCH `/products/{id}` | Removes the target price: sends `{"target_price": null}`. |
|
|
143
148
|
| `delete_product()` | DELETE `/products/{id}` | Removes the product and its price history. |
|
|
144
149
|
| `fetch_offers()` | POST `/offers` | Reads the offers on Amazon for 1 credit, refunded if it doesn't answer. A read made in the last 3 hours, by anyone, is returned instead, fo… |
|
|
145
|
-
| `get_account()` | GET `/account` | Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month
|
|
150
|
+
| `get_account()` | GET `/account` | Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month, the credits each… |
|
|
146
151
|
| `get_asin_history()` | GET `/history` | Every price Asin read for an ASIN on a marketplace over the period, whoever tracks it, oldest first, with the lowest, highest and average o… |
|
|
147
152
|
| `get_offers()` | GET `/offers` | Who sells the product and at what price, as last read, cheapest first, with Amazon's own price and the cheapest new and used offers (used i… |
|
|
148
153
|
| `get_product()` | GET `/products/{id}` | The product's latest state and every price read of the period, oldest first. The history covers every read of this ASIN on this marketplace… |
|
|
149
154
|
| `list_products()` | GET `/products` | Your watchlist, newest first, with each product's latest state and its recent prices (trend). Filter with asin (and marketplace) to know if… |
|
|
150
155
|
| `search_amazon()` | GET `/search` | Amazon search results (up to 60, sponsored included), to find the ASIN of a product. Free, limited to 30 searches per hour. |
|
|
151
156
|
| `track_product()` | POST `/products` | Adds an ASIN, an Amazon link or a short link (amzn.to, a.co…) to your watchlist. The first check runs in the background within seconds (che… |
|
|
152
|
-
| `update_product()` | PATCH `/products/{id}` | Target price, drop alerts, check interval, or pause. Send only what changes. |
|
|
157
|
+
| `update_product()` | PATCH `/products/{id}` | Target price, drop alerts, check interval, or pause. Send only what changes. On the free plan, alerts (price drop, back in stock, target pr… |
|
|
153
158
|
|
|
154
159
|
## All Asin SDKs
|
|
155
160
|
|
|
@@ -165,6 +170,10 @@ client = AsinClient(http_client=http_client)
|
|
|
165
170
|
| CLI | [`@asindev/cli`](https://www.npmjs.com/package/@asindev/cli) | `npm install -g @asindev/cli` |
|
|
166
171
|
| MCP server | [`@asindev/mcp`](https://www.npmjs.com/package/@asindev/mcp) | `npx -y @asindev/mcp` |
|
|
167
172
|
|
|
173
|
+
## Trademarks
|
|
174
|
+
|
|
175
|
+
Amazon® is a trademark of Amazon.com, Inc. or its affiliates. Asin is not affiliated with, endorsed or sponsored by Amazon.
|
|
176
|
+
|
|
168
177
|
## License
|
|
169
178
|
|
|
170
179
|
MIT — see [LICENSE](LICENSE).
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "asindotdev"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2.0"
|
|
8
8
|
description = "Official Python SDK for the Asin Amazon price tracking API."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -14,7 +14,7 @@ authors = [
|
|
|
14
14
|
{ name = "Asin", email = "contact@asin.dev" },
|
|
15
15
|
]
|
|
16
16
|
keywords = [
|
|
17
|
-
"amazon
|
|
17
|
+
"amazon",
|
|
18
18
|
"price-tracking",
|
|
19
19
|
"price-history",
|
|
20
20
|
"asin",
|
|
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from typing import Any, Literal, cast
|
|
6
6
|
|
|
7
|
+
from ._serialization import JSON_NULL
|
|
7
8
|
from .models import APIResponse, JsonResponse, RequestOptions
|
|
8
9
|
|
|
9
10
|
|
|
@@ -86,7 +87,7 @@ class _SyncOperations:
|
|
|
86
87
|
*,
|
|
87
88
|
request_options: RequestOptions | None = None,
|
|
88
89
|
) -> JsonResponse:
|
|
89
|
-
"""Plan and remaining credits. Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month
|
|
90
|
+
"""Plan and remaining credits. Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month, the credits each alert email costs, the days of history you can read and, on the free plan, the API and MCP requests…
|
|
90
91
|
|
|
91
92
|
``GET /account``
|
|
92
93
|
"""
|
|
@@ -104,14 +105,14 @@ class _SyncOperations:
|
|
|
104
105
|
days: int | None = None,
|
|
105
106
|
request_options: RequestOptions | None = None,
|
|
106
107
|
) -> JsonResponse:
|
|
107
|
-
"""Price history of any ASIN. Every price Asin read for an ASIN on a marketplace over the period, whoever tracks it, oldest first, with the lowest, highest and average of those prices. A
|
|
108
|
+
"""Price history of any ASIN. Every price Asin read for an ASIN on a marketplace over the period, whoever tracks it, oldest first, with the lowest, highest and average of those prices. A price the store gave in another currency than the marketplace's isn't part of it.…
|
|
108
109
|
|
|
109
110
|
``GET /history``
|
|
110
111
|
|
|
111
112
|
Args:
|
|
112
113
|
asin: 10-character ASIN
|
|
113
114
|
marketplace: Amazon store, e.g. com for amazon.com
|
|
114
|
-
days: History period in days
|
|
115
|
+
days: History period in days. The free plan reads the last 30: history_days says which period was returned.
|
|
115
116
|
"""
|
|
116
117
|
return cast(
|
|
117
118
|
JsonResponse,
|
|
@@ -159,7 +160,7 @@ class _SyncOperations:
|
|
|
159
160
|
|
|
160
161
|
Args:
|
|
161
162
|
id: product_id returned when the product was added
|
|
162
|
-
days: History period in days
|
|
163
|
+
days: History period in days. The free plan reads the last 30: history_days says which period was returned.
|
|
163
164
|
"""
|
|
164
165
|
return cast(
|
|
165
166
|
JsonResponse, self._call("get_product", {"id": id, "days": days}, request_options)
|
|
@@ -252,9 +253,9 @@ class _SyncOperations:
|
|
|
252
253
|
``POST /products``
|
|
253
254
|
|
|
254
255
|
Args:
|
|
255
|
-
product: ASIN (B09DFCB66S) or Amazon product link
|
|
256
|
+
product: ASIN (B09DFCB66S) or Amazon product link.
|
|
256
257
|
marketplace: Amazon store, e.g. com for amazon.com. A product link sets it on its own.
|
|
257
|
-
target_price: Email the owner when the price goes at or below this amount. null removes it.
|
|
258
|
+
target_price: Email the owner when the price goes at or below this amount (on the free plan, for the first 5 products with an alert). null removes it.
|
|
258
259
|
interval_minutes: Minutes between two checks (1440 = daily). Checks faster than daily need a plan or a credit pack: every 60 minutes with a pack or Starter, 30 with Pro, 5 with Business.
|
|
259
260
|
wait: Answer once the first check is done (up to 45 seconds)
|
|
260
261
|
"""
|
|
@@ -283,15 +284,15 @@ class _SyncOperations:
|
|
|
283
284
|
paused: bool | None = None,
|
|
284
285
|
request_options: RequestOptions | None = None,
|
|
285
286
|
) -> JsonResponse:
|
|
286
|
-
"""Change alerts and checks. Target price, drop alerts, check interval, or pause. Send only what changes.
|
|
287
|
+
"""Change alerts and checks. Target price, drop alerts, check interval, or pause. Send only what changes. On the free plan, alerts (price drop, back in stock, target price) email for the first 5 products added among the active ones with an alert set; the others stay t…
|
|
287
288
|
|
|
288
289
|
``PATCH /products/{id}``
|
|
289
290
|
|
|
290
291
|
Args:
|
|
291
292
|
id: product_id returned when the product was added
|
|
292
|
-
target_price: Email the owner when the price goes at or below this amount. null removes it.
|
|
293
|
+
target_price: Email the owner when the price goes at or below this amount (on the free plan, for the first 5 products with an alert). null removes it.
|
|
293
294
|
interval_minutes: Minutes between two checks (1440 = daily). Checks faster than daily need a plan or a credit pack: every 60 minutes with a pack or Starter, 30 with Pro, 5 with Business.
|
|
294
|
-
alert_on_drop: Email when the price drops or the product is back in stock
|
|
295
|
+
alert_on_drop: Email when the price drops or the product is back in stock (on the free plan, for the first 5 products with an alert)
|
|
295
296
|
paused: Stop checking (and charging) for now; false resumes
|
|
296
297
|
"""
|
|
297
298
|
return cast(
|
|
@@ -309,6 +310,22 @@ class _SyncOperations:
|
|
|
309
310
|
),
|
|
310
311
|
)
|
|
311
312
|
|
|
313
|
+
def clear_target_price(
|
|
314
|
+
self, *, id: str, request_options: RequestOptions | None = None
|
|
315
|
+
) -> JsonResponse:
|
|
316
|
+
"""Remove the product's target price.
|
|
317
|
+
|
|
318
|
+
``PATCH /products/{id}`` with the body ``{"target_price": null}``. ``update_product(target_price=None)``
|
|
319
|
+
cannot do it, because ``None`` values are never sent.
|
|
320
|
+
|
|
321
|
+
Args:
|
|
322
|
+
id: product_id returned when the product was added
|
|
323
|
+
"""
|
|
324
|
+
return cast(
|
|
325
|
+
JsonResponse,
|
|
326
|
+
self._call("update_product", {"id": id, "target_price": JSON_NULL}, request_options),
|
|
327
|
+
)
|
|
328
|
+
|
|
312
329
|
|
|
313
330
|
class _AsyncOperations:
|
|
314
331
|
"""Generated Asin endpoint methods."""
|
|
@@ -390,7 +407,7 @@ class _AsyncOperations:
|
|
|
390
407
|
*,
|
|
391
408
|
request_options: RequestOptions | None = None,
|
|
392
409
|
) -> JsonResponse:
|
|
393
|
-
"""Plan and remaining credits. Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month
|
|
410
|
+
"""Plan and remaining credits. Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month, the credits each alert email costs, the days of history you can read and, on the free plan, the API and MCP requests…
|
|
394
411
|
|
|
395
412
|
``GET /account``
|
|
396
413
|
"""
|
|
@@ -408,14 +425,14 @@ class _AsyncOperations:
|
|
|
408
425
|
days: int | None = None,
|
|
409
426
|
request_options: RequestOptions | None = None,
|
|
410
427
|
) -> JsonResponse:
|
|
411
|
-
"""Price history of any ASIN. Every price Asin read for an ASIN on a marketplace over the period, whoever tracks it, oldest first, with the lowest, highest and average of those prices. A
|
|
428
|
+
"""Price history of any ASIN. Every price Asin read for an ASIN on a marketplace over the period, whoever tracks it, oldest first, with the lowest, highest and average of those prices. A price the store gave in another currency than the marketplace's isn't part of it.…
|
|
412
429
|
|
|
413
430
|
``GET /history``
|
|
414
431
|
|
|
415
432
|
Args:
|
|
416
433
|
asin: 10-character ASIN
|
|
417
434
|
marketplace: Amazon store, e.g. com for amazon.com
|
|
418
|
-
days: History period in days
|
|
435
|
+
days: History period in days. The free plan reads the last 30: history_days says which period was returned.
|
|
419
436
|
"""
|
|
420
437
|
return cast(
|
|
421
438
|
JsonResponse,
|
|
@@ -465,7 +482,7 @@ class _AsyncOperations:
|
|
|
465
482
|
|
|
466
483
|
Args:
|
|
467
484
|
id: product_id returned when the product was added
|
|
468
|
-
days: History period in days
|
|
485
|
+
days: History period in days. The free plan reads the last 30: history_days says which period was returned.
|
|
469
486
|
"""
|
|
470
487
|
return cast(
|
|
471
488
|
JsonResponse, await self._call("get_product", {"id": id, "days": days}, request_options)
|
|
@@ -558,9 +575,9 @@ class _AsyncOperations:
|
|
|
558
575
|
``POST /products``
|
|
559
576
|
|
|
560
577
|
Args:
|
|
561
|
-
product: ASIN (B09DFCB66S) or Amazon product link
|
|
578
|
+
product: ASIN (B09DFCB66S) or Amazon product link.
|
|
562
579
|
marketplace: Amazon store, e.g. com for amazon.com. A product link sets it on its own.
|
|
563
|
-
target_price: Email the owner when the price goes at or below this amount. null removes it.
|
|
580
|
+
target_price: Email the owner when the price goes at or below this amount (on the free plan, for the first 5 products with an alert). null removes it.
|
|
564
581
|
interval_minutes: Minutes between two checks (1440 = daily). Checks faster than daily need a plan or a credit pack: every 60 minutes with a pack or Starter, 30 with Pro, 5 with Business.
|
|
565
582
|
wait: Answer once the first check is done (up to 45 seconds)
|
|
566
583
|
"""
|
|
@@ -589,15 +606,15 @@ class _AsyncOperations:
|
|
|
589
606
|
paused: bool | None = None,
|
|
590
607
|
request_options: RequestOptions | None = None,
|
|
591
608
|
) -> JsonResponse:
|
|
592
|
-
"""Change alerts and checks. Target price, drop alerts, check interval, or pause. Send only what changes.
|
|
609
|
+
"""Change alerts and checks. Target price, drop alerts, check interval, or pause. Send only what changes. On the free plan, alerts (price drop, back in stock, target price) email for the first 5 products added among the active ones with an alert set; the others stay t…
|
|
593
610
|
|
|
594
611
|
``PATCH /products/{id}``
|
|
595
612
|
|
|
596
613
|
Args:
|
|
597
614
|
id: product_id returned when the product was added
|
|
598
|
-
target_price: Email the owner when the price goes at or below this amount. null removes it.
|
|
615
|
+
target_price: Email the owner when the price goes at or below this amount (on the free plan, for the first 5 products with an alert). null removes it.
|
|
599
616
|
interval_minutes: Minutes between two checks (1440 = daily). Checks faster than daily need a plan or a credit pack: every 60 minutes with a pack or Starter, 30 with Pro, 5 with Business.
|
|
600
|
-
alert_on_drop: Email when the price drops or the product is back in stock
|
|
617
|
+
alert_on_drop: Email when the price drops or the product is back in stock (on the free plan, for the first 5 products with an alert)
|
|
601
618
|
paused: Stop checking (and charging) for now; false resumes
|
|
602
619
|
"""
|
|
603
620
|
return cast(
|
|
@@ -614,3 +631,21 @@ class _AsyncOperations:
|
|
|
614
631
|
request_options,
|
|
615
632
|
),
|
|
616
633
|
)
|
|
634
|
+
|
|
635
|
+
async def clear_target_price(
|
|
636
|
+
self, *, id: str, request_options: RequestOptions | None = None
|
|
637
|
+
) -> JsonResponse:
|
|
638
|
+
"""Remove the product's target price.
|
|
639
|
+
|
|
640
|
+
``PATCH /products/{id}`` with the body ``{"target_price": null}``. ``update_product(target_price=None)``
|
|
641
|
+
cannot do it, because ``None`` values are never sent.
|
|
642
|
+
|
|
643
|
+
Args:
|
|
644
|
+
id: product_id returned when the product was added
|
|
645
|
+
"""
|
|
646
|
+
return cast(
|
|
647
|
+
JsonResponse,
|
|
648
|
+
await self._call(
|
|
649
|
+
"update_product", {"id": id, "target_price": JSON_NULL}, request_options
|
|
650
|
+
),
|
|
651
|
+
)
|
|
@@ -30,11 +30,15 @@ def create_raw_response(response: httpx.Response, body: bytes) -> RawResponse:
|
|
|
30
30
|
def create_api_error(raw_response: RawResponse) -> AsinAPIError:
|
|
31
31
|
parsed, value = _try_parse_json(raw_response.body)
|
|
32
32
|
message = None
|
|
33
|
+
code: str | None = None
|
|
33
34
|
if parsed and isinstance(value, dict):
|
|
34
35
|
# The API answers {"error": {"code", "message"}}.
|
|
35
36
|
nested = value.get("error")
|
|
36
|
-
if isinstance(nested, dict)
|
|
37
|
-
|
|
37
|
+
if isinstance(nested, dict):
|
|
38
|
+
if isinstance(nested.get("message"), str):
|
|
39
|
+
message = nested["message"]
|
|
40
|
+
if isinstance(nested.get("code"), str):
|
|
41
|
+
code = nested["code"]
|
|
38
42
|
for key in _ERROR_MESSAGE_KEYS:
|
|
39
43
|
candidate = value.get(key)
|
|
40
44
|
if isinstance(candidate, str) and candidate:
|
|
@@ -44,6 +48,7 @@ def create_api_error(raw_response: RawResponse) -> AsinAPIError:
|
|
|
44
48
|
raw_response=raw_response,
|
|
45
49
|
response_body=value if parsed else None,
|
|
46
50
|
error_message=message,
|
|
51
|
+
error_code=code,
|
|
47
52
|
)
|
|
48
53
|
|
|
49
54
|
|
|
@@ -18,6 +18,17 @@ _PATH_PARAM = re.compile(r"\{([^}]+)\}")
|
|
|
18
18
|
QUERY_STRING_PARAMS = {"/products/{id}/check": ("wait",)}
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
class _JsonNull:
|
|
22
|
+
__slots__ = ()
|
|
23
|
+
|
|
24
|
+
def __repr__(self) -> str:
|
|
25
|
+
return "JSON_NULL"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
JSON_NULL = _JsonNull()
|
|
29
|
+
"""Internal marker sent as ``null`` in a JSON body, where ``None`` means "not set" and is omitted."""
|
|
30
|
+
|
|
31
|
+
|
|
21
32
|
@dataclass(frozen=True, slots=True)
|
|
22
33
|
class SerializedRequest:
|
|
23
34
|
path: str
|
|
@@ -32,7 +43,8 @@ def serialize_request(
|
|
|
32
43
|
|
|
33
44
|
``wait`` stays in the query string on POST /products/{id}/check.
|
|
34
45
|
|
|
35
|
-
``None`` values and empty sequences are omitted; ``False`` and ``0`` are sent.
|
|
46
|
+
``None`` values and empty sequences are omitted; ``False`` and ``0`` are sent. ``JSON_NULL`` becomes ``null``
|
|
47
|
+
in a JSON body.
|
|
36
48
|
"""
|
|
37
49
|
|
|
38
50
|
if params is not None and not isinstance(params, Mapping):
|
|
@@ -66,7 +78,8 @@ def serialize_request(
|
|
|
66
78
|
for name, value in remaining.items():
|
|
67
79
|
if isinstance(value, float) and not math.isfinite(value):
|
|
68
80
|
raise AsinSerializationError(f'The "{name}" parameter must be a finite number.', name)
|
|
69
|
-
|
|
81
|
+
body = {name: None if value is JSON_NULL else value for name, value in remaining.items()}
|
|
82
|
+
return SerializedRequest(path=path, query=query, body=body)
|
|
70
83
|
|
|
71
84
|
|
|
72
85
|
def to_wire_string(name: str, value: Any) -> str:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.0"
|
|
@@ -34,13 +34,13 @@ DEFAULT_TIMEOUT = 120.0
|
|
|
34
34
|
DEFAULT_CONCURRENCY = 10
|
|
35
35
|
"""Tasks run at the same time by ``batch()``."""
|
|
36
36
|
MAX_RETRIES = 3
|
|
37
|
-
"""Retries after a network error or a 408,
|
|
37
|
+
"""Retries after a network error or a 408, 500, 502, 503 or 504 response."""
|
|
38
38
|
RETRY_BACKOFF_FACTOR = 1.5
|
|
39
39
|
"""Each retry waits this many times longer than the previous one (a Retry-After header wins)."""
|
|
40
40
|
DEFAULT_RETRY_DELAY = 1.0
|
|
41
41
|
"""Seconds before the first retry."""
|
|
42
42
|
MAX_RETRY_DELAY = 30.0
|
|
43
|
-
RETRYABLE_STATUSES = frozenset({408,
|
|
43
|
+
RETRYABLE_STATUSES = frozenset({408, 500, 502, 503, 504})
|
|
44
44
|
API_KEY_ENVIRONMENT_VARIABLE = "ASIN_API_KEY"
|
|
45
45
|
|
|
46
46
|
|
|
@@ -40,6 +40,7 @@ class AsinAPIError(AsinError):
|
|
|
40
40
|
|
|
41
41
|
status: int
|
|
42
42
|
error_message: str | None
|
|
43
|
+
error_code: str | None
|
|
43
44
|
response_body: Any | None
|
|
44
45
|
raw_response: RawResponse
|
|
45
46
|
|
|
@@ -49,12 +50,14 @@ class AsinAPIError(AsinError):
|
|
|
49
50
|
raw_response: RawResponse,
|
|
50
51
|
response_body: Any | None = None,
|
|
51
52
|
error_message: str | None = None,
|
|
53
|
+
error_code: str | None = None,
|
|
52
54
|
) -> None:
|
|
53
55
|
super().__init__(
|
|
54
56
|
error_message or f"Asin API request failed with status {raw_response.status}."
|
|
55
57
|
)
|
|
56
58
|
self.status = raw_response.status
|
|
57
59
|
self.error_message = error_message
|
|
60
|
+
self.error_code = error_code
|
|
58
61
|
self.response_body = response_body
|
|
59
62
|
self.raw_response = raw_response
|
|
60
63
|
|
|
@@ -193,6 +193,7 @@ def test_api_error() -> None:
|
|
|
193
193
|
assert info.value.status == 401
|
|
194
194
|
assert str(info.value) == "Invalid API Key"
|
|
195
195
|
assert info.value.response_body == {"error": "Invalid API Key"}
|
|
196
|
+
assert info.value.error_code is None
|
|
196
197
|
|
|
197
198
|
|
|
198
199
|
def test_non_json_error_body() -> None:
|
|
@@ -237,13 +238,28 @@ async def test_async_client() -> None:
|
|
|
237
238
|
|
|
238
239
|
|
|
239
240
|
def test_retries_then_succeeds() -> None:
|
|
240
|
-
statuses = [503,
|
|
241
|
+
statuses = [503, 502, 200]
|
|
241
242
|
client, requests = _client(lambda _r: _json({"ok": True}, statuses.pop(0)), retry_delay=0.001)
|
|
242
243
|
response = client.request("GET", "/account")
|
|
243
244
|
assert isinstance(response, JsonResponse)
|
|
244
245
|
assert len(requests) == 3
|
|
245
246
|
|
|
246
247
|
|
|
248
|
+
def test_never_retries_429() -> None:
|
|
249
|
+
statuses = [429, 200]
|
|
250
|
+
client, requests = _client(
|
|
251
|
+
lambda _r: _json(
|
|
252
|
+
{"error": {"code": "rate_limited", "message": "Slow down"}}, statuses.pop(0)
|
|
253
|
+
),
|
|
254
|
+
retry_delay=0.001,
|
|
255
|
+
)
|
|
256
|
+
with pytest.raises(AsinAPIError) as info:
|
|
257
|
+
client.request("GET", "/account")
|
|
258
|
+
assert info.value.status == 429
|
|
259
|
+
assert info.value.error_code == "rate_limited"
|
|
260
|
+
assert len(requests) == 1
|
|
261
|
+
|
|
262
|
+
|
|
247
263
|
def test_gives_up_after_max_retries() -> None:
|
|
248
264
|
client, requests = _client(
|
|
249
265
|
lambda _r: _json({"error": "busy"}, 503), retry_delay=0.001, max_retries=2
|
|
@@ -270,7 +286,7 @@ def test_retries_network_errors_and_retry_after() -> None:
|
|
|
270
286
|
if calls["n"] == 1:
|
|
271
287
|
raise httpx.ConnectError("reset")
|
|
272
288
|
if calls["n"] == 2:
|
|
273
|
-
return httpx.Response(
|
|
289
|
+
return httpx.Response(503, json={}, headers={"retry-after": "0"})
|
|
274
290
|
return _json({"ok": True})
|
|
275
291
|
|
|
276
292
|
client, _ = _client(flaky, retry_delay=0.001)
|
|
@@ -310,6 +326,37 @@ def test_nested_error_message() -> None:
|
|
|
310
326
|
with pytest.raises(AsinAPIError) as info:
|
|
311
327
|
client.get_account()
|
|
312
328
|
assert info.value.error_message == "No credits left"
|
|
329
|
+
assert info.value.error_code == "insufficient_credits"
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def test_clear_target_price_sends_null() -> None:
|
|
333
|
+
client, requests = _client(lambda _r: _json({"product_id": "p1", "target_price": None}))
|
|
334
|
+
response = client.clear_target_price(id="p1")
|
|
335
|
+
assert isinstance(response, JsonResponse)
|
|
336
|
+
assert requests[0].method == "PATCH"
|
|
337
|
+
assert requests[0].url.path == "/api/v1/products/p1"
|
|
338
|
+
assert requests[0].url.query == b""
|
|
339
|
+
assert requests[0].content == b'{"target_price": null}'
|
|
340
|
+
client.update_product(id="p1", target_price=None, paused=True)
|
|
341
|
+
assert json.loads(requests[1].content) == {"paused": True}
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
@pytest.mark.asyncio
|
|
345
|
+
async def test_async_clear_target_price_sends_null() -> None:
|
|
346
|
+
requests: list[httpx.Request] = []
|
|
347
|
+
|
|
348
|
+
def handler(request: httpx.Request) -> httpx.Response:
|
|
349
|
+
requests.append(request)
|
|
350
|
+
return _json({})
|
|
351
|
+
|
|
352
|
+
async with AsyncAsinClient(
|
|
353
|
+
"k", http_client=httpx.AsyncClient(transport=httpx.MockTransport(handler))
|
|
354
|
+
) as client:
|
|
355
|
+
response = await client.clear_target_price(id="p1")
|
|
356
|
+
assert isinstance(response, JsonResponse)
|
|
357
|
+
assert requests[0].method == "PATCH"
|
|
358
|
+
assert requests[0].url.path == "/api/v1/products/p1"
|
|
359
|
+
assert requests[0].content == b'{"target_price": null}'
|
|
313
360
|
|
|
314
361
|
|
|
315
362
|
def test_request_level_retry_override() -> None:
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.1.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|