asindotdev 0.1.0__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.
asin/models.py ADDED
@@ -0,0 +1,81 @@
1
+ """Public response and option types."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Mapping
6
+ from dataclasses import dataclass, field
7
+ from typing import Any, Generic, Literal, TypeAlias, TypeVar
8
+
9
+ T = TypeVar("T")
10
+
11
+ HTTPMethod: TypeAlias = Literal["GET", "POST", "PATCH", "DELETE"]
12
+
13
+
14
+ @dataclass(frozen=True, slots=True)
15
+ class RawResponse:
16
+ """Buffered HTTP response: status, lower-cased multi-value headers, content type and body bytes."""
17
+
18
+ status: int
19
+ status_text: str
20
+ headers: Mapping[str, tuple[str, ...]]
21
+ content_type: str | None
22
+ body: bytes = field(repr=False)
23
+
24
+
25
+ @dataclass(frozen=True, slots=True)
26
+ class JsonResponse:
27
+ """A successful JSON response; ``data`` is the parsed body."""
28
+
29
+ data: Any
30
+ raw_response: RawResponse = field(repr=False)
31
+ kind: Literal["json"] = "json"
32
+
33
+
34
+ @dataclass(frozen=True, slots=True)
35
+ class BinaryResponse:
36
+ """A successful non-JSON response (image, PDF, HTML…)."""
37
+
38
+ bytes: bytes = field(repr=False)
39
+ content_type: str | None = None
40
+ raw_response: RawResponse | None = field(default=None, repr=False)
41
+ kind: Literal["binary"] = "binary"
42
+
43
+
44
+ APIResponse: TypeAlias = JsonResponse | BinaryResponse
45
+
46
+
47
+ @dataclass(frozen=True, slots=True)
48
+ class RequestOptions:
49
+ """Per-request options for generated endpoint methods."""
50
+
51
+ method: HTTPMethod | None = None
52
+ """Defaults to the method of the operation."""
53
+ timeout: float | None = None
54
+ """Seconds; overrides the client timeout for this request."""
55
+ headers: Mapping[str, str] | None = None
56
+ """Extra headers for this request."""
57
+ max_retries: int | None = None
58
+ """Overrides the client retry count for this request (0 disables retries)."""
59
+
60
+
61
+ @dataclass(frozen=True, slots=True)
62
+ class BatchResult(Generic[T]):
63
+ """Outcome of one ``batch()`` item: ``value`` when ``ok``, else ``error``."""
64
+
65
+ index: int
66
+ value: T | None = None
67
+ error: BaseException | None = None
68
+
69
+ @property
70
+ def ok(self) -> bool:
71
+ return self.error is None
72
+
73
+
74
+ @dataclass(frozen=True, slots=True)
75
+ class EndpointDefinition:
76
+ """Path, supported methods and required parameters of one documented operation."""
77
+
78
+ path: str
79
+ methods: tuple[HTTPMethod, ...]
80
+ response: Literal["json", "any"]
81
+ required: tuple[str, ...]
asin/py.typed ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,201 @@
1
+ Metadata-Version: 2.5
2
+ Name: asindotdev
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for the Asin Amazon price tracking API.
5
+ Project-URL: Homepage, https://www.asin.dev
6
+ Project-URL: Documentation, https://www.asin.dev/docs
7
+ Project-URL: Repository, https://github.com/asindotdev/asin-python
8
+ Project-URL: Issues, https://github.com/asindotdev/asin-python/issues
9
+ Author-email: Asin <contact@asin.dev>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: amazon-api,api,asin,price-history,price-tracking,sdk
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Internet :: WWW/HTTP
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: httpx<1,>=0.27
24
+ Provides-Extra: dev
25
+ Requires-Dist: build<2,>=1.2; extra == 'dev'
26
+ Requires-Dist: mypy>=1.13; extra == 'dev'
27
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
28
+ Requires-Dist: pytest>=8.3; extra == 'dev'
29
+ Requires-Dist: ruff<1,>=0.8; extra == 'dev'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # Asin Python SDK
33
+
34
+ The official Python SDK for the [Asin](https://www.asin.dev) Amazon price tracking API.
35
+
36
+ Track Amazon prices and products with a scheduled watchlist, price history, offers and alerts.
37
+
38
+ The SDK exposes **11 typed methods**, one per documented endpoint, with blocking and `asyncio` clients built on [HTTPX](https://www.python-httpx.org/), plus a generic `request()`.
39
+
40
+ ## Requirements
41
+
42
+ - Python 3.11 or newer
43
+
44
+ ## Installation
45
+
46
+ ```sh
47
+ pip install asindotdev
48
+ ```
49
+
50
+ ## Get your API key
51
+
52
+ [Sign up for Asin](https://www.asin.dev/signup) or sign in, then copy your API key from the [dashboard](https://www.asin.dev/app). The client reads the `ASIN_API_KEY` environment variable when no key is passed.
53
+
54
+ ## Quick start
55
+
56
+ ```python
57
+ import os
58
+
59
+ from asin import AsinClient
60
+
61
+ with AsinClient(os.environ["ASIN_API_KEY"]) as client:
62
+ response = client.search_amazon(query="wireless earbuds")
63
+ print(response.data)
64
+ ```
65
+
66
+ Keyword arguments mirror the [API reference](https://www.asin.dev/docs). Python keywords get a trailing underscore (`from_=`), and the wire name is used on the request.
67
+
68
+ ## Async I/O
69
+
70
+ ```python
71
+ import asyncio
72
+
73
+ from asin import AsyncAsinClient
74
+
75
+
76
+ async def main() -> None:
77
+ async with AsyncAsinClient() as client:
78
+ response = await client.search_amazon(query="wireless earbuds")
79
+ print(response.data)
80
+
81
+
82
+ asyncio.run(main())
83
+ ```
84
+
85
+ ## HTTP methods
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. Null values are never sent, so `target_price` cannot be removed through the SDK yet.
88
+
89
+ `None` values are omitted, `False` and `0` are sent, and sequences repeat the parameter name.
90
+
91
+ ## Any endpoint
92
+
93
+ ```python
94
+ response = client.request("GET", "/account")
95
+ ```
96
+
97
+ ## Errors
98
+
99
+ ```python
100
+ from asin import AsinAPIError
101
+
102
+ try:
103
+ client.search_amazon(query="wireless earbuds")
104
+ except AsinAPIError as error:
105
+ print(error.status, error, error.response_body)
106
+ ```
107
+
108
+ | Error | When |
109
+ | --- | --- |
110
+ | `AsinConfigurationError` | Missing API key, invalid options, unsupported method, closed client. |
111
+ | `AsinSerializationError` | A required parameter is missing or a value can't be sent. |
112
+ | `AsinTransportError` | Network failure or timeout. |
113
+ | `AsinAPIError` | Non-2xx status (`status`, `error_message`, `response_body`, `raw_response`). |
114
+ | `AsinResponseDecodingError` | A success response could not be decoded. |
115
+
116
+ All of them extend `AsinError`.
117
+
118
+ ## Retries
119
+
120
+ Requests are retried up to 3 times after a network error, a `408`, `429`, `500`, `502`, `503` or `504`. Other statuses, such as `400`, `401`, `402` or `404`, and client-side timeouts are not retried. The delay starts at 1 second and grows 1.5× per retry (capped at 30 seconds); a `Retry-After` header wins.
121
+
122
+ ```python
123
+ client = AsinClient(max_retries=5, retry_delay=0.5)
124
+
125
+ # or for one request
126
+ client.search_amazon(query="wireless earbuds", request_options=RequestOptions(max_retries=0))
127
+ ```
128
+
129
+ ## Batch requests
130
+
131
+ `batch()` runs a function per item on 10 threads (`concurrency`) and returns one `BatchResult` per item, in input order. A failing item never stops the others. `AsyncAsinClient.batch()` does the same with `asyncio`.
132
+
133
+ ```python
134
+ inputs = ["wireless earbuds", "mechanical keyboard", "usb-c hub"]
135
+ results = client.batch(inputs, lambda query: client.search_amazon(query=query), concurrency=5)
136
+
137
+ for result in results:
138
+ if result.ok:
139
+ print(result.value.data)
140
+ else:
141
+ print(inputs[result.index], result.error)
142
+ ```
143
+
144
+ | Constant | Default | Description |
145
+ | --- | --- | --- |
146
+ | `DEFAULT_CONCURRENCY` | `10` | Tasks run at the same time by batch |
147
+ | `DEFAULT_TIMEOUT` | `120.0` | Request timeout (seconds) |
148
+ | `MAX_RETRIES` | `3` | Retry attempts after a network error, a 408/429/5xx |
149
+ | `RETRY_BACKOFF_FACTOR` | `1.5` | Exponential backoff multiplier |
150
+ | `DEFAULT_RETRY_DELAY` | `1.0` | Delay before the first retry (seconds) |
151
+
152
+ ## Timeouts and custom HTTPX clients
153
+
154
+ ```python
155
+ import httpx
156
+
157
+ from asin import AsinClient, RequestOptions
158
+
159
+ client = AsinClient(timeout=60) # seconds, default 120, None disables
160
+ client.search_amazon(query="wireless earbuds", request_options=RequestOptions(timeout=30))
161
+
162
+ # Bring your own HTTPX client (proxies, limits, event hooks…). You keep ownership of it.
163
+ http_client = httpx.Client(proxy="http://localhost:8080")
164
+ client = AsinClient(http_client=http_client)
165
+ ```
166
+
167
+ ## Endpoints
168
+
169
+ 11 methods, generated from the [OpenAPI document](https://www.asin.dev/openapi.json).
170
+
171
+ | Method | HTTP | Description |
172
+ | --- | --- | --- |
173
+ | `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… |
174
+ | `delete_product()` | DELETE `/products/{id}` | Removes the product and its price history. |
175
+ | `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. |
177
+ | `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
+ | `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
+ | `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
+ | `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
+ | `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
+ | `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. |
184
+
185
+ ## All Asin SDKs
186
+
187
+ | SDK | Package | Install |
188
+ | --- | --- | --- |
189
+ | Node.js | [`@asindev/sdk`](https://www.npmjs.com/package/@asindev/sdk) | `npm install @asindev/sdk` |
190
+ | Python | [`asindotdev`](https://pypi.org/project/asindotdev/) | `pip install asindotdev` |
191
+ | Go | [`asin-go`](https://pkg.go.dev/github.com/asindotdev/asin-go) | `go get github.com/asindotdev/asin-go` |
192
+ | .NET | [`Asin`](https://www.nuget.org/packages/Asin) | `dotnet add package Asin` |
193
+ | Ruby | [`asindotdev`](https://rubygems.org/gems/asindotdev) | `gem install asindotdev` |
194
+ | PHP | [`asindotdev/sdk`](https://packagist.org/packages/asindotdev/sdk) | `composer require asindotdev/sdk` |
195
+ | Java | [`asin-java`](https://github.com/asindotdev/asin-java) | build from source, see its README |
196
+ | CLI | [`@asindev/cli`](https://www.npmjs.com/package/@asindev/cli) | `npm install -g @asindev/cli` |
197
+ | MCP server | [`@asindev/mcp`](https://www.npmjs.com/package/@asindev/mcp) | `npx -y @asindev/mcp` |
198
+
199
+ ## License
200
+
201
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,14 @@
1
+ asin/__init__.py,sha256=zgkNZ3aIaUvcZmR1ToAYfJeVaXeXsE1-RWR8DBfsp6Y,1212
2
+ asin/_endpoints.py,sha256=-U-jtftyzExaW8VkJxa1urxlpRsma_Bpdijt8wNUSjA,1881
3
+ asin/_operations.py,sha256=PU4liDTGk1MNufFnaF8sLffmzTuT8B9U9gtyoio_bUc,22857
4
+ asin/_response.py,sha256=gAD7XElM8XgtjRWvhLiMZeOjxUySt7gq_SVlrRpUwC4,3082
5
+ asin/_serialization.py,sha256=vs2Xid_d8cEezyWkr_DYZRxTYkx-K1V7EuDoIXwP7CQ,3890
6
+ asin/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
7
+ asin/client.py,sha256=lzdUuLzWDK85840w2EQOUPbiVmQd2aP0NYj_XP5I1Lc,16951
8
+ asin/errors.py,sha256=qW90EoF72CqShHxdJ64Ot6I9ZmmUcEhl5mgikdlcR1g,1916
9
+ asin/models.py,sha256=2JgilW_j9lNtn_jrsmpo2bkPRN_OnE7UthgYgSCmIOA,2288
10
+ asin/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
11
+ asindotdev-0.1.0.dist-info/METADATA,sha256=_MOD909hwXzQA40QKSxiJyS56poRa5LI0ZVy0zPaDn0,8761
12
+ asindotdev-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
13
+ asindotdev-0.1.0.dist-info/licenses/LICENSE,sha256=40XiVEShZ-xwT0JK4A1MdXg9Hl3GVBACPZQKDSmasgU,1061
14
+ asindotdev-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Asin
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.