serpbit 0.3.0__tar.gz → 0.3.2__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: serpbit
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Google Search, News, Shopping, Images, Videos, Maps, Autocomplete and AI Mode as data: the Serpbit API client.
5
5
  Author-email: Serpbit <support@serpbit.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "serpbit"
7
- version = "0.3.0"
7
+ version = "0.3.2"
8
8
  description = "Google Search, News, Shopping, Images, Videos, Maps, Autocomplete and AI Mode as data: the Serpbit API client."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -15,7 +15,7 @@ from ._errors import APIConnectionError, InsufficientCreditsError, SerpbitError,
15
15
 
16
16
  DEFAULT_BASE_URL = "https://api.serpbit.com"
17
17
  DEFAULT_CONNECT_URL = "wss://connect.serpbit.com"
18
- VERSION = "0.3.0"
18
+ VERSION = "0.3.2"
19
19
 
20
20
  # A call is retried on these: the rate limit (after Retry-After), Google giving no page in time, our side failing.
21
21
  _RETRY = {429, 500, 502, 503, 504}
@@ -110,7 +110,7 @@ class Serpbit:
110
110
  serpbit.verify_webhook) and stays readable with batch_results for a day after the batch ends.
111
111
  """
112
112
  body: Dict[str, Any] = {"requests": [
113
- {**r, "params": {k: v for k, v in (r.get("params") or {}).items() if v is not None and v is not False}}
113
+ {**r, "params": {k: v for k, v in (r.get("params") or {}).items() if v is not None and (v is not False or k == "ai_overview")}}
114
114
  for r in requests]}
115
115
  if webhook:
116
116
  body["webhook"] = webhook
@@ -191,9 +191,11 @@ class Serpbit:
191
191
 
192
192
  def request(self, path: str, *, method: str = "GET", json_body: Any = None, idempotency_key: Optional[str] = None,
193
193
  retry: bool = True, **params: Any) -> Answer:
194
- """Call path with params. True is sent as true; None and False are left out; a list is joined by commas.
194
+ """Call path with params. True is sent as true; None and False are left out (ai_overview=False is sent as 0: none,
195
+ as left out a search brings the page's overview); a list is joined by commas.
195
196
  retry=False makes one attempt: a call that is not safe to make twice, as opening a browser."""
196
- query = {k: _value(v) for k, v in params.items() if v is not None and v is not False}
197
+ query = {k: "0" if k == "ai_overview" and v is False else _value(v) for k, v in params.items()
198
+ if v is not None and (v is not False or k == "ai_overview")}
197
199
  url = self.base_url + path + ("?" + urllib.parse.urlencode(query) if query else "")
198
200
  retries = self.max_retries if retry else 0
199
201
  key = idempotency_key or (uuid.uuid4().hex if retries else None)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: serpbit
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Google Search, News, Shopping, Images, Videos, Maps, Autocomplete and AI Mode as data: the Serpbit API client.
5
5
  Author-email: Serpbit <support@serpbit.com>
6
6
  License-Expression: MIT
@@ -96,6 +96,13 @@ class ClientTest(unittest.TestCase):
96
96
  FakeAPI.seen, FakeAPI.script = [], []
97
97
  self.sb = Serpbit("sb_live_test", base_url=self.base, max_retries=2)
98
98
 
99
+ def test_ai_overview_false_is_sent_as_0(self):
100
+ # Left out, a search brings the page's overview: False asks for none.
101
+ self.sb.search("x", ai_overview=False)
102
+ self.assertEqual(FakeAPI.seen[-1]["query"], {"q": "x", "ai_overview": "0"})
103
+ self.sb.batch([{"path": "/v1/search", "params": {"q": "y", "ai_overview": False, "html": False}}])
104
+ self.assertEqual(FakeAPI.seen[-1]["body"]["requests"][0]["params"], {"q": "y", "ai_overview": False})
105
+
99
106
  def test_a_search_sends_its_parameters_and_reads_the_json(self):
100
107
  a = self.sb.search("coffee grinder", gl="de", pages=2, content=True, ai_overview=True, safe=None, html=False,
101
108
  lr=["lang_de", "lang_en"])
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes