watchlogdev 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.
watchlog/errors.py ADDED
@@ -0,0 +1,76 @@
1
+ """Watchlog SDK error categories."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from .models import RawResponse
8
+
9
+
10
+ class WatchlogError(Exception):
11
+ """Base class for all SDK-defined errors."""
12
+
13
+
14
+ class WatchlogConfigurationError(WatchlogError):
15
+ """The client configuration is missing or unusable."""
16
+
17
+
18
+ class WatchlogSerializationError(WatchlogError):
19
+ """A request value cannot be represented safely on the wire."""
20
+
21
+ param: str | None
22
+
23
+ def __init__(self, message: str, param: str | None = None) -> None:
24
+ super().__init__(message)
25
+ self.param = param
26
+
27
+
28
+ class WatchlogTransportError(WatchlogError):
29
+ """The request failed before a complete HTTP response was received."""
30
+
31
+ cause: Exception
32
+
33
+ def __init__(self, message: str, cause: Exception) -> None:
34
+ super().__init__(message)
35
+ self.cause = cause
36
+
37
+
38
+ class WatchlogAPIError(WatchlogError):
39
+ """Watchlog returned a non-success HTTP status."""
40
+
41
+ status: int
42
+ error_message: str | None
43
+ error_code: str | None
44
+ response_body: Any | None
45
+ raw_response: RawResponse
46
+
47
+ def __init__(
48
+ self,
49
+ *,
50
+ raw_response: RawResponse,
51
+ response_body: Any | None = None,
52
+ error_message: str | None = None,
53
+ error_code: str | None = None,
54
+ ) -> None:
55
+ super().__init__(
56
+ error_message or f"Watchlog API request failed with status {raw_response.status}."
57
+ )
58
+ self.status = raw_response.status
59
+ self.error_message = error_message
60
+ self.error_code = error_code
61
+ self.response_body = response_body
62
+ self.raw_response = raw_response
63
+
64
+
65
+ class WatchlogResponseDecodingError(WatchlogError):
66
+ """A successful response could not be decoded as the documented representation."""
67
+
68
+ raw_response: RawResponse
69
+ cause: Exception | None
70
+
71
+ def __init__(
72
+ self, message: str, raw_response: RawResponse, cause: Exception | None = None
73
+ ) -> None:
74
+ super().__init__(message)
75
+ self.raw_response = raw_response
76
+ self.cause = cause
watchlog/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, ...]
watchlog/py.typed ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.5
2
+ Name: watchlogdev
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for the Watchlog watch price tracking API.
5
+ Project-URL: Homepage, https://www.watchlog.dev
6
+ Project-URL: Documentation, https://www.watchlog.dev/docs
7
+ Project-URL: Repository, https://github.com/watchlogdev/watchlog-python
8
+ Project-URL: Issues, https://github.com/watchlogdev/watchlog-python/issues
9
+ Author-email: Watchlog <contact@watchlog.dev>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: api,luxury-watches,price-history,price-tracking,sdk,watch-prices,watchlog
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
+ # Watchlog Python SDK
33
+
34
+ The official Python SDK for the [Watchlog](https://www.watchlog.dev) watch price tracking API.
35
+
36
+ Track watch prices, by reference number or single listing, with a scheduled watchlist, price history and alerts.
37
+
38
+ The SDK exposes **9 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 watchlogdev
48
+ ```
49
+
50
+ ## Get your API key
51
+
52
+ [Sign up for Watchlog](https://www.watchlog.dev/signup) or sign in, then copy your API key from the [dashboard](https://www.watchlog.dev/app). The client reads the `WATCHLOG_API_KEY` environment variable when no key is passed.
53
+
54
+ ## Quick start
55
+
56
+ ```python
57
+ import os
58
+
59
+ from watchlog import WatchlogClient
60
+
61
+ with WatchlogClient(os.environ["WATCHLOG_API_KEY"]) as client:
62
+ response = client.search_watches(query="submariner")
63
+ print(response.data)
64
+ ```
65
+
66
+ Keyword arguments mirror the [API reference](https://www.watchlog.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 watchlog import AsyncWatchlogClient
74
+
75
+
76
+ async def main() -> None:
77
+ async with AsyncWatchlogClient() as client:
78
+ response = await client.search_watches(query="submariner")
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. `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
+ ```
92
+
93
+ `None` values are omitted, `False` and `0` are sent, and sequences repeat the parameter name.
94
+
95
+ ## Any endpoint
96
+
97
+ ```python
98
+ response = client.request("GET", "/account")
99
+ ```
100
+
101
+ ## Errors
102
+
103
+ ```python
104
+ from watchlog import WatchlogAPIError
105
+
106
+ try:
107
+ client.search_watches(query="submariner")
108
+ except WatchlogAPIError as error:
109
+ print(error.status, error.error_code, error, error.response_body)
110
+ ```
111
+
112
+ | Error | When |
113
+ | --- | --- |
114
+ | `WatchlogConfigurationError` | Missing API key, invalid options, unsupported method, closed client. |
115
+ | `WatchlogSerializationError` | A required parameter is missing or a value can't be sent. |
116
+ | `WatchlogTransportError` | Network failure or timeout. |
117
+ | `WatchlogAPIError` | 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). |
118
+ | `WatchlogResponseDecodingError` | A success response could not be decoded. |
119
+
120
+ All of them extend `WatchlogError`.
121
+
122
+ ## Retries
123
+
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.
125
+
126
+ ```python
127
+ client = WatchlogClient(max_retries=5, retry_delay=0.5)
128
+
129
+ # or for one request
130
+ client.search_watches(query="submariner", request_options=RequestOptions(max_retries=0))
131
+ ```
132
+
133
+ ## Batch requests
134
+
135
+ `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. `AsyncWatchlogClient.batch()` does the same with `asyncio`.
136
+
137
+ ```python
138
+ inputs = ["submariner", "speedmaster", "royal oak"]
139
+ results = client.batch(inputs, lambda query: client.search_watches(query=query), concurrency=5)
140
+
141
+ for result in results:
142
+ if result.ok:
143
+ print(result.value.data)
144
+ else:
145
+ print(inputs[result.index], result.error)
146
+ ```
147
+
148
+ | Constant | Default | Description |
149
+ | --- | --- | --- |
150
+ | `DEFAULT_CONCURRENCY` | `10` | Tasks run at the same time by batch |
151
+ | `DEFAULT_TIMEOUT` | `120.0` | Request timeout (seconds) |
152
+ | `MAX_RETRIES` | `3` | Retry attempts after a network error, a 408/5xx |
153
+ | `RETRY_BACKOFF_FACTOR` | `1.5` | Exponential backoff multiplier |
154
+ | `DEFAULT_RETRY_DELAY` | `1.0` | Delay before the first retry (seconds) |
155
+
156
+ ## Timeouts and custom HTTPX clients
157
+
158
+ ```python
159
+ import httpx
160
+
161
+ from watchlog import WatchlogClient, RequestOptions
162
+
163
+ client = WatchlogClient(timeout=60) # seconds, default 120, None disables
164
+ client.search_watches(query="submariner", request_options=RequestOptions(timeout=30))
165
+
166
+ # Bring your own HTTPX client (proxies, limits, event hooks…). You keep ownership of it.
167
+ http_client = httpx.Client(proxy="http://localhost:8080")
168
+ client = WatchlogClient(http_client=http_client)
169
+ ```
170
+
171
+ ## Endpoints
172
+
173
+ 9 methods, generated from the [OpenAPI document](https://www.watchlog.dev/openapi.json), plus `clear_target_price()`.
174
+
175
+ | Method | HTTP | Description |
176
+ | --- | --- | --- |
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}`. |
179
+ | `delete_product()` | DELETE `/products/{id}` | Removes the product and its price history. |
180
+ | `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… |
181
+ | `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 reference on this market… |
182
+ | `get_watch_history()` | GET `/history` | Every price Watchlog read for a reference or listing id in a currency over the period, whoever tracks it, oldest first, with the lowest, hi… |
183
+ | `list_products()` | GET `/products` | Your watchlist, newest first, with each product's latest state and its recent prices (trend). Filter with watch_id (and marketplace) to kno… |
184
+ | `search_watches()` | GET `/search` | Watch models matching the keywords first (watch_id is their reference number, price the lowest asking price last seen across the whole mark… |
185
+ | `track_product()` | POST `/products` | Adds a watch to your watchlist: a model by its reference number (126610LN), priced at the lowest asking price among the current listings th… |
186
+ | `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 on the market, targ… |
187
+
188
+ ## All Watchlog SDKs
189
+
190
+ | SDK | Package | Install |
191
+ | --- | --- | --- |
192
+ | Node.js | [`@watchlogdev/sdk`](https://www.npmjs.com/package/@watchlogdev/sdk) | `npm install @watchlogdev/sdk` |
193
+ | Python | [`watchlogdev`](https://pypi.org/project/watchlogdev/) | `pip install watchlogdev` |
194
+ | Go | [`watchlog-go`](https://pkg.go.dev/github.com/watchlogdev/watchlog-go) | `go get github.com/watchlogdev/watchlog-go` |
195
+ | .NET | [`Watchlog`](https://www.nuget.org/packages/Watchlog) | `dotnet add package Watchlog` |
196
+ | Ruby | [`watchlogdev`](https://rubygems.org/gems/watchlogdev) | `gem install watchlogdev` |
197
+ | PHP | [`watchlogdev/sdk`](https://packagist.org/packages/watchlogdev/sdk) | `composer require watchlogdev/sdk` |
198
+ | Java | [`watchlog-java`](https://github.com/watchlogdev/watchlog-java) | build from source, see its README |
199
+ | CLI | [`@watchlogdev/cli`](https://www.npmjs.com/package/@watchlogdev/cli) | `npm install -g @watchlogdev/cli` |
200
+ | MCP server | [`@watchlogdev/mcp`](https://www.npmjs.com/package/@watchlogdev/mcp) | `npx -y @watchlogdev/mcp` |
201
+
202
+ ## Trademarks
203
+
204
+ Watch brand and model names are trademarks of their respective owners. Watchlog is an independent service, not affiliated with any watch brand, dealer or marketplace.
205
+
206
+ ## License
207
+
208
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,14 @@
1
+ watchlog/__init__.py,sha256=Q4uLswTgxpmFBIjJyAzaDVmZMdpicEw9qVyEOOtNQWs,1280
2
+ watchlog/_endpoints.py,sha256=fiIX0R9xqemPfkEC1DudUf444V5N-Z9UKRrm6Zl6PgA,1592
3
+ watchlog/_operations.py,sha256=dD9WsFhVZv87v7tABxUPVujlumcG8rnGdsNFIAyMuUQ,21379
4
+ watchlog/_response.py,sha256=ttA2saqkZ2bdxChx6igCf0P7aug2haK29J8kiYv3Va4,3273
5
+ watchlog/_serialization.py,sha256=0moRtedJwLWjtYCh_TXC1ZZSR5wggUsM7zNg31LMU7w,4369
6
+ watchlog/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
7
+ watchlog/client.py,sha256=TthAgefEtyTPs0wSIzCl98Xq4_9iuq5pDMWIUStgFR8,17131
8
+ watchlog/errors.py,sha256=RB2LKsxKdJRna7xGO9kyScclAhThKsm88CK7ASOJ-lw,2075
9
+ watchlog/models.py,sha256=2JgilW_j9lNtn_jrsmpo2bkPRN_OnE7UthgYgSCmIOA,2288
10
+ watchlog/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
11
+ watchlogdev-0.1.0.dist-info/METADATA,sha256=q6r0qriNQGCEdguMmjkSZ2O1CV2Dg6gvloRcFGZ-Frs,9483
12
+ watchlogdev-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
13
+ watchlogdev-0.1.0.dist-info/licenses/LICENSE,sha256=zKmsB3eUktTEq6ucakX_dOlfQFBrz2oAKLjfRD5Jh84,1065
14
+ watchlogdev-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 Watchlog
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.