keepa 1.4.2__tar.gz → 1.4.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: keepa
3
- Version: 1.4.2
3
+ Version: 1.4.4
4
4
  Summary: Interfaces with keepa.com's API.
5
5
  Keywords: keepa
6
6
  Author-email: Alex Kaszynski <akascap@gmail.com>
@@ -22,9 +22,9 @@ Requires-Dist: tqdm
22
22
  Requires-Dist: aiohttp
23
23
  Requires-Dist: pandas <= 3.0
24
24
  Requires-Dist: pydantic
25
- Requires-Dist: sphinx==7.3.7 ; extra == "doc"
26
- Requires-Dist: pydata-sphinx-theme==0.15.4 ; extra == "doc"
27
- Requires-Dist: numpydoc==1.7.0 ; extra == "doc"
25
+ Requires-Dist: sphinx==9.1.0 ; extra == "doc"
26
+ Requires-Dist: pydata-sphinx-theme==0.16.1 ; extra == "doc"
27
+ Requires-Dist: numpydoc==1.10.0 ; extra == "doc"
28
28
  Requires-Dist: matplotlib ; extra == "test"
29
29
  Requires-Dist: pandas ; extra == "test"
30
30
  Requires-Dist: pytest-asyncio ; extra == "test"
@@ -52,14 +52,10 @@ Python keepa Client Library
52
52
  .. image:: https://codecov.io/gh/akaszynski/keepa/branch/main/graph/badge.svg
53
53
  :target: https://codecov.io/gh/akaszynski/keepa
54
54
 
55
- .. image:: https://app.codacy.com/project/badge/Grade/9452f99f297c4a6eac14e2d21189ab6f
56
- :target: https://www.codacy.com/gh/akaszynski/keepa/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=akaszynski/keepa&amp;utm_campaign=Badge_Grade
57
-
58
55
 
59
56
  This Python library allows you to interface with the API at `Keepa
60
- <https://keepa.com/>`_ to query for Amazon product information and
61
- history. It also contains a plotting module to allow for plotting of
62
- a product.
57
+ <https://keepa.com/>`_ to query for Amazon product information and history. It
58
+ also contains a plotting module to allow for plotting of a product.
63
59
 
64
60
  Sign up for `Keepa Data Access <https://get.keepa.com/d7vrq>`_.
65
61
 
@@ -346,8 +342,8 @@ found at `keepacom/api_backend <https://github.com/keepacom/api_backend/>`_.
346
342
 
347
343
  License
348
344
  -------
349
- Apache License, please see license file. Work is credited to both Alex
350
- Kaszynski and Marius Johann.
345
+ Apache License, please see license file. Work is credited to both Alex Kaszynski
346
+ and Marius Johann.
351
347
 
352
348
 
353
349
  .. _create a pull request: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request
@@ -14,14 +14,10 @@ Python keepa Client Library
14
14
  .. image:: https://codecov.io/gh/akaszynski/keepa/branch/main/graph/badge.svg
15
15
  :target: https://codecov.io/gh/akaszynski/keepa
16
16
 
17
- .. image:: https://app.codacy.com/project/badge/Grade/9452f99f297c4a6eac14e2d21189ab6f
18
- :target: https://www.codacy.com/gh/akaszynski/keepa/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=akaszynski/keepa&amp;utm_campaign=Badge_Grade
19
-
20
17
 
21
18
  This Python library allows you to interface with the API at `Keepa
22
- <https://keepa.com/>`_ to query for Amazon product information and
23
- history. It also contains a plotting module to allow for plotting of
24
- a product.
19
+ <https://keepa.com/>`_ to query for Amazon product information and history. It
20
+ also contains a plotting module to allow for plotting of a product.
25
21
 
26
22
  Sign up for `Keepa Data Access <https://get.keepa.com/d7vrq>`_.
27
23
 
@@ -308,8 +304,8 @@ found at `keepacom/api_backend <https://github.com/keepacom/api_backend/>`_.
308
304
 
309
305
  License
310
306
  -------
311
- Apache License, please see license file. Work is credited to both Alex
312
- Kaszynski and Marius Johann.
307
+ Apache License, please see license file. Work is credited to both Alex Kaszynski
308
+ and Marius Johann.
313
309
 
314
310
 
315
311
  .. _create a pull request: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request
@@ -2,9 +2,6 @@
2
2
  build-backend = "flit_core.buildapi"
3
3
  requires = ["flit_core >=3,<4"]
4
4
 
5
- [mypy]
6
- plugins = "pydantic.mypy"
7
-
8
5
  [project]
