recapi 0.4.11__tar.gz → 0.4.12__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.
- {recapi-0.4.11/recapi.egg-info → recapi-0.4.12}/PKG-INFO +4 -3
- {recapi-0.4.11 → recapi-0.4.12}/README.md +3 -2
- {recapi-0.4.11 → recapi-0.4.12}/pyproject.toml +1 -1
- {recapi-0.4.11 → recapi-0.4.12}/recapi/client.py +19 -4
- {recapi-0.4.11 → recapi-0.4.12/recapi.egg-info}/PKG-INFO +4 -3
- {recapi-0.4.11 → recapi-0.4.12}/tests/test_client.py +16 -0
- {recapi-0.4.11 → recapi-0.4.12}/tests/test_client_vectors.py +8 -0
- {recapi-0.4.11 → recapi-0.4.12}/LICENSE +0 -0
- {recapi-0.4.11 → recapi-0.4.12}/recapi/__init__.py +0 -0
- {recapi-0.4.11 → recapi-0.4.12}/recapi/async_client.py +0 -0
- {recapi-0.4.11 → recapi-0.4.12}/recapi/history.py +0 -0
- {recapi-0.4.11 → recapi-0.4.12}/recapi/py.typed +0 -0
- {recapi-0.4.11 → recapi-0.4.12}/recapi.egg-info/SOURCES.txt +0 -0
- {recapi-0.4.11 → recapi-0.4.12}/recapi.egg-info/dependency_links.txt +0 -0
- {recapi-0.4.11 → recapi-0.4.12}/recapi.egg-info/top_level.txt +0 -0
- {recapi-0.4.11 → recapi-0.4.12}/setup.cfg +0 -0
- {recapi-0.4.11 → recapi-0.4.12}/tests/test_async_client.py +0 -0
- {recapi-0.4.11 → recapi-0.4.12}/tests/test_history.py +0 -0
- {recapi-0.4.11 → recapi-0.4.12}/tests/test_stores.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: recapi
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.12
|
|
4
4
|
Summary: Python client for the recapi recommendation API: per-user history, event batching, retries, popular fallback.
|
|
5
5
|
License: MIT
|
|
6
6
|
Project-URL: Homepage, https://recapi.io
|
|
@@ -49,7 +49,7 @@ Your recapi API serves the same library, for servers that can't reach PyPI
|
|
|
49
49
|
(the dashboard's quick start shows the line with your API's address):
|
|
50
50
|
|
|
51
51
|
```sh
|
|
52
|
-
pip install https://api.<your-domain>/sdk/python/recapi-0.4.
|
|
52
|
+
pip install https://api.<your-domain>/sdk/python/recapi-0.4.12-py3-none-any.whl
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
To work on the library itself, install it from a checkout of recapi's repository
|
|
@@ -272,7 +272,8 @@ batch that can succeed later is retried with backoff (up to 10,000 queued).
|
|
|
272
272
|
list on a 401 or 403, and logs one warning to the `recapi` logger. A bad
|
|
273
273
|
request or a reply that isn't the API's raises `recapi.RecapiError` (`code`,
|
|
274
274
|
`status`, `retryable`); `upsert_items` raises `recapi.RejectedItemsError` for
|
|
275
|
-
the items the API refused.
|
|
275
|
+
the items the API refused. An API error also carries `docs_url`, the address
|
|
276
|
+
of its section on the errors page; its message ends with it.
|
|
276
277
|
|
|
277
278
|
- [Errors](https://recapi.io/docs/errors): each error code, its cause and fix.
|
|
278
279
|
- [Troubleshooting](https://recapi.io/docs/troubleshooting): no lists yet,
|
|
@@ -26,7 +26,7 @@ Your recapi API serves the same library, for servers that can't reach PyPI
|
|
|
26
26
|
(the dashboard's quick start shows the line with your API's address):
|
|
27
27
|
|
|
28
28
|
```sh
|
|
29
|
-
pip install https://api.<your-domain>/sdk/python/recapi-0.4.
|
|
29
|
+
pip install https://api.<your-domain>/sdk/python/recapi-0.4.12-py3-none-any.whl
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
To work on the library itself, install it from a checkout of recapi's repository
|
|
@@ -249,7 +249,8 @@ batch that can succeed later is retried with backoff (up to 10,000 queued).
|
|
|
249
249
|
list on a 401 or 403, and logs one warning to the `recapi` logger. A bad
|
|
250
250
|
request or a reply that isn't the API's raises `recapi.RecapiError` (`code`,
|
|
251
251
|
`status`, `retryable`); `upsert_items` raises `recapi.RejectedItemsError` for
|
|
252
|
-
the items the API refused.
|
|
252
|
+
the items the API refused. An API error also carries `docs_url`, the address
|
|
253
|
+
of its section on the errors page; its message ends with it.
|
|
253
254
|
|
|
254
255
|
- [Errors](https://recapi.io/docs/errors): each error code, its cause and fix.
|
|
255
256
|
- [Troubleshooting](https://recapi.io/docs/troubleshooting): no lists yet,
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "recapi"
|
|
7
|
-
version = "0.4.
|
|
7
|
+
version = "0.4.12"
|
|
8
8
|
description = "Python client for the recapi recommendation API: per-user history, event batching, retries, popular fallback."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -29,7 +29,7 @@ from typing import Any, Protocol
|
|
|
29
29
|
|
|
30
30
|
from .history import History, is_id
|
|
31
31
|
|
|
32
|
-
__version__ = "0.4.
|
|
32
|
+
__version__ = "0.4.12"
|
|
33
33
|
|
|
34
34
|
log = logging.getLogger("recapi")
|
|
35
35
|
Tags = Sequence[str] | None
|
|
@@ -114,16 +114,27 @@ class RecapiError(Exception):
|
|
|
114
114
|
|
|
115
115
|
``code`` is the API's error code (``invalid_request``, ``rate_limited``,
|
|
116
116
|
``quota_exceeded``...) or a client one: ``network``, ``timeout``,
|
|
117
|
-
``invalid_response``.
|
|
117
|
+
``invalid_response``. ``docs_url`` is the errors page's section for an
|
|
118
|
+
API error, from its body (None when the API sent none, and for a client
|
|
119
|
+
code); the error's text then ends with ``, see <docs_url>``.
|
|
118
120
|
"""
|
|
119
121
|
|
|
120
122
|
def __init__(
|
|
121
|
-
self,
|
|
123
|
+
self,
|
|
124
|
+
code: str,
|
|
125
|
+
message: str,
|
|
126
|
+
*,
|
|
127
|
+
status: int = 0,
|
|
128
|
+
retry_after: float | None = None,
|
|
129
|
+
docs_url: str | None = None,
|
|
122
130
|
) -> None:
|
|
123
|
-
|
|
131
|
+
# The address ends the text, so the log line or traceback that
|
|
132
|
+
# prints the error names its fix.
|
|
133
|
+
super().__init__(f"{message}, see {docs_url}" if docs_url else message)
|
|
124
134
|
self.code = code
|
|
125
135
|
self.status = status
|
|
126
136
|
self.retry_after = retry_after
|
|
137
|
+
self.docs_url = docs_url or None
|
|
127
138
|
|
|
128
139
|
@property
|
|
129
140
|
def retryable(self) -> bool:
|
|
@@ -1211,11 +1222,15 @@ def _http_error(status: int, headers: Any, text: bytes) -> RecapiError:
|
|
|
1211
1222
|
or _CODE_BY_STATUS.get(status)
|
|
1212
1223
|
or ("internal" if status >= 500 else "http_error")
|
|
1213
1224
|
)
|
|
1225
|
+
# Only a string: an older server sends none, and a proxy's odd body must
|
|
1226
|
+
# not put an object in the text.
|
|
1227
|
+
docs_url = body.get("docs_url")
|
|
1214
1228
|
return RecapiError(
|
|
1215
1229
|
str(code),
|
|
1216
1230
|
str(body.get("message") or f"HTTP {status}"),
|
|
1217
1231
|
status=status,
|
|
1218
1232
|
retry_after=_retry_after(headers.get("Retry-After")),
|
|
1233
|
+
docs_url=docs_url if isinstance(docs_url, str) else None,
|
|
1219
1234
|
)
|
|
1220
1235
|
|
|
1221
1236
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: recapi
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.12
|
|
4
4
|
Summary: Python client for the recapi recommendation API: per-user history, event batching, retries, popular fallback.
|
|
5
5
|
License: MIT
|
|
6
6
|
Project-URL: Homepage, https://recapi.io
|
|
@@ -49,7 +49,7 @@ Your recapi API serves the same library, for servers that can't reach PyPI
|
|
|
49
49
|
(the dashboard's quick start shows the line with your API's address):
|
|
50
50
|
|
|
51
51
|
```sh
|
|
52
|
-
pip install https://api.<your-domain>/sdk/python/recapi-0.4.
|
|
52
|
+
pip install https://api.<your-domain>/sdk/python/recapi-0.4.12-py3-none-any.whl
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
To work on the library itself, install it from a checkout of recapi's repository
|
|
@@ -272,7 +272,8 @@ batch that can succeed later is retried with backoff (up to 10,000 queued).
|
|
|
272
272
|
list on a 401 or 403, and logs one warning to the `recapi` logger. A bad
|
|
273
273
|
request or a reply that isn't the API's raises `recapi.RecapiError` (`code`,
|
|
274
274
|
`status`, `retryable`); `upsert_items` raises `recapi.RejectedItemsError` for
|
|
275
|
-
the items the API refused.
|
|
275
|
+
the items the API refused. An API error also carries `docs_url`, the address
|
|
276
|
+
of its section on the errors page; its message ends with it.
|
|
276
277
|
|
|
277
278
|
- [Errors](https://recapi.io/docs/errors): each error code, its cause and fix.
|
|
278
279
|
- [Troubleshooting](https://recapi.io/docs/troubleshooting): no lists yet,
|
|
@@ -392,6 +392,22 @@ class Recommend(APITest):
|
|
|
392
392
|
self.assertIn("recs down", logs.output[0])
|
|
393
393
|
self.assertIn("pop down", logs.output[0])
|
|
394
394
|
|
|
395
|
+
def test_the_log_line_for_a_refused_key_ends_with_the_address_of_its_fix(self) -> None:
|
|
396
|
+
docs_url = "https://app.recapi.io/docs/errors#401-unauthorized"
|
|
397
|
+
error = {"code": "unauthorized", "message": "missing or invalid API key"}
|
|
398
|
+
self.api.handler = lambda call: Reply(401, {"error": {**error, "docs_url": docs_url}})
|
|
399
|
+
client = self.client()
|
|
400
|
+
client.track("a", 1, user_id="u")
|
|
401
|
+
with self.assertLogs("recapi", "WARNING") as logs:
|
|
402
|
+
client.flush()
|
|
403
|
+
client.recommend(user_id="u", count=3)
|
|
404
|
+
self.assertTrue(logs.output)
|
|
405
|
+
for line in logs.output:
|
|
406
|
+
self.assertTrue(line.endswith(f"missing or invalid API key, see {docs_url}"), line)
|
|
407
|
+
with self.assertRaises(recapi.RecapiError) as caught:
|
|
408
|
+
client._popular(1, None, None, None)
|
|
409
|
+
self.assertEqual(caught.exception.docs_url, docs_url)
|
|
410
|
+
|
|
395
411
|
def test_an_unusable_context_item_id_is_reported_without_the_id(self) -> None:
|
|
396
412
|
# A page takes the id from a visitor's URL: the visitor must not reach
|
|
397
413
|
# the log, the rejected item still leaves the list, and the history
|
|
@@ -25,6 +25,8 @@ def error_reply(case: dict) -> Reply:
|
|
|
25
25
|
body = None
|
|
26
26
|
if case.get("body_code"):
|
|
27
27
|
body = {"error": {"code": case["body_code"], "message": "from the vector"}}
|
|
28
|
+
if "docs_url" in case:
|
|
29
|
+
body["error"]["docs_url"] = case["docs_url"]
|
|
28
30
|
headers = {"Retry-After": case["retry_after"]} if "retry_after" in case else {}
|
|
29
31
|
if "retry_after_ms" in case and case["retry_after_ms"] is not None and not headers:
|
|
30
32
|
headers = {"Retry-After": str(case["retry_after_ms"] / 1000)}
|
|
@@ -84,6 +86,12 @@ class ClientVectors(APITest):
|
|
|
84
86
|
if "retry_after_ms" in case:
|
|
85
87
|
want = case["retry_after_ms"]
|
|
86
88
|
self.assertEqual(error.retry_after, None if want is None else want / 1000)
|
|
89
|
+
self.assertEqual(error.docs_url, case.get("docs_url"))
|
|
90
|
+
# An older server sends no docs_url: no address, and the message as sent.
|
|
91
|
+
if "docs_url" in case:
|
|
92
|
+
self.assertTrue(str(error).endswith(", see " + case["docs_url"]), str(error))
|
|
93
|
+
elif case.get("body_code"):
|
|
94
|
+
self.assertEqual(str(error), "from the vector")
|
|
87
95
|
|
|
88
96
|
def test_vector_list_calls_keep_the_page_up(self) -> None:
|
|
89
97
|
for case in VECTORS["errors"]:
|
|
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
|
|
File without changes
|