9
6
  authors = [
10
7
  {name = "Alex Kaszynski", email = "akascap@gmail.com"}
@@ -33,13 +30,13 @@ keywords = ["keepa"]
33
30
  name = "keepa"
34
31
  readme = "README.rst"
35
32
  requires-python = ">=3.10"
36
- version = "1.4.2"
33
+ version = "1.4.4"
37
34
 
38
35
  [project.optional-dependencies]
39
36
  doc = [
40
- "sphinx==7.3.7",
41
- "pydata-sphinx-theme==0.15.4",
42
- "numpydoc==1.7.0"
37
+ "sphinx==9.1.0",
38
+ "pydata-sphinx-theme==0.16.1",
39
+ "numpydoc==1.10.0"
43
40
  ]
44
41
  test = [
45
42
  "matplotlib",
@@ -54,6 +51,9 @@ test = [
54
51
  Documentation = "https://keepaapi.readthedocs.io/en/latest/"
55
52
  Source = "https://github.com/akaszynski/keepa"
56
53
 
54
+ [tool.mypy]
55
+ plugins = "pydantic.mypy"
56
+
57
57
  [tool.pytest.ini_options]
58
58
  addopts = "--cov=keepa --cov-fail-under=85"
59
59
  asyncio_default_fixture_loop_scope = "function"
@@ -130,7 +130,7 @@ class AsyncKeepa:
130
130
 
131
131
  async def update_status(self) -> None:
132
132
  """Update available tokens."""
133
- self.status = await self._request("token", {"key": self.accesskey}, wait=False)
133
+ await self._request("token", {"key": self.accesskey}, wait=False)
134
134
 
135
135
  async def wait_for_tokens(self) -> None:
136
136
  """Check if there are any remaining tokens and waits if none are available."""
@@ -40,9 +40,14 @@ class Keepa:
40
40
  server has not issued a response for timeout seconds. Setting this to
41
41
  0.0 disables the timeout, but will cause any request to hang
42
42
  indefiantly should keepa.com be down
43
- logging_level: string, default: "DEBUG"
43
+ logging_level: str, default: "DEBUG"
44
44
  Logging level to use. Default is "DEBUG". Other options are "INFO",
45
45
  "WARNING", "ERROR", and "CRITICAL".
46
+ check_key : bool, default: True
47
+ Check the keepa key on initialization and update the number of
48
+ available tokens. This is a free check and does not cost any tokens,
49
+ but does slow down the time to initialize. Disable this to speed up
50
+ init at the risk of using an invalid key when querying for a product.
46
51
 
47
52
  Examples
48
53
  --------
@@ -81,7 +86,13 @@ class Keepa:
81
86
  status: Status
82
87
  _timeout: float
83
88
 
84
- def __init__(self, accesskey: str, timeout: float = 10.0, logging_level: str = "DEBUG") -> None:
89
+ def __init__(
90
+ self,
91
+ accesskey: str,
92
+ timeout: float = 10.0,
93
+ logging_level: str = "DEBUG",
94
+ check_key: bool = False,
95
+ ) -> None:
85
96
  """Initialize server connection."""
86
97
  self.accesskey = accesskey
87
98
  self.tokens_left = 0
@@ -93,9 +104,11 @@ class Keepa:
93
104
  raise TypeError("logging_level must be one of: " + ", ".join(levels))
94
105
  log.setLevel(logging_level)
95
106
 
96
- # Don't check available tokens on init
107
+ # Check available tokens on init
97
108
  log.info("Using key ending in %s", accesskey[-6:])
98
109
  self.status = Status()
110
+ if check_key:
111
+ self.update_status()
99
112
 
100
113
  @property
101
114
  def time_to_refill(self) -> float:
@@ -114,6 +127,20 @@ class Keepa:
114
127
  0.0
115
128
 
116
129
  """
130
+ if (
131
+ self.status.refillRate is None
132
+ or self.status.refillIn is None
133
+ or self.status.timestamp is None
134
+ ):
135
+ self.update_status()
136
+
137
+ if (
138
+ self.status.refillRate is None
139
+ or self.status.refillIn is None
140
+ or self.status.timestamp is None
141
+ ):
142
+ raise RuntimeError("Failed to update status")
143
+
117
144
  # Get current timestamp in milliseconds from UNIX epoch
118
145
  now = int(time.time() * 1000)
119
146
  time_at_refill = self.status.timestamp + self.status.refillIn
@@ -130,11 +157,10 @@ class Keepa:
130
157
  # Return value in seconds
131
158
  return time_to_refill / 1000.0
132
159
 
133
- def update_status(self) -> dict[str, Any]:
160
+ def update_status(self) -> None:
134
161
  """Update available tokens."""
135
- status = self._request("token", {"key": self.accesskey}, wait=False)
136
- self.status = status
137
- return status
162
+ # number of available tokens is always returned
163
+ self._request("token", {"key": self.accesskey}, wait=False)
138
164
 
139
165
  def wait_for_tokens(self) -> None:
140
166
  """Check if there are any remaining tokens and waits if none are available."""
@@ -143,7 +169,7 @@ class Keepa:
143
169
  # Wait if no tokens available
144
170
  if self.tokens_left <= 0:
145
171
  tdelay = self.time_to_refill
146
- log.warning("Waiting %.0f seconds for additional tokens" % tdelay)
172
+ log.warning("Waiting %.0f seconds for additional tokens", tdelay)
147
173
  time.sleep(tdelay)
148
174
  self.update_status()
149
175
 
@@ -632,6 +658,11 @@ class Keepa:
632
658
  if offers > 100 or offers < 20:
633
659
  raise ValueError('Parameter "offers" must be between 20 and 100')
634
660
 
661
+ if self.status.refillRate is None or self.status.refillIn is None:
662
+ self.update_status()
663
+ if self.status.refillRate is None or self.status.refillIn is None:
664
+ raise RuntimeError("Failed to update status")
665
+
635
666
  # Report time to completion
636
667
  if self.status.refillRate is not None:
637
668
  tcomplete = (
@@ -797,7 +828,7 @@ class Keepa:
797
828
  to_datetime = kwargs.pop("to_datetime", True)
798
829
 
799
830
  # Query and replace csv with parsed data if history enabled
800
- wait = kwargs.get("wait")
831
+ wait = bool(kwargs.get("wait"))
801
832
  kwargs.pop("wait", None)
802
833
  raw_response = kwargs.pop("raw", False)
803
834
  response = self._request("product", kwargs, wait=wait, raw_response=raw_response)
@@ -956,7 +987,7 @@ class Keepa:
956
987
 
957
988
  def search_for_categories(
958
989
  self, searchterm: str, domain: str | Domain = "US", wait: bool = True
959
- ) -> list:
990
+ ) -> dict[str, Any]:
960
991
  """
961
992
  Search for categories from Amazon.
962
993
 
